Skip to content

Commit e40975f

Browse files
Merge pull request openstack-k8s-operators#370 from gibizer/namespace-delete
Fix reconcileDelete during namespace delete
2 parents 4eb40d4 + 966da9c commit e40975f

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

controllers/keystoneendpoint_controller.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ func (r *KeystoneEndpointReconciler) Reconcile(ctx context.Context, req ctrl.Req
157157
return ctrl.Result{}, err
158158
}
159159

160+
// If both the endpoint and the KeystoneAPI is deleted then we can skip
161+
// the cleanup of the endpoint in the DB as the DB is going away as well.
162+
// Moreover if KeystoneAPI is being deleted then we cannot talk to the
163+
// keystone REST API any more. This happens for example during namespace
164+
// deletion.
165+
if !instance.DeletionTimestamp.IsZero() && !keystoneAPI.DeletionTimestamp.IsZero() {
166+
return r.reconcileDeleteFinalizersOnly(ctx, instance, helper, keystoneAPI)
167+
}
168+
160169
// If this KeystoneEndpoint CR is being deleted and it has not registered any actual
161170
// endpoints on the OpenStack side, just redirect execution to the "reconcileDelete()"
162171
// logic to avoid potentially hanging on waiting for the KeystoneAPI to be ready
@@ -303,6 +312,43 @@ func (r *KeystoneEndpointReconciler) reconcileDelete(
303312
return ctrl.Result{}, nil
304313
}
305314

315+
func (r *KeystoneEndpointReconciler) reconcileDeleteFinalizersOnly(
316+
ctx context.Context,
317+
instance *keystonev1.KeystoneEndpoint,
318+
helper *helper.Helper,
319+
keystoneAPI *keystonev1.KeystoneAPI,
320+
) (ctrl.Result, error) {
321+
l := GetLog(ctx)
322+
l.Info("Reconciling Endpoint delete while KeystoneAPI is being deleted")
323+
324+
ksSvc, err := keystonev1.GetKeystoneServiceWithName(ctx, helper, instance.Spec.ServiceName, instance.Namespace)
325+
if err == nil {
326+
// Remove the finalizer for this endpoint from the Service
327+
if controllerutil.RemoveFinalizer(ksSvc, fmt.Sprintf("%s-%s", helper.GetFinalizer(), instance.Name)) {
328+
err := r.Update(ctx, ksSvc)
329+
330+
if err != nil {
331+
return ctrl.Result{}, err
332+
}
333+
}
334+
} else if !k8s_errors.IsNotFound(err) {
335+
return ctrl.Result{}, err
336+
}
337+
338+
if controllerutil.RemoveFinalizer(keystoneAPI, fmt.Sprintf("%s-%s", helper.GetFinalizer(), instance.Name)) {
339+
err := r.Update(ctx, keystoneAPI)
340+
341+
if err != nil {
342+
return ctrl.Result{}, err
343+
}
344+
}
345+
346+
controllerutil.RemoveFinalizer(instance, helper.GetFinalizer())
347+
l.Info("Reconciled Endpoint delete successfully")
348+
349+
return ctrl.Result{}, nil
350+
}
351+
306352
func (r *KeystoneEndpointReconciler) reconcileNormal(
307353
ctx context.Context,
308354
instance *keystonev1.KeystoneEndpoint,

controllers/keystoneservice_controller.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ func (r *KeystoneServiceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
170170
return ctrl.Result{}, err
171171
}
172172

173+
// If both the service and the KeystoneAPI is deleted then we can skip
174+
// the cleanup of the service in the DB as the DB is going away as well.
175+
// Moreover if KeystoneAPI is being deleted then we cannot talk to the
176+
// keystone REST API any more. This happens for example during namespace
177+
// deletion.
178+
if !instance.DeletionTimestamp.IsZero() && !keystoneAPI.DeletionTimestamp.IsZero() {
179+
return r.reconcileDeleteFinalizersOnly(ctx, instance, helper, keystoneAPI)
180+
}
181+
173182
// If this KeystoneService CR is being deleted and it has not registered any actual
174183
// service on the OpenStack side, just redirect execution to the "reconcileDelete()"
175184
// logic to avoid potentially hanging on waiting for the KeystoneAPI to be ready
@@ -301,6 +310,29 @@ func (r *KeystoneServiceReconciler) reconcileDelete(
301310
return ctrl.Result{}, nil
302311
}
303312

313+
func (r *KeystoneServiceReconciler) reconcileDeleteFinalizersOnly(
314+
ctx context.Context,
315+
instance *keystonev1.KeystoneService,
316+
helper *helper.Helper,
317+
keystoneAPI *keystonev1.KeystoneAPI,
318+
) (ctrl.Result, error) {
319+
l := GetLog(ctx)
320+
l.Info("Reconciling Service delete while KeystoneAPI is being deleted")
321+
322+
if controllerutil.RemoveFinalizer(keystoneAPI, fmt.Sprintf("%s-%s", helper.GetFinalizer(), instance.Name)) {
323+
err := r.Update(ctx, keystoneAPI)
324+
325+
if err != nil {
326+
return ctrl.Result{}, err
327+
}
328+
}
329+
330+
controllerutil.RemoveFinalizer(instance, helper.GetFinalizer())
331+
l.Info("Reconciled Service delete successfully")
332+
333+
return ctrl.Result{}, nil
334+
}
335+
304336
func (r *KeystoneServiceReconciler) reconcileNormal(
305337
ctx context.Context,
306338
instance *keystonev1.KeystoneService,

0 commit comments

Comments
 (0)