From 0eb17375436405ea859020087a0ff90d436719db Mon Sep 17 00:00:00 2001 From: Fabian Wiesel Date: Fri, 13 Feb 2026 10:31:17 +0100 Subject: [PATCH] Maintenance: Fix summary when evicting Before this change, the summary was setting the hypervisor summary condition 'Ready' to the same value, regardless if the eviction was ongoing or not. In both cases, the description and reason was saying *evicted*, which is incorrect. This fixes the reason and message to *evicting* when the eviction is still ongoing. --- api/v1/hypervisor_types.go | 1 + .../hypervisor_maintenance_controller.go | 19 ++++--- .../hypervisor_maintenance_controller_test.go | 54 +++++++++++++++++++ 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/api/v1/hypervisor_types.go b/api/v1/hypervisor_types.go index b285b955..714c3105 100644 --- a/api/v1/hypervisor_types.go +++ b/api/v1/hypervisor_types.go @@ -58,6 +58,7 @@ const ( ConditionReasonReadyReady = "Ready" ConditionReasonReadyMaintenance = "Maintenance" ConditionReasonReadyEvicted = "Evicted" + ConditionReasonReadyEvicting = "Evicting" // ConditionTypeOnboarding reasons ConditionReasonInitial = "Initial" diff --git a/internal/controller/hypervisor_maintenance_controller.go b/internal/controller/hypervisor_maintenance_controller.go index 928b7255..eeaee0ae 100644 --- a/internal/controller/hypervisor_maintenance_controller.go +++ b/internal/controller/hypervisor_maintenance_controller.go @@ -194,10 +194,22 @@ func (hec *HypervisorMaintenanceController) reconcileEviction(ctx context.Contex message = "Evicted" reason = kvmv1.ConditionReasonSucceeded hv.Status.Evicted = true + meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{ + Type: kvmv1.ConditionTypeReady, + Status: metav1.ConditionFalse, + Reason: kvmv1.ConditionReasonReadyEvicted, + Message: "Hypervisor is disabled and evicted", + }) } else { message = "Evicting" reason = kvmv1.ConditionReasonRunning hv.Status.Evicted = false + meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{ + Type: kvmv1.ConditionTypeReady, + Status: metav1.ConditionFalse, + Reason: kvmv1.ConditionReasonReadyEvicting, + Message: "Hypervisor is disabled and evicting", + }) } meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{ @@ -207,13 +219,6 @@ func (hec *HypervisorMaintenanceController) reconcileEviction(ctx context.Contex Message: message, }) - meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{ - Type: kvmv1.ConditionTypeReady, - Status: metav1.ConditionFalse, - Reason: kvmv1.ConditionReasonReadyEvicted, - Message: "Hypervisor is disabled and evicted", - }) - return nil } diff --git a/internal/controller/hypervisor_maintenance_controller_test.go b/internal/controller/hypervisor_maintenance_controller_test.go index 07cd7e16..234ec068 100644 --- a/internal/controller/hypervisor_maintenance_controller_test.go +++ b/internal/controller/hypervisor_maintenance_controller_test.go @@ -291,6 +291,60 @@ var _ = Describe("HypervisorMaintenanceController", func() { }) }) + When("there is an ongoing eviction", func() { + BeforeEach(func(ctx SpecContext) { + eviction := &kvmv1.Eviction{ + ObjectMeta: metav1.ObjectMeta{Name: hypervisorName.Name}, + Spec: kvmv1.EvictionSpec{ + Hypervisor: hypervisorName.Name, + Reason: "test", + }, + } + hypervisor := &kvmv1.Hypervisor{} + Expect(k8sClient.Get(ctx, hypervisorName, hypervisor)).To(Succeed()) + Expect(controllerutil.SetControllerReference(hypervisor, eviction, controller.Scheme)).To(Succeed()) + Expect(k8sClient.Create(ctx, eviction)).To(Succeed()) + + Expect(k8sClient.Get(ctx, hypervisorName, hypervisor)).To(Succeed()) + meta.SetStatusCondition(&eviction.Status.Conditions, metav1.Condition{ + Type: kvmv1.ConditionTypeEvicting, + Status: metav1.ConditionTrue, + Message: "whatever", + Reason: kvmv1.ConditionReasonRunning, + }) + Expect(k8sClient.Status().Update(ctx, eviction)).To(Succeed()) + }) + + It("should reflect it in the hypervisor evicting condition", func(ctx SpecContext) { + hypervisor := &kvmv1.Hypervisor{} + Expect(k8sClient.Get(ctx, hypervisorName, hypervisor)).To(Succeed()) + Expect(hypervisor.Status.Conditions).To(ContainElement( + SatisfyAll( + HaveField("Type", kvmv1.ConditionTypeEvicting), + HaveField("Status", metav1.ConditionTrue), + HaveField("Reason", kvmv1.ConditionReasonRunning), + ), + )) + }) + + It("should reflect it in the hypervisor evicted status", func(ctx SpecContext) { + hypervisor := &kvmv1.Hypervisor{} + Expect(k8sClient.Get(ctx, hypervisorName, hypervisor)).To(Succeed()) + Expect(hypervisor.Status.Evicted).To(BeFalse()) + }) + + It("should set the ConditionTypeReady to false and reason to evicting", func(ctx SpecContext) { + updated := &kvmv1.Hypervisor{} + Expect(k8sClient.Get(ctx, hypervisorName, updated)).To(Succeed()) + Expect(updated.Status.Conditions).To(ContainElement( + SatisfyAll( + HaveField("Type", kvmv1.ConditionTypeReady), + HaveField("Status", metav1.ConditionFalse), + HaveField("Reason", kvmv1.ConditionReasonReadyEvicting), + ))) + }) + }) + When("there is a finished eviction", func() { BeforeEach(func(ctx SpecContext) { eviction := &kvmv1.Eviction{