Skip to content

Commit 6c733e0

Browse files
committed
Wait for eviction condition when offboarding and match eviction trigger
It doesn't make sense to poll openstack for the hypervisors, when we are still evicting, so wait for that. We have to match the condition to trigger the eviction and waiting on the eviction.
1 parent 21a6831 commit 6c733e0

3 files changed

Lines changed: 29 additions & 10 deletions

File tree

internal/controller/decomission_controller.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,18 @@ func (r *NodeDecommissionReconciler) Reconcile(ctx context.Context, req ctrl.Req
7878
return ctrl.Result{}, nil
7979
}
8080

81-
log.Info("removing host from nova")
81+
// Onboarding-condition needs to be either unset or set to false, so that we can continue
82+
// The first means, onboarding has never started, the second means it has been aborted or finished
83+
if meta.IsStatusConditionTrue(hv.Status.Conditions, kvmv1.ConditionTypeOnboarding) {
84+
return ctrl.Result{}, nil
85+
}
86+
87+
// If the service id is set, there might be VMs either from onboarding or even from normal operation
88+
// In that case we need to wait until those are evicted
89+
if hv.Status.ServiceID != "" && !meta.IsStatusConditionFalse(hv.Status.Conditions, kvmv1.ConditionTypeEvicting) {
90+
// Either has not evicted yet, or is still evicting VMs, so we have to wait for that to finish
91+
return ctrl.Result{}, nil
92+
}
8293

8394
hypervisor, err := openstack.GetHypervisorByName(ctx, r.computeClient, hostname, true)
8495
if err != nil {

internal/controller/decomission_controller_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ var _ = Describe("Decommission Controller", func() {
135135
Expect(k8sClient.Status().Update(ctx, hypervisor)).To(Succeed())
136136
})
137137

138-
When("the hypervisor was set to ready", func() {
138+
When("the hypervisor was set to ready and has been evicted", func() {
139139
getHypervisorsCalled := 0
140140
BeforeEach(func(ctx SpecContext) {
141141
hv := &kvmv1.Hypervisor{}
@@ -148,6 +148,12 @@ var _ = Describe("Decommission Controller", func() {
148148
Message: "dontcare",
149149
},
150150
)
151+
meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
152+
Type: kvmv1.ConditionTypeEvicting,
153+
Status: metav1.ConditionFalse,
154+
Reason: "dontcare",
155+
Message: "dontcare",
156+
})
151157
Expect(k8sClient.Status().Update(ctx, hv)).To(Succeed())
152158

153159
fakeServer.Mux.HandleFunc("GET /os-hypervisors/detail", func(w http.ResponseWriter, r *http.Request) {

internal/controller/hypervisor_maintenance_controller.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,17 @@ type HypervisorMaintenanceController struct {
5454
// +kubebuilder:rbac:groups=kvm.cloud.sap,resources=hypervisors,verbs=get;list;watch
5555
// +kubebuilder:rbac:groups=kvm.cloud.sap,resources=hypervisors/status,verbs=get;list;watch;create;update;patch;delete
5656
// +kubebuilder:rbac:groups=kvm.cloud.sap,resources=evictions,verbs=get;list;watch;create;update;patch;delete
57-
5857
func (hec *HypervisorMaintenanceController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
5958
hv := &kvmv1.Hypervisor{}
6059
if err := hec.Get(ctx, req.NamespacedName, hv); err != nil {
6160
// OnboardingReconciler not found errors, could be deleted
6261
return ctrl.Result{}, k8sclient.IgnoreNotFound(err)
6362
}
6463

65-
// is onboarding completed?
66-
if !meta.IsStatusConditionFalse(hv.Status.Conditions, kvmv1.ConditionTypeOnboarding) {
67-
return ctrl.Result{}, nil
68-
}
69-
70-
// ensure serviceId is set
71-
if hv.Status.ServiceID == "" {
64+
// If onboarding hasn't even started, no value will be set
65+
// If it has been started, but not finished yet, we need to wait for it to be aborted
66+
// So we can continue, if the condition is either not set at all or false
67+
if meta.IsStatusConditionTrue(hv.Status.Conditions, kvmv1.ConditionTypeOnboarding) {
7268
return ctrl.Result{}, nil
7369
}
7470

@@ -94,6 +90,12 @@ func (hec *HypervisorMaintenanceController) reconcileComputeService(ctx context.
9490
log := logger.FromContext(ctx)
9591
serviceId := hv.Status.ServiceID
9692

93+
// We can only do something here, if there is a service to begin with.
94+
// The onboarding should take care of that
95+
if serviceId == "" {
96+
return nil
97+
}
98+
9799
switch hv.Spec.Maintenance {
98100
case kvmv1.MaintenanceUnset:
99101
// Enable the compute service (in case we haven't done so already)

0 commit comments

Comments
 (0)