Skip to content

Commit 8267927

Browse files
committed
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.
1 parent 584e8e2 commit 8267927

3 files changed

Lines changed: 67 additions & 7 deletions

File tree

api/v1/hypervisor_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const (
5858
ConditionReasonReadyReady = "Ready"
5959
ConditionReasonReadyMaintenance = "Maintenance"
6060
ConditionReasonReadyEvicted = "Evicted"
61+
ConditionReasonReadyEvicting = "Evicting"
6162

6263
// ConditionTypeOnboarding reasons
6364
ConditionReasonInitial = "Initial"

internal/controller/hypervisor_maintenance_controller.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,22 @@ func (hec *HypervisorMaintenanceController) reconcileEviction(ctx context.Contex
194194
message = "Evicted"
195195
reason = kvmv1.ConditionReasonSucceeded
196196
hv.Status.Evicted = true
197+
meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
198+
Type: kvmv1.ConditionTypeReady,
199+
Status: metav1.ConditionFalse,
200+
Reason: kvmv1.ConditionReasonReadyEvicted,
201+
Message: "Hypervisor is disabled and evicted",
202+
})
197203
} else {
198204
message = "Evicting"
199205
reason = kvmv1.ConditionReasonRunning
200206
hv.Status.Evicted = false
207+
meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
208+
Type: kvmv1.ConditionTypeReady,
209+
Status: metav1.ConditionFalse,
210+
Reason: kvmv1.ConditionReasonReadyEvicting,
211+
Message: "Hypervisor is disabled and evicting",
212+
})
201213
}
202214

203215
meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
@@ -207,13 +219,6 @@ func (hec *HypervisorMaintenanceController) reconcileEviction(ctx context.Contex
207219
Message: message,
208220
})
209221

210-
meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
211-
Type: kvmv1.ConditionTypeReady,
212-
Status: metav1.ConditionFalse,
213-
Reason: kvmv1.ConditionReasonReadyEvicted,
214-
Message: "Hypervisor is disabled and evicted",
215-
})
216-
217222
return nil
218223
}
219224

internal/controller/hypervisor_maintenance_controller_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,60 @@ var _ = Describe("HypervisorMaintenanceController", func() {
291291
})
292292
})
293293

294+
When("there is an ongoing eviction", func() {
295+
BeforeEach(func(ctx SpecContext) {
296+
eviction := &kvmv1.Eviction{
297+
ObjectMeta: metav1.ObjectMeta{Name: hypervisorName.Name},
298+
Spec: kvmv1.EvictionSpec{
299+
Hypervisor: hypervisorName.Name,
300+
Reason: "test",
301+
},
302+
}
303+
hypervisor := &kvmv1.Hypervisor{}
304+
Expect(k8sClient.Get(ctx, hypervisorName, hypervisor)).To(Succeed())
305+
Expect(controllerutil.SetControllerReference(hypervisor, eviction, controller.Scheme)).To(Succeed())
306+
Expect(k8sClient.Create(ctx, eviction)).To(Succeed())
307+
308+
Expect(k8sClient.Get(ctx, hypervisorName, hypervisor)).To(Succeed())
309+
meta.SetStatusCondition(&eviction.Status.Conditions, metav1.Condition{
310+
Type: kvmv1.ConditionTypeEvicting,
311+
Status: metav1.ConditionTrue,
312+
Message: "whatever",
313+
Reason: kvmv1.ConditionReasonRunning,
314+
})
315+
Expect(k8sClient.Status().Update(ctx, eviction)).To(Succeed())
316+
})
317+
318+
It("should reflect it in the hypervisor evicting condition", func(ctx SpecContext) {
319+
hypervisor := &kvmv1.Hypervisor{}
320+
Expect(k8sClient.Get(ctx, hypervisorName, hypervisor)).To(Succeed())
321+
Expect(hypervisor.Status.Conditions).To(ContainElement(
322+
SatisfyAll(
323+
HaveField("Type", kvmv1.ConditionTypeEvicting),
324+
HaveField("Status", metav1.ConditionTrue),
325+
HaveField("Reason", kvmv1.ConditionReasonRunning),
326+
),
327+
))
328+
})
329+
330+
It("should reflect it in the hypervisor evicted status", func(ctx SpecContext) {
331+
hypervisor := &kvmv1.Hypervisor{}
332+
Expect(k8sClient.Get(ctx, hypervisorName, hypervisor)).To(Succeed())
333+
Expect(hypervisor.Status.Evicted).To(BeFalse())
334+
})
335+
336+
It("should set the ConditionTypeReady to false and reason to evicting", func(ctx SpecContext) {
337+
updated := &kvmv1.Hypervisor{}
338+
Expect(k8sClient.Get(ctx, hypervisorName, updated)).To(Succeed())
339+
Expect(updated.Status.Conditions).To(ContainElement(
340+
SatisfyAll(
341+
HaveField("Type", kvmv1.ConditionTypeReady),
342+
HaveField("Status", metav1.ConditionFalse),
343+
HaveField("Reason", kvmv1.ConditionReasonReadyEvicting),
344+
)))
345+
})
346+
})
347+
294348
When("there is a finished eviction", func() {
295349
BeforeEach(func(ctx SpecContext) {
296350
eviction := &kvmv1.Eviction{

0 commit comments

Comments
 (0)