Skip to content

Rely on spec.maintenance=termination instead of terminating#289

Merged
fwiesel merged 1 commit intomainfrom
termination
Apr 15, 2026
Merged

Rely on spec.maintenance=termination instead of terminating#289
fwiesel merged 1 commit intomainfrom
termination

Conversation

@fwiesel
Copy link
Copy Markdown
Contributor

@fwiesel fwiesel commented Apr 15, 2026

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

    • Modified how the system detects termination state for cleanup and maintenance operations across multiple controllers
  • Tests

    • Updated test suite to reflect the new termination detection approach and expanded coverage for eviction scenarios

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.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 15, 2026

📝 Walkthrough

Walkthrough

Three controllers (aggregates, onboarding, traits) have their termination detection logic refactored to check the hv.Spec.Maintenance field for MaintenanceTermination instead of checking the ConditionTypeTerminating status condition. Corresponding tests are updated to reflect the new detection mechanism.

Changes

Cohort / File(s) Summary
Aggregates Controller
internal/controller/aggregates_controller.go, internal/controller/aggregates_controller_test.go
Changed termination trigger from status condition ConditionTypeTerminating to spec field hv.Spec.Maintenance == MaintenanceTermination. Test restructured into sub-contexts for "eviction in progress" (validates no aggregate updates) and "eviction complete" (validates aggregate clearing with new HTTP mocks).
Onboarding Controller
internal/controller/onboarding_controller.go
Changed early-exit guard for aborting onboarding from status condition ConditionTypeTerminating check to spec field hv.Spec.Maintenance == MaintenanceTermination check.
Traits Controller
internal/controller/traits_controller.go, internal/controller/traits_controller_test.go
Changed reconcile early-exit guard from status condition ConditionTypeTerminating to spec field hv.Spec.Maintenance == MaintenanceTermination. Test setup now explicitly updates hypervisor spec field instead of setting status condition.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • toanju
  • bashar-alkhateeb

Poem

🐰 Spec now tells the termination tale,
No more status conditions pale,
Three controllers hear the call,
Maintenance field leads through it all!
Cleaner logic, simpler way, 🌿

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main change: shifting the termination trigger from a status condition to a spec field value.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch termination

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller 63.80% (+0.11%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/aggregates_controller.go 82.76% (+1.72%) 58 48 (+1) 10 (-1) 👍
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/onboarding_controller.go 55.83% (ø) 240 134 106
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/traits_controller.go 60.94% (ø) 64 39 25

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

  • github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/aggregates_controller_test.go
  • github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/traits_controller_test.go

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f20183e and 8de9fae.

📒 Files selected for processing (5)
  • internal/controller/aggregates_controller.go
  • internal/controller/aggregates_controller_test.go
  • internal/controller/onboarding_controller.go
  • internal/controller/traits_controller.go
  • internal/controller/traits_controller_test.go

Comment on lines +95 to 97
if hv.Spec.Maintenance == kvmv1.MaintenanceTermination {
return ctrl.Result{}, r.abortOnboarding(ctx, hv, computeHost)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

@fwiesel fwiesel merged commit 01f561b into main Apr 15, 2026
7 checks passed
@fwiesel fwiesel deleted the termination branch April 15, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants