Skip to content

Commit

Permalink
Merge pull request #370 from gibizer/namespace-delete
Browse files Browse the repository at this point in the history
Fix reconcileDelete during namespace delete
  • Loading branch information
openshift-merge-bot[bot] authored Feb 13, 2024
2 parents 4eb40d4 + 966da9c commit e40975f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
46 changes: 46 additions & 0 deletions controllers/keystoneendpoint_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ func (r *KeystoneEndpointReconciler) Reconcile(ctx context.Context, req ctrl.Req
return ctrl.Result{}, err
}

// If both the endpoint and the KeystoneAPI is deleted then we can skip
// the cleanup of the endpoint in the DB as the DB is going away as well.
// Moreover if KeystoneAPI is being deleted then we cannot talk to the
// keystone REST API any more. This happens for example during namespace
// deletion.
if !instance.DeletionTimestamp.IsZero() && !keystoneAPI.DeletionTimestamp.IsZero() {
return r.reconcileDeleteFinalizersOnly(ctx, instance, helper, keystoneAPI)
}

// If this KeystoneEndpoint CR is being deleted and it has not registered any actual
// endpoints on the OpenStack side, just redirect execution to the "reconcileDelete()"
// logic to avoid potentially hanging on waiting for the KeystoneAPI to be ready
Expand Down Expand Up @@ -303,6 +312,43 @@ func (r *KeystoneEndpointReconciler) reconcileDelete(
return ctrl.Result{}, nil
}

func (r *KeystoneEndpointReconciler) reconcileDeleteFinalizersOnly(
ctx context.Context,
instance *keystonev1.KeystoneEndpoint,
helper *helper.Helper,
keystoneAPI *keystonev1.KeystoneAPI,
) (ctrl.Result, error) {
l := GetLog(ctx)
l.Info("Reconciling Endpoint delete while KeystoneAPI is being deleted")

ksSvc, err := keystonev1.GetKeystoneServiceWithName(ctx, helper, instance.Spec.ServiceName, instance.Namespace)
if err == nil {
// Remove the finalizer for this endpoint from the Service
if controllerutil.RemoveFinalizer(ksSvc, fmt.Sprintf("%s-%s", helper.GetFinalizer(), instance.Name)) {
err := r.Update(ctx, ksSvc)

if err != nil {
return ctrl.Result{}, err
}
}
} else if !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}

if controllerutil.RemoveFinalizer(keystoneAPI, fmt.Sprintf("%s-%s", helper.GetFinalizer(), instance.Name)) {
err := r.Update(ctx, keystoneAPI)

if err != nil {
return ctrl.Result{}, err
}
}

controllerutil.RemoveFinalizer(instance, helper.GetFinalizer())
l.Info("Reconciled Endpoint delete successfully")

return ctrl.Result{}, nil
}

func (r *KeystoneEndpointReconciler) reconcileNormal(
ctx context.Context,
instance *keystonev1.KeystoneEndpoint,
Expand Down
32 changes: 32 additions & 0 deletions controllers/keystoneservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ func (r *KeystoneServiceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, err
}

// If both the service and the KeystoneAPI is deleted then we can skip
// the cleanup of the service in the DB as the DB is going away as well.
// Moreover if KeystoneAPI is being deleted then we cannot talk to the
// keystone REST API any more. This happens for example during namespace
// deletion.
if !instance.DeletionTimestamp.IsZero() && !keystoneAPI.DeletionTimestamp.IsZero() {
return r.reconcileDeleteFinalizersOnly(ctx, instance, helper, keystoneAPI)
}

// If this KeystoneService CR is being deleted and it has not registered any actual
// service on the OpenStack side, just redirect execution to the "reconcileDelete()"
// logic to avoid potentially hanging on waiting for the KeystoneAPI to be ready
Expand Down Expand Up @@ -301,6 +310,29 @@ func (r *KeystoneServiceReconciler) reconcileDelete(
return ctrl.Result{}, nil
}

func (r *KeystoneServiceReconciler) reconcileDeleteFinalizersOnly(
ctx context.Context,
instance *keystonev1.KeystoneService,
helper *helper.Helper,
keystoneAPI *keystonev1.KeystoneAPI,
) (ctrl.Result, error) {
l := GetLog(ctx)
l.Info("Reconciling Service delete while KeystoneAPI is being deleted")

if controllerutil.RemoveFinalizer(keystoneAPI, fmt.Sprintf("%s-%s", helper.GetFinalizer(), instance.Name)) {
err := r.Update(ctx, keystoneAPI)

if err != nil {
return ctrl.Result{}, err
}
}

controllerutil.RemoveFinalizer(instance, helper.GetFinalizer())
l.Info("Reconciled Service delete successfully")

return ctrl.Result{}, nil
}

func (r *KeystoneServiceReconciler) reconcileNormal(
ctx context.Context,
instance *keystonev1.KeystoneService,
Expand Down

0 comments on commit e40975f

Please sign in to comment.