Skip to content

Commit 9735d5f

Browse files
committed
Always evict, if there is even a chance of a VM
1 parent 5a5ce4c commit 9735d5f

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

internal/controller/decomission_controller.go

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

81-
if !meta.IsStatusConditionFalse(hv.Status.Conditions, kvmv1.ConditionTypeEvicting) {
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) {
8290
// Either has not evicted yet, or is still evicting VMs, so we have to wait for that to finish
8391
return ctrl.Result{}, nil
8492
}

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)