From d54d8026eb422c9ea1905a219b299ec8ac55302a Mon Sep 17 00:00:00 2001 From: Fabian Wiesel Date: Tue, 7 Oct 2025 17:00:57 +0200 Subject: [PATCH] HypervisorController: Only update the status when needed We only need to update the status when it has changed. --- internal/controller/hypervisor_controller.go | 10 +++++----- internal/controller/hypervisor_controller_test.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/controller/hypervisor_controller.go b/internal/controller/hypervisor_controller.go index 25f0e765..4ebbe6db 100644 --- a/internal/controller/hypervisor_controller.go +++ b/internal/controller/hypervisor_controller.go @@ -96,21 +96,21 @@ func (hv *HypervisorController) Reconcile(ctx context.Context, req ctrl.Request) nodeTerminationCondition := FindNodeStatusCondition(node.Status.Conditions, "Terminating") if nodeTerminationCondition != nil && nodeTerminationCondition.Status == corev1.ConditionTrue { // Node might be terminating, propagate condition to hypervisor - meta.SetStatusCondition(&hypervisor.Status.Conditions, metav1.Condition{ + changed := meta.SetStatusCondition(&hypervisor.Status.Conditions, metav1.Condition{ Type: kvmv1.ConditionTypeReady, Status: metav1.ConditionFalse, Reason: nodeTerminationCondition.Reason, Message: nodeTerminationCondition.Message, - }) - meta.SetStatusCondition(&hypervisor.Status.Conditions, metav1.Condition{ + }) || meta.SetStatusCondition(&hypervisor.Status.Conditions, metav1.Condition{ Type: kvmv1.ConditionTypeTerminating, Status: metav1.ConditionStatus(nodeTerminationCondition.Status), Reason: nodeTerminationCondition.Reason, Message: nodeTerminationCondition.Message, }) - return ctrl.Result{}, hv.Status().Update(ctx, hypervisor) + if changed { + return ctrl.Result{}, hv.Status().Update(ctx, hypervisor) + } } - return ctrl.Result{}, nil } diff --git a/internal/controller/hypervisor_controller_test.go b/internal/controller/hypervisor_controller_test.go index 32ba6e17..094ff0ae 100644 --- a/internal/controller/hypervisor_controller_test.go +++ b/internal/controller/hypervisor_controller_test.go @@ -101,7 +101,7 @@ var _ = Describe("Hypervisor Controller", func() { Expect(k8sClient.Status().Update(ctx, resource)).To(Succeed()) By("Reconciling the created resource") - for i := 0; i < 2; i++ { + for i := 0; i < 3; i++ { _, err := hypervisorController.Reconcile(ctx, ctrl.Request{ NamespacedName: types.NamespacedName{Name: resource.Name}, })