Skip to content

Commit e12357a

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 e923ff7 commit e12357a

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"
@@ -87,17 +88,18 @@ func (r *OnboardingController) Reconcile(ctx context.Context, req ctrl.Request)
8788
return ctrl.Result{}, k8sclient.IgnoreNotFound(err)
8889
}
8990

91+
computeHost := hv.Name
92+
9093
// check if lifecycle management is enabled
9194
if !hv.Spec.LifecycleEnabled {
92-
return ctrl.Result{}, nil
95+
return r.abortOnboarding(ctx, hv, computeHost)
9396
}
9497

9598
// check if hv is terminating
9699
if meta.IsStatusConditionTrue(hv.Status.Conditions, kvmv1.ConditionTypeTerminating) {
97-
return ctrl.Result{}, nil
100+
return r.abortOnboarding(ctx, hv, computeHost)
98101
}
99102

100-
computeHost := hv.Name
101103
// We bail here out, because the openstack api is not the best to poll
102104
if hv.Status.HypervisorID == "" || hv.Status.ServiceID == "" {
103105
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
@@ -144,6 +146,34 @@ func (r *OnboardingController) Reconcile(ctx context.Context, req ctrl.Request)
144146
}
145147
}
146148

149+
func (r *OnboardingController) abortOnboarding(ctx context.Context, hv *kvmv1.Hypervisor, computeHost string) (ctrl.Result, error) {
150+
status := meta.FindStatusCondition(hv.Status.Conditions, ConditionTypeOnboarding)
151+
// Never onboarded
152+
if status == nil {
153+
return ctrl.Result{}, nil
154+
}
155+
156+
changed := meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
157+
Type: kvmv1.ConditionTypeReady,
158+
Status: metav1.ConditionFalse,
159+
Reason: ConditionReasonOnboarding,
160+
Message: "Onboarding aborted",
161+
}) || meta.SetStatusCondition(&hv.Status.Conditions, metav1.Condition{
162+
Type: ConditionTypeOnboarding,
163+
Status: metav1.ConditionTrue,
164+
Reason: ConditionReasonAborted,
165+
Message: "Aborted due to LivecycleEnabled being false",
166+
})
167+
if !changed {
168+
// Already aborted
169+
return ctrl.Result{}, nil
170+
}
171+
if err := r.deleteTestServers(ctx, computeHost); err != nil {
172+
return ctrl.Result{}, err
173+
}
174+
return ctrl.Result{}, r.Status().Update(ctx, hv)
175+
}
176+
147177
func (r *OnboardingController) initialOnboarding(ctx context.Context, hv *kvmv1.Hypervisor, host string) error {
148178
zone, found := hv.Labels[corev1.LabelTopologyZone]
149179
if !found || zone == "" {

0 commit comments

Comments
 (0)