-
Notifications
You must be signed in to change notification settings - Fork 48
fix:return evaluation errors from processAllNodesForRule #237
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
dorodb-web22
wants to merge
2
commits into
kubernetes-sigs:main
Choose a base branch
from
dorodb-web22:fix/propagate-rule-evaluation-errors
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.
+12
−4
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "strings" | ||
| "sync" | ||
|
|
@@ -144,6 +145,7 @@ | |
| r.Controller.updateRuleCache(ctx, rule) | ||
|
|
||
| // Handle dry run | ||
| var processErr error | ||
| if rule.Spec.DryRun { | ||
| if err := r.Controller.processDryRun(ctx, rule, nodeList); err != nil { | ||
| log.Error(err, "Failed to process dry run", "rule", rule.Name) | ||
|
|
@@ -153,14 +155,15 @@ | |
| // Clear previous dry run results | ||
| rule.Status.DryRunResults = readinessv1alpha1.DryRunResults{} | ||
|
|
||
| // Process all applicable nodes for this rule | ||
| // Process all applicable nodes for this rule; save error so status | ||
| // is still updated before retrying. | ||
| if err := r.Controller.processAllNodesForRule(ctx, rule, nodeList); err != nil { | ||
| log.Error(err, "Failed to process nodes for rule", "rule", rule.Name) | ||
| return ctrl.Result{RequeueAfter: time.Minute}, err | ||
| processErr = err | ||
| } | ||
| } | ||
|
|
||
| // Update rule status | ||
| // Update rule status regardless of evaluation errors above | ||
| if err := r.Controller.updateRuleStatus(ctx, rule); err != nil { | ||
| log.Error(err, "Failed to update rule status", "rule", rule.Name) | ||
| return ctrl.Result{RequeueAfter: time.Minute}, err | ||
|
|
@@ -172,6 +175,9 @@ | |
| return ctrl.Result{RequeueAfter: time.Minute}, err | ||
| } | ||
|
|
||
| if processErr != nil { | ||
| return ctrl.Result{RequeueAfter: time.Minute}, processErr | ||
| } | ||
| return ctrl.Result{}, nil | ||
| } | ||
|
|
||
|
|
@@ -258,13 +264,14 @@ | |
|
|
||
| // processAllNodesForRule processes all nodes when a rule changes. | ||
| // | ||
| //nolint:unparam // Keep error return for future extensibility and API stability. | ||
| func (r *RuleReadinessController) processAllNodesForRule(ctx context.Context, rule *readinessv1alpha1.NodeReadinessRule, nodeList *corev1.NodeList) error { | ||
| log := ctrl.LoggerFrom(ctx) | ||
|
|
||
| log.Info("Processing all nodes for rule", "rule", rule.Name, "totalNodes", len(nodeList.Items)) | ||
|
|
||
| var appliedNodes []string | ||
| var errs []error | ||
| for _, node := range nodeList.Items { | ||
| if r.ruleAppliesTo(ctx, rule, &node) { | ||
| appliedNodes = append(appliedNodes, node.Name) | ||
|
|
@@ -274,6 +281,7 @@ | |
| log.Error(err, "Failed to evaluate node for rule", "rule", rule.Name, "node", node.Name) | ||
| r.recordNodeFailure(rule, node.Name, "EvaluationError", err.Error()) | ||
| metrics.Failures.WithLabelValues(rule.Name, "EvaluationError").Inc() | ||
| errs = append(errs, err) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -287,7 +295,7 @@ | |
| } | ||
|
|
||
| log.Info("Completed processing nodes for rule", "rule", rule.Name, "processedCount", len(appliedNodes)) | ||
| return nil | ||
| return errors.Join(errs...) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
can you also add unit tests to capture these gaps that this PR aims to address? |
||
| } | ||
|
|
||
| // evaluateRuleForNode evaluates a single rule against a single node. | ||
|
|
@@ -586,7 +594,7 @@ | |
| func (r *RuleReadinessController) cleanupTaintsForRule(ctx context.Context, rule *readinessv1alpha1.NodeReadinessRule, nodeList *corev1.NodeList) error { | ||
| log := ctrl.LoggerFrom(ctx) | ||
|
|
||
| var errors []string | ||
| for _, node := range nodeList.Items { | ||
| if !r.ruleAppliesTo(ctx, rule, &node) { | ||
| continue | ||
|
|
@@ -623,7 +631,7 @@ | |
| } | ||
|
|
||
| // Clean up nodes that matched old selector but not new selector | ||
| var errors []string | ||
| for _, node := range nodeList.Items { | ||
| // Check if node matched old selector | ||
| matchedOld := false | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning an error will keep the caller function(in this case this) in an infinite loop. Other rules will not be evaluated too. It will also not update the status(here) till the error is fixed.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the early return was skipping
updateRuleStatusandcleanupDeletedNodes. i ffixed by saving the error, letting status update complete, then returning the error at the end to trigger requeue.