Skip to content

Commit f154d9e

Browse files
committed
HypervisorMaintenance: Update hypervisor ready condition
When we disable the hypervisor, it should be marked as not ready.
1 parent 61fafed commit f154d9e

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

api/v1/hypervisor_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ const (
3030
// ConditionTypeReady is the type of condition for ready status of a hypervisor
3131
ConditionTypeReady = "Ready"
3232
ConditionTypeTerminating = "Terminating"
33+
34+
// Reasons for the various being ready...
35+
ConditionReasonReadyReady = "ready"
36+
// or not
37+
ConditionReasonReadyMaintenance = "maintenance"
3338
)
3439

3540
// HypervisorSpec defines the desired state of Hypervisor

internal/controller/hypervisor_maintenance_controller.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,20 @@ func (hec *HypervisorMaintenanceController) reconcileComputeService(ctx context.
9393
if !meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
9494
Type: kvmv1.ConditionTypeHypervisorDisabled,
9595
Status: metav1.ConditionFalse,
96-
Message: "Hypervisor enabled",
96+
Message: "Hypervisor is enabled",
9797
Reason: kvmv1.ConditionReasonSucceeded,
9898
}) {
9999
// Spec matches status
100100
return false, nil
101101
}
102+
103+
meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
104+
Type: kvmv1.ConditionTypeReady,
105+
Status: metav1.ConditionTrue,
106+
Reason: kvmv1.ConditionReasonReadyReady,
107+
Message: "Hypervisor is ready",
108+
})
109+
102110
// We need to enable the host as per spec
103111
enableService := services.UpdateOpts{Status: services.ServiceEnabled}
104112
log.Info("Enabling hypervisor", "id", serviceId)
@@ -110,13 +118,20 @@ func (hec *HypervisorMaintenanceController) reconcileComputeService(ctx context.
110118
if !meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
111119
Type: kvmv1.ConditionTypeHypervisorDisabled,
112120
Status: metav1.ConditionTrue,
113-
Message: "Hypervisor disabled",
121+
Message: "Hypervisor is disabled",
114122
Reason: kvmv1.ConditionReasonSucceeded,
115123
}) {
116124
// Spec matches status
117125
return false, nil
118126
}
119127

128+
meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
129+
Type: kvmv1.ConditionTypeReady,
130+
Status: metav1.ConditionFalse,
131+
Reason: kvmv1.ConditionReasonReadyMaintenance,
132+
Message: "Hypervisor is disabled",
133+
})
134+
120135
// We need to disable the host as per spec
121136
enableService := services.UpdateOpts{
122137
Status: services.ServiceDisabled,

internal/controller/hypervisor_maintenance_controller_test.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
. "github.com/onsi/ginkgo/v2"
2828
. "github.com/onsi/gomega"
2929
"k8s.io/apimachinery/pkg/api/meta"
30-
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/apimachinery/pkg/types"
3232
ctrl "sigs.k8s.io/controller-runtime"
3333

@@ -90,7 +90,7 @@ var _ = Describe("HypervisorServiceController", func() {
9090

9191
By("Creating a blank Hypervisor resource")
9292
hypervisor := &kvmv1.Hypervisor{
93-
ObjectMeta: v1.ObjectMeta{
93+
ObjectMeta: metav1.ObjectMeta{
9494
Name: hypervisorName.Name,
9595
Namespace: hypervisorName.Namespace,
9696
},
@@ -116,10 +116,10 @@ var _ = Describe("HypervisorServiceController", func() {
116116
Expect(tc.Client.Get(ctx, hypervisorName, hypervisor)).To(Succeed())
117117
hypervisor.Status.ServiceID = "1234"
118118
meta.SetStatusCondition(&hypervisor.Status.Conditions,
119-
v1.Condition{
119+
metav1.Condition{
120120
Type: ConditionTypeOnboarding,
121-
Status: v1.ConditionFalse,
122-
Reason: v1.StatusSuccess,
121+
Status: metav1.ConditionFalse,
122+
Reason: metav1.StatusSuccess,
123123
Message: "random text",
124124
},
125125
)
@@ -146,6 +146,16 @@ var _ = Describe("HypervisorServiceController", func() {
146146
Expect(tc.Client.Get(ctx, hypervisorName, updated)).To(Succeed())
147147
Expect(meta.IsStatusConditionFalse(updated.Status.Conditions, kvmv1.ConditionTypeHypervisorDisabled)).To(BeTrue())
148148
})
149+
150+
It("should set the ConditionTypeReady to true", func() {
151+
updated := &kvmv1.Hypervisor{}
152+
Expect(tc.Client.Get(ctx, hypervisorName, updated)).To(Succeed())
153+
Expect(updated.Status.Conditions).To(ContainElement(
154+
SatisfyAll(
155+
HaveField("Type", kvmv1.ConditionTypeReady),
156+
HaveField("Status", metav1.ConditionTrue),
157+
)))
158+
})
149159
}) // Spec.Maintenance=""
150160
})
151161

@@ -168,6 +178,16 @@ var _ = Describe("HypervisorServiceController", func() {
168178
Expect(tc.Client.Get(ctx, hypervisorName, updated)).To(Succeed())
169179
Expect(meta.IsStatusConditionTrue(updated.Status.Conditions, kvmv1.ConditionTypeHypervisorDisabled)).To(BeTrue())
170180
})
181+
182+
It("should set the ConditionTypeReady to false", func() {
183+
updated := &kvmv1.Hypervisor{}
184+
Expect(tc.Client.Get(ctx, hypervisorName, updated)).To(Succeed())
185+
Expect(updated.Status.Conditions).To(ContainElement(
186+
SatisfyAll(
187+
HaveField("Type", kvmv1.ConditionTypeReady),
188+
HaveField("Status", metav1.ConditionFalse),
189+
)))
190+
})
171191
}) // Spec.Maintenance="<mode>"
172192
}
173193

internal/controller/onboarding_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ const (
5757
ConditionReasonOnboarding = "onboarding"
5858
ConditionReasonTesting = "testing"
5959
ConditionReasonCompleted = "completed"
60-
ConditionReasonReady = "ready"
6160
testAggregateName = "tenant_filter_tests"
6261
testProjectName = "test"
6362
testDomainName = "cc3test"
@@ -306,7 +305,7 @@ func (r *OnboardingController) completeOnboarding(ctx context.Context, host stri
306305
meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
307306
Type: kvmv1.ConditionTypeReady,
308307
Status: metav1.ConditionTrue,
309-
Reason: ConditionReasonReady,
308+
Reason: kvmv1.ConditionReasonReadyReady,
310309
Message: "Hypervisor is ready",
311310
})
312311

0 commit comments

Comments
 (0)