Skip to content

Commit 0ee2627

Browse files
committed
Onboarding: Cleanup also when we need to abort
The spec can disable the life-cycle or we can get a terminating condition, even while we are testing. We better clean up the test instances then too.
1 parent 3c760f7 commit 0ee2627

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

internal/controller/onboarding_controller.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var errRequeue = errors.New("requeue requested")
5353
const (
5454
defaultWaitTime = 1 * time.Minute
5555
ConditionTypeOnboarding = "Onboarding"
56+
ConditionReasonAborted = "aborted"
5657
ConditionReasonInitial = "initial"
5758
ConditionReasonOnboarding = "onboarding"
5859
ConditionReasonTesting = "testing"
@@ -102,17 +103,18 @@ func (r *OnboardingController) Reconcile(ctx context.Context, req ctrl.Request)
102103
return ctrl.Result{}, k8sclient.IgnoreNotFound(err)
103104
}
104105

106+
computeHost := hv.Name
107+
105108
// check if lifecycle management is enabled
106109
if !hv.Spec.LifecycleEnabled {
107-
return ctrl.Result{}, nil
110+
return r.abortOnboarding(ctx, hv, computeHost)
108111
}
109112

110113
// check if hv is terminating
111114
if meta.IsStatusConditionTrue(hv.Status.Conditions, kvmv1.ConditionTypeTerminating) {
112-
return ctrl.Result{}, nil
115+
return r.abortOnboarding(ctx, hv, computeHost)
113116
}
114117

115-
computeHost := hv.Name
116118
// We bail here out, because the openstack api is not the best to poll
117119
if hv.Status.HypervisorID == "" || hv.Status.ServiceID == "" {
118120
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
@@ -169,6 +171,34 @@ func (r *OnboardingController) Reconcile(ctx context.Context, req ctrl.Request)
169171
}
170172
}
171173

174+
func (r *OnboardingController) abortOnboarding(ctx context.Context, hv *kvmv1.Hypervisor, computeHost string) (ctrl.Result, error) {
175+
status := meta.FindStatusCondition(hv.Status.Conditions, ConditionTypeOnboarding)
176+
// Never onboarded
177+
if status == nil {
178+
return ctrl.Result{}, nil
179+
}
180+
181+
changed := meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
182+
Type: kvmv1.ConditionTypeReady,
183+
Status: metav1.ConditionFalse,
184+
Reason: ConditionReasonOnboarding,
185+
Message: "Onboarding aborted",
186+
}) || meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
187+
Type: ConditionTypeOnboarding,
188+
Status: metav1.ConditionTrue,
189+
Reason: ConditionReasonAborted,
190+
Message: "Aborted due to LivecycleEnabled being false",
191+
})
192+
if !changed {
193+
// Already aborted
194+
return ctrl.Result{}, nil
195+
}
196+
if err := r.deleteTestServers(ctx, computeHost); err != nil {
197+
return ctrl.Result{}, err
198+
}
199+
return ctrl.Result{}, r.Status().Update(ctx, hv)
200+
}
201+
172202
func (r *OnboardingController) initialOnboarding(ctx context.Context, hv *kvmv1.Hypervisor, host string) error {
173203
node := &corev1.Node{}
174204
if err := r.Get(ctx, types.NamespacedName{Name: hv.Name}, node); err != nil {

0 commit comments

Comments
 (0)