Rely on spec.maintenance=termination instead of terminating#289
Conversation
Main motivation is to let anyone set the hypervisor into termination, and for that the spec should be the authorative source for the custom-resource. That means, one can manually offboard the node now by setting that spec too. But also, the terminating condition on the node is not guaranteed to stay, as it is part of the gardener contract. We should keep the use of that to as few places as possible, so if that changes we do not have to rewrite all our code.
📝 WalkthroughWalkthroughThree controllers (aggregates, onboarding, traits) have their termination detection logic refactored to check the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Merging this branch will increase overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/controller/onboarding_controller.go`:
- Around line 95-97: The abort path for hv.Spec.Maintenance ==
kvmv1.MaintenanceTermination calls abortOnboarding but abortOnboarding always
logs "Aborted due to LifecycleEnabled being false", which is incorrect for
termination-triggered aborts; update abortOnboarding usage to accept an explicit
abort reason (or set the abort message on the hv object before calling) and pass
a termination-specific reason when maintenance==MaintenanceTermination so
abortOnboarding records/logs "Aborted due to MaintenanceTermination" (or
similar), ensuring abortOnboarding still uses the provided reason when setting
the status/message.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 907ef81b-f3c0-4a1f-822b-50a87c717450
📒 Files selected for processing (5)
internal/controller/aggregates_controller.gointernal/controller/aggregates_controller_test.gointernal/controller/onboarding_controller.gointernal/controller/traits_controller.gointernal/controller/traits_controller_test.go
| if hv.Spec.Maintenance == kvmv1.MaintenanceTermination { | ||
| return ctrl.Result{}, r.abortOnboarding(ctx, hv, computeHost) | ||
| } |
There was a problem hiding this comment.
Abort status message is now misleading for termination-triggered aborts.
Line 95 routes spec.maintenance=termination through abortOnboarding, but that function always sets "Aborted due to LifecycleEnabled being false", which is incorrect for this path.
💡 Proposed fix
- if !hv.Spec.LifecycleEnabled {
- return ctrl.Result{}, r.abortOnboarding(ctx, hv, computeHost)
- }
+ if !hv.Spec.LifecycleEnabled {
+ return ctrl.Result{}, r.abortOnboarding(ctx, hv, computeHost, "lifecycle disabled")
+ }
- if hv.Spec.Maintenance == kvmv1.MaintenanceTermination {
- return ctrl.Result{}, r.abortOnboarding(ctx, hv, computeHost)
- }
+ if hv.Spec.Maintenance == kvmv1.MaintenanceTermination {
+ return ctrl.Result{}, r.abortOnboarding(ctx, hv, computeHost, "termination requested")
+ }
-func (r *OnboardingController) abortOnboarding(ctx context.Context, hv *kvmv1.Hypervisor, computeHost string) error {
+func (r *OnboardingController) abortOnboarding(ctx context.Context, hv *kvmv1.Hypervisor, computeHost, cause string) error {
...
meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
Type: kvmv1.ConditionTypeOnboarding,
Status: metav1.ConditionFalse,
Reason: kvmv1.ConditionReasonAborted,
- Message: "Aborted due to LifecycleEnabled being false",
+ Message: fmt.Sprintf("Aborted: %s", cause),
})🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/controller/onboarding_controller.go` around lines 95 - 97, The abort
path for hv.Spec.Maintenance == kvmv1.MaintenanceTermination calls
abortOnboarding but abortOnboarding always logs "Aborted due to LifecycleEnabled
being false", which is incorrect for termination-triggered aborts; update
abortOnboarding usage to accept an explicit abort reason (or set the abort
message on the hv object before calling) and pass a termination-specific reason
when maintenance==MaintenanceTermination so abortOnboarding records/logs
"Aborted due to MaintenanceTermination" (or similar), ensuring abortOnboarding
still uses the provided reason when setting the status/message.
Main motivation is to let anyone set the hypervisor into termination, and for that the spec should be the authorative source for the custom-resource. That means, one can manually offboard the node now by setting that spec too.
But also, the terminating condition on the node is not guaranteed to stay, as it is part of the gardener contract. We should keep the use of that to as few places as possible, so if that changes we do not have to rewrite all our code.
Summary by CodeRabbit
Refactor
Tests