-
Notifications
You must be signed in to change notification settings - Fork 17
Fix NPD kubeconfig and node-name issues #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f05f3af
fix(npd): point node-problem-detector at the real kubelet kubeconfig
dhia-gharsallaoui 68265d6
Initial plan
Copilot 3aad170
Validate NPD in e2e flow
Copilot 58bfa49
Address NPD validation review feedback
Copilot c4ef0d4
Refine NPD validation checks
Copilot 92f521c
Harden NPD validation script
Copilot 0af12f8
Improve NPD validation diagnostics
Copilot 6831aea
Collect NPD logs in E2E
Copilot be31c15
Surface NPD log collection errors
Copilot cf2a5ad
Harden NPD log diagnostics
Copilot 4db154d
Tighten NPD log cleanup
Copilot aed10a0
Simplify NPD log diagnostics
Copilot d89a631
Clarify NPD log variables
Copilot 52b2121
Merge PR 193 npd kubeconfig fix
bcho 54153f0
Merge PR 197 npd e2e validation
bcho b66d2df
fix(npd): override hostname with node name
bcho 599fab5
refactor(npd): use resolved node goal state
bcho 0b3d576
Apply suggestions from code review
bcho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package npd | ||
|
|
||
| import ( | ||
| "log/slog" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/Azure/unbounded/pkg/agent/goalstates" | ||
| ) | ||
|
|
||
| // wantKubeconfigPath is the path the kubelet actually writes its kubeconfig to. | ||
| // The historical bug used a doubled segment ("/var/lib/kubelet/kubelet/kubeconfig"), | ||
| // which made node-problem-detector panic on startup and crash-loop forever: | ||
| // | ||
| // panic: stat /var/lib/kubelet/kubelet/kubeconfig: no such file or directory | ||
| const wantKubeconfigPath = "/var/lib/kubelet/kubeconfig" | ||
|
|
||
| // TestCanonicalKubeletKubeconfigPath guards the value of the shared library | ||
| // constant so the doubled-segment typo cannot reappear from a dependency bump. | ||
| func TestCanonicalKubeletKubeconfigPath(t *testing.T) { | ||
|
bcho marked this conversation as resolved.
|
||
| t.Parallel() | ||
| if goalstates.KubeletKubeconfigPath != wantKubeconfigPath { | ||
| t.Fatalf("goalstates.KubeletKubeconfigPath = %q, want %q", | ||
| goalstates.KubeletKubeconfigPath, wantKubeconfigPath) | ||
| } | ||
| } | ||
|
|
||
| // TestRenderedNPDUnitUsesCanonicalKubeconfig drives Start() through the real | ||
| // service-file rendering and asserts on the kubeconfig path that ends up in the | ||
| // node-problem-detector systemd unit's ExecStart. Asserting on the rendered unit | ||
| // (the externally observable artifact) rather than internal fields keeps the | ||
| // test stable across refactors while still exercising the Start() wiring. | ||
| func TestRenderedNPDUnitUsesCanonicalKubeconfig(t *testing.T) { | ||
|
bcho marked this conversation as resolved.
|
||
| t.Parallel() | ||
| machineDir := t.TempDir() | ||
| nodeStart := &goalstates.NodeStart{ | ||
| MachineDir: machineDir, | ||
| MachineName: "kube1", | ||
| NodeName: "vm-e2e-token-1781659839", | ||
| Kubelet: goalstates.Kubelet{ | ||
| APIServer: "https://example.hcp.westus.azmk8s.io:443", | ||
| }, | ||
| } | ||
| task, ok := Start(slog.Default(), nodeStart).(*startTask) | ||
| if !ok { | ||
| t.Fatalf("Start did not return *startTask") | ||
| } | ||
| if _, err := task.ensureServiceFile(); err != nil { | ||
| t.Fatalf("ensureServiceFile: %v", err) | ||
| } | ||
|
|
||
| unitPath := filepath.Join(machineDir, "etc/systemd/system", systemdUnitNPD) | ||
| data, err := os.ReadFile(unitPath) //nolint:gosec // path built from test TempDir | ||
| if err != nil { | ||
| t.Fatalf("read rendered unit: %v", err) | ||
| } | ||
| rendered := string(data) | ||
|
|
||
| if !strings.Contains(rendered, "auth="+wantKubeconfigPath) { | ||
| t.Fatalf("rendered unit missing auth=%s:\n%s", wantKubeconfigPath, rendered) | ||
| } | ||
| if strings.Contains(rendered, "kubelet/kubelet") { | ||
| t.Fatalf("rendered unit contains doubled 'kubelet' segment:\n%s", rendered) | ||
| } | ||
| if !strings.Contains(rendered, "--hostname-override=vm-e2e-token-1781659839") { | ||
| t.Fatalf("rendered unit missing hostname override:\n%s", rendered) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.