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
1 change: 1 addition & 0 deletions api/v1/hypervisor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
ConditionReasonReadyReady = "Ready"
ConditionReasonReadyMaintenance = "Maintenance"
ConditionReasonReadyEvicted = "Evicted"
ConditionReasonReadyEvicting = "Evicting"

// ConditionTypeOnboarding reasons
ConditionReasonInitial = "Initial"
Expand Down
19 changes: 12 additions & 7 deletions internal/controller/hypervisor_maintenance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,22 @@ func (hec *HypervisorMaintenanceController) reconcileEviction(ctx context.Contex
message = "Evicted"
reason = kvmv1.ConditionReasonSucceeded
hv.Status.Evicted = true
meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
Type: kvmv1.ConditionTypeReady,
Status: metav1.ConditionFalse,
Reason: kvmv1.ConditionReasonReadyEvicted,
Message: "Hypervisor is disabled and evicted",
})
} else {
message = "Evicting"
reason = kvmv1.ConditionReasonRunning
hv.Status.Evicted = false
meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
Type: kvmv1.ConditionTypeReady,
Status: metav1.ConditionFalse,
Reason: kvmv1.ConditionReasonReadyEvicting,
Message: "Hypervisor is disabled and evicting",
})
}

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

meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
Type: kvmv1.ConditionTypeReady,
Status: metav1.ConditionFalse,
Reason: kvmv1.ConditionReasonReadyEvicted,
Message: "Hypervisor is disabled and evicted",
})

return nil
}

Expand Down
54 changes: 54 additions & 0 deletions internal/controller/hypervisor_maintenance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,60 @@ var _ = Describe("HypervisorMaintenanceController", func() {
})
})

When("there is an ongoing eviction", func() {
BeforeEach(func(ctx SpecContext) {
eviction := &kvmv1.Eviction{
ObjectMeta: metav1.ObjectMeta{Name: hypervisorName.Name},
Spec: kvmv1.EvictionSpec{
Hypervisor: hypervisorName.Name,
Reason: "test",
},
}
hypervisor := &kvmv1.Hypervisor{}
Expect(k8sClient.Get(ctx, hypervisorName, hypervisor)).To(Succeed())
Expect(controllerutil.SetControllerReference(hypervisor, eviction, controller.Scheme)).To(Succeed())
Expect(k8sClient.Create(ctx, eviction)).To(Succeed())

Expect(k8sClient.Get(ctx, hypervisorName, hypervisor)).To(Succeed())
meta.SetStatusCondition(&eviction.Status.Conditions, metav1.Condition{
Type: kvmv1.ConditionTypeEvicting,
Status: metav1.ConditionTrue,
Message: "whatever",
Reason: kvmv1.ConditionReasonRunning,
})
Expect(k8sClient.Status().Update(ctx, eviction)).To(Succeed())
})

It("should reflect it in the hypervisor evicting condition", func(ctx SpecContext) {
hypervisor := &kvmv1.Hypervisor{}
Expect(k8sClient.Get(ctx, hypervisorName, hypervisor)).To(Succeed())
Expect(hypervisor.Status.Conditions).To(ContainElement(
SatisfyAll(
HaveField("Type", kvmv1.ConditionTypeEvicting),
HaveField("Status", metav1.ConditionTrue),
HaveField("Reason", kvmv1.ConditionReasonRunning),
),
))
})

It("should reflect it in the hypervisor evicted status", func(ctx SpecContext) {
hypervisor := &kvmv1.Hypervisor{}
Expect(k8sClient.Get(ctx, hypervisorName, hypervisor)).To(Succeed())
Expect(hypervisor.Status.Evicted).To(BeFalse())
})

It("should set the ConditionTypeReady to false and reason to evicting", func(ctx SpecContext) {
updated := &kvmv1.Hypervisor{}
Expect(k8sClient.Get(ctx, hypervisorName, updated)).To(Succeed())
Expect(updated.Status.Conditions).To(ContainElement(
SatisfyAll(
HaveField("Type", kvmv1.ConditionTypeReady),
HaveField("Status", metav1.ConditionFalse),
HaveField("Reason", kvmv1.ConditionReasonReadyEvicting),
)))
})
})

When("there is a finished eviction", func() {
BeforeEach(func(ctx SpecContext) {
eviction := &kvmv1.Eviction{
Expand Down