From 81c15cfc9c2c73ff3a2247f4d6e59241f6ca1f08 Mon Sep 17 00:00:00 2001 From: Fabian Wiesel Date: Mon, 17 Nov 2025 16:39:10 +0100 Subject: [PATCH] HypervisorMaintenance: Update hypervisor ready condition When we disable the hypervisor, it should be marked as not ready. --- api/v1/hypervisor_types.go | 5 ++++ .../hypervisor_maintenance_controller.go | 19 ++++++++++-- .../hypervisor_maintenance_controller_test.go | 30 +++++++++++++++---- internal/controller/onboarding_controller.go | 3 +- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/api/v1/hypervisor_types.go b/api/v1/hypervisor_types.go index b5ed1d18..ffdfaeaa 100644 --- a/api/v1/hypervisor_types.go +++ b/api/v1/hypervisor_types.go @@ -30,6 +30,11 @@ const ( // ConditionTypeReady is the type of condition for ready status of a hypervisor ConditionTypeReady = "Ready" ConditionTypeTerminating = "Terminating" + + // Reasons for the various being ready... + ConditionReasonReadyReady = "ready" + // or not + ConditionReasonReadyMaintenance = "maintenance" ) // HypervisorSpec defines the desired state of Hypervisor diff --git a/internal/controller/hypervisor_maintenance_controller.go b/internal/controller/hypervisor_maintenance_controller.go index e95fea70..336c8cd0 100644 --- a/internal/controller/hypervisor_maintenance_controller.go +++ b/internal/controller/hypervisor_maintenance_controller.go @@ -93,12 +93,20 @@ func (hec *HypervisorMaintenanceController) reconcileComputeService(ctx context. if !meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{ Type: kvmv1.ConditionTypeHypervisorDisabled, Status: metav1.ConditionFalse, - Message: "Hypervisor enabled", + Message: "Hypervisor is enabled", Reason: kvmv1.ConditionReasonSucceeded, }) { // Spec matches status return false, nil } + + meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{ + Type: kvmv1.ConditionTypeReady, + Status: metav1.ConditionTrue, + Reason: kvmv1.ConditionReasonReadyReady, + Message: "Hypervisor is ready", + }) + // We need to enable the host as per spec enableService := services.UpdateOpts{Status: services.ServiceEnabled} log.Info("Enabling hypervisor", "id", serviceId) @@ -110,13 +118,20 @@ func (hec *HypervisorMaintenanceController) reconcileComputeService(ctx context. if !meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{ Type: kvmv1.ConditionTypeHypervisorDisabled, Status: metav1.ConditionTrue, - Message: "Hypervisor disabled", + Message: "Hypervisor is disabled", Reason: kvmv1.ConditionReasonSucceeded, }) { // Spec matches status return false, nil } + meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{ + Type: kvmv1.ConditionTypeReady, + Status: metav1.ConditionFalse, + Reason: kvmv1.ConditionReasonReadyMaintenance, + Message: "Hypervisor is disabled", + }) + // We need to disable the host as per spec enableService := services.UpdateOpts{ Status: services.ServiceDisabled, diff --git a/internal/controller/hypervisor_maintenance_controller_test.go b/internal/controller/hypervisor_maintenance_controller_test.go index c39d7343..bed5fc5b 100644 --- a/internal/controller/hypervisor_maintenance_controller_test.go +++ b/internal/controller/hypervisor_maintenance_controller_test.go @@ -27,7 +27,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/api/meta" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" @@ -90,7 +90,7 @@ var _ = Describe("HypervisorServiceController", func() { By("Creating a blank Hypervisor resource") hypervisor := &kvmv1.Hypervisor{ - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: hypervisorName.Name, Namespace: hypervisorName.Namespace, }, @@ -116,10 +116,10 @@ var _ = Describe("HypervisorServiceController", func() { Expect(tc.Client.Get(ctx, hypervisorName, hypervisor)).To(Succeed()) hypervisor.Status.ServiceID = "1234" meta.SetStatusCondition(&hypervisor.Status.Conditions, - v1.Condition{ + metav1.Condition{ Type: ConditionTypeOnboarding, - Status: v1.ConditionFalse, - Reason: v1.StatusSuccess, + Status: metav1.ConditionFalse, + Reason: metav1.StatusSuccess, Message: "random text", }, ) @@ -146,6 +146,16 @@ var _ = Describe("HypervisorServiceController", func() { Expect(tc.Client.Get(ctx, hypervisorName, updated)).To(Succeed()) Expect(meta.IsStatusConditionFalse(updated.Status.Conditions, kvmv1.ConditionTypeHypervisorDisabled)).To(BeTrue()) }) + + It("should set the ConditionTypeReady to true", func() { + updated := &kvmv1.Hypervisor{} + Expect(tc.Client.Get(ctx, hypervisorName, updated)).To(Succeed()) + Expect(updated.Status.Conditions).To(ContainElement( + SatisfyAll( + HaveField("Type", kvmv1.ConditionTypeReady), + HaveField("Status", metav1.ConditionTrue), + ))) + }) }) // Spec.Maintenance="" }) @@ -168,6 +178,16 @@ var _ = Describe("HypervisorServiceController", func() { Expect(tc.Client.Get(ctx, hypervisorName, updated)).To(Succeed()) Expect(meta.IsStatusConditionTrue(updated.Status.Conditions, kvmv1.ConditionTypeHypervisorDisabled)).To(BeTrue()) }) + + It("should set the ConditionTypeReady to false", func() { + updated := &kvmv1.Hypervisor{} + Expect(tc.Client.Get(ctx, hypervisorName, updated)).To(Succeed()) + Expect(updated.Status.Conditions).To(ContainElement( + SatisfyAll( + HaveField("Type", kvmv1.ConditionTypeReady), + HaveField("Status", metav1.ConditionFalse), + ))) + }) }) // Spec.Maintenance="" } diff --git a/internal/controller/onboarding_controller.go b/internal/controller/onboarding_controller.go index 43bd7f03..ef0c7675 100644 --- a/internal/controller/onboarding_controller.go +++ b/internal/controller/onboarding_controller.go @@ -57,7 +57,6 @@ const ( ConditionReasonOnboarding = "onboarding" ConditionReasonTesting = "testing" ConditionReasonCompleted = "completed" - ConditionReasonReady = "ready" testAggregateName = "tenant_filter_tests" testProjectName = "test" testDomainName = "cc3test" @@ -306,7 +305,7 @@ func (r *OnboardingController) completeOnboarding(ctx context.Context, host stri meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{ Type: kvmv1.ConditionTypeReady, Status: metav1.ConditionTrue, - Reason: ConditionReasonReady, + Reason: kvmv1.ConditionReasonReadyReady, Message: "Hypervisor is ready", })