-
Notifications
You must be signed in to change notification settings - Fork 12
node condtion remediation #131
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
Open
runzhen
wants to merge
15
commits into
main
Choose a base branch
from
runzhen/npd3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
723915f
npd
runzhen ac31627
npd
runzhen 6dee544
npd
runzhen 915ec60
npd
runzhen 0875cc7
npd
runzhen 42b396c
Update pkg/status/collector.go
runzhen 55ed1bb
Update pkg/status/collector.go
runzhen 1c3b733
Update pkg/drift/remediation.go
runzhen 7cbe9d6
npd
runzhen 94ee58c
npd
runzhen 82b8a0b
npd
runzhen 7cc494b
Update pkg/drift/remediation.go
runzhen ce20060
Update pkg/drift/remediation.go
runzhen 3c04925
Update pkg/drift/remediation.go
runzhen 89e55e8
npd
runzhen 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package drift | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/Azure/AKSFlexNode/pkg/config" | ||
| "github.com/Azure/AKSFlexNode/pkg/spec" | ||
| "github.com/Azure/AKSFlexNode/pkg/status" | ||
| ) | ||
|
|
||
| const NodeRebootFindingID = "node-reboot" | ||
|
|
||
| type RebootDetector struct{} | ||
|
|
||
| func NewRebootDetector() *RebootDetector { | ||
| return &RebootDetector{} | ||
| } | ||
|
|
||
| func (d *RebootDetector) Name() string { | ||
| return "RebootDetector" | ||
| } | ||
|
|
||
| func (d *RebootDetector) Detect( | ||
| ctx context.Context, | ||
| _ *config.Config, | ||
| _ *spec.ManagedClusterSpec, | ||
| statusSnap *status.NodeStatus, | ||
| ) ([]Finding, error) { | ||
| if ctx.Err() != nil { | ||
| return nil, ctx.Err() | ||
| } | ||
|
|
||
| if statusSnap == nil { | ||
| return nil, nil | ||
| } | ||
|
|
||
| if !statusSnap.NeedReboot { | ||
| return nil, nil | ||
| } | ||
|
|
||
| return []Finding{ | ||
| { | ||
| ID: NodeRebootFindingID, | ||
| Title: "Node reboot required", | ||
| Details: "Node status indicates a reboot is needed", | ||
| Remediation: Remediation{ | ||
| Action: RemediationActionReboot, | ||
| }, | ||
| }, | ||
| }, nil | ||
| } |
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,82 @@ | ||
| package drift | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/Azure/AKSFlexNode/pkg/status" | ||
| ) | ||
|
|
||
| func TestRebootDetector_Name(t *testing.T) { | ||
| t.Parallel() | ||
| d := NewRebootDetector() | ||
| if name := d.Name(); name != "RebootDetector" { | ||
| t.Errorf("expected name %q, got %q", "RebootDetector", name) | ||
| } | ||
| } | ||
|
|
||
| func TestRebootDetector_NilStatus_NoFindings(t *testing.T) { | ||
| t.Parallel() | ||
| d := NewRebootDetector() | ||
| findings, err := d.Detect(context.Background(), nil, nil, nil) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if len(findings) != 0 { | ||
| t.Errorf("expected no findings, got %d", len(findings)) | ||
| } | ||
| } | ||
|
|
||
| func TestRebootDetector_NeedRebootFalse_NoFindings(t *testing.T) { | ||
| t.Parallel() | ||
| d := NewRebootDetector() | ||
| statusSnap := &status.NodeStatus{ | ||
| NeedReboot: false, | ||
| } | ||
| findings, err := d.Detect(context.Background(), nil, nil, statusSnap) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if len(findings) != 0 { | ||
| t.Errorf("expected no findings, got %d", len(findings)) | ||
| } | ||
| } | ||
|
|
||
| func TestRebootDetector_NeedRebootTrue_ReturnsFinding(t *testing.T) { | ||
| t.Parallel() | ||
| d := NewRebootDetector() | ||
| statusSnap := &status.NodeStatus{ | ||
| NeedReboot: true, | ||
| } | ||
| findings, err := d.Detect(context.Background(), nil, nil, statusSnap) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if len(findings) != 1 { | ||
| t.Fatalf("expected 1 finding, got %d", len(findings)) | ||
| } | ||
|
|
||
| f := findings[0] | ||
| if f.ID != NodeRebootFindingID { | ||
| t.Errorf("expected ID %q, got %q", NodeRebootFindingID, f.ID) | ||
| } | ||
| if f.Title != "Node reboot required" { | ||
| t.Errorf("unexpected title: %q", f.Title) | ||
| } | ||
| if f.Remediation.Action != RemediationActionReboot { | ||
| t.Errorf("expected action %q, got %q", RemediationActionReboot, f.Remediation.Action) | ||
| } | ||
| } | ||
|
|
||
| func TestRebootDetector_CanceledContext_ReturnsError(t *testing.T) { | ||
| t.Parallel() | ||
| d := NewRebootDetector() | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| cancel() | ||
|
|
||
| statusSnap := &status.NodeStatus{NeedReboot: true} | ||
| _, err := d.Detect(ctx, nil, nil, statusSnap) | ||
| if err == nil { | ||
| t.Fatal("expected error from canceled context") | ||
| } | ||
| } |
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
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.