-
Notifications
You must be signed in to change notification settings - Fork 75
fix: consistent dry-run behavior between NodeController and RuleContr… #422
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,10 +140,41 @@ func (r *RuleReadinessController) processNodeAgainstAllRules(ctx context.Context | |
| continue | ||
| } | ||
|
|
||
| // Skip if dry run | ||
| // Handle dry run | ||
| if rule.Spec.DryRun { | ||
| log.Info("Skipping rule - dry run mode", | ||
| log.Info("Evaluating rule - dry run mode", | ||
| "node", node.Name, "rule", rule.Name) | ||
|
|
||
| nodeList := &corev1.NodeList{} | ||
| if err := r.List(ctx, nodeList); err != nil { | ||
| log.Error(err, "Failed to list nodes for dry run evaluation", "rule", rule.Name) | ||
| errs = append(errs, err) | ||
| continue | ||
| } | ||
|
|
||
| if err := r.processDryRun(ctx, rule, nodeList); err != nil { | ||
| log.Error(err, "Failed to process dry run for node", | ||
| "node", node.Name, "rule", rule.Name) | ||
| errs = append(errs, err) | ||
| continue | ||
| } | ||
|
|
||
| err := retry.RetryOnConflict(retry.DefaultRetry, func() error { | ||
|
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. This patches the live rule with state read from the cache. If someone flips dryRun: false while a node reconcile is in flight, we can end up writing dryRunResults back onto a now-enforcing rule and reverting observedGeneration. Status is a subresource and we use GenerationChangedPredicate, so RuleReconciler never re-runs to fix it. Can we re-check latestRule.Spec.DryRun inside the retry closure, and skip the ObservedGeneration write here? |
||
| latestRule := &readinessv1alpha1.NodeReadinessRule{} | ||
| if err := r.Get(ctx, client.ObjectKey{Name: rule.Name}, latestRule); err != nil { | ||
| return err | ||
| } | ||
| patch := client.MergeFrom(latestRule.DeepCopy()) | ||
| latestRule.Status.DryRunResults = rule.Status.DryRunResults | ||
| latestRule.Status.ObservedGeneration = rule.Status.ObservedGeneration | ||
| return r.Status().Patch(ctx, latestRule, patch) | ||
|
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. This fires on every node event regardless of whether Could we compare against |
||
| }) | ||
|
|
||
| if err != nil { | ||
| log.Error(err, "Failed to update rule status after dry run evaluation", | ||
| "node", node.Name, "rule", rule.Name) | ||
| errs = append(errs, err) | ||
| } | ||
| continue | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -543,15 +543,22 @@ status: | |||||
| }, 10*time.Second, 2*time.Second).Should(BeTrue()) | ||||||
|
|
||||||
| By("verifying rule has dry-run results showing what would happen") | ||||||
| Eventually(func() bool { | ||||||
| cmd := exec.Command("kubectl", "get", "nodereadinessrule", "dryrun-test-rule", "-o", "jsonpath={.status.dryRunResults}") | ||||||
| output, err := utils.Run(cmd) | ||||||
| if err != nil { | ||||||
| return false | ||||||
| } | ||||||
| // Check that dry run results exist and contain the node | ||||||
| return len(output) > 0 | ||||||
| }, 30*time.Second, 2*time.Second).Should(BeTrue()) | ||||||
| Eventually(func() string { | ||||||
| cmd := exec.Command("kubectl", "get", "nodereadinessrule", "dryrun-test-rule", "-o", "jsonpath={.status.dryRunResults.taintsToAdd}") | ||||||
| output, _ := utils.Run(cmd) | ||||||
| return output | ||||||
| }, 30*time.Second, 2*time.Second).Should(Equal("1")) | ||||||
|
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. Unless I'm misreading the marshalling,
Suggested change
Optional, but |
||||||
|
|
||||||
| By("updating node condition to True") | ||||||
| err = patchNodeCondition(nodeName, "TestReady", "True") | ||||||
| Expect(err).NotTo(HaveOccurred()) | ||||||
|
|
||||||
| By("verifying rule dry-run results update to reflect the change") | ||||||
| Eventually(func() string { | ||||||
| cmd := exec.Command("kubectl", "get", "nodereadinessrule", "dryrun-test-rule", "-o", "jsonpath={.status.dryRunResults.taintsToAdd}") | ||||||
| output, _ := utils.Run(cmd) | ||||||
| return output | ||||||
| }, 30*time.Second, 2*time.Second).Should(BeEmpty()) | ||||||
|
|
||||||
| By("cleaning up test resources") | ||||||
| exec.Command("kubectl", "delete", "node", nodeName).Run() | ||||||
|
|
||||||
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.
This List runs inside the per-rule loop, so N matching dry-run rules means N cluster-wide lists per node event. It's a cache read, but controller-runtime still deep-copies every Node, and processDryRun then walks all of them. During a rolling upgrade that's O(nodes²).
Two fixes:
client.MatchingLabelsso we only copy matching nodes