Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/v1/hypervisor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions internal/controller/hypervisor_maintenance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
30 changes: 25 additions & 5 deletions internal/controller/hypervisor_maintenance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
},
Expand All @@ -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",
},
)
Expand All @@ -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=""
})

Expand All @@ -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="<mode>"
}

Expand Down
3 changes: 1 addition & 2 deletions internal/controller/onboarding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const (
ConditionReasonOnboarding = "onboarding"
ConditionReasonTesting = "testing"
ConditionReasonCompleted = "completed"
ConditionReasonReady = "ready"
testAggregateName = "tenant_filter_tests"
testProjectName = "test"
testDomainName = "cc3test"
Expand Down Expand Up @@ -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",
})

Expand Down