From 926c1dfa17a730ab72e7f3f2c8249f02993cce83 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Fri, 24 Sep 2021 09:29:09 +0200 Subject: [PATCH] Remove finalizer from deletion flow to fix Gardener shoot deletion. (#27) --- controllers/duros_controller.go | 37 ------------------- controllers/resources.go | 63 --------------------------------- 2 files changed, 100 deletions(-) diff --git a/controllers/duros_controller.go b/controllers/duros_controller.go index 936f3fc..b785dd8 100644 --- a/controllers/duros_controller.go +++ b/controllers/duros_controller.go @@ -26,7 +26,6 @@ import ( "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/predicate" "github.com/metal-stack/duros-go" @@ -89,33 +88,6 @@ func (r *DurosReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl projectID := duros.Spec.MetalProjectID storageClasses := duros.Spec.StorageClasses - if duros.ObjectMeta.DeletionTimestamp.IsZero() { - if !containsString(duros.GetFinalizers(), DurosFinalizerName) { - controllerutil.AddFinalizer(duros, DurosFinalizerName) - if err := r.Update(ctx, duros); err != nil { - return requeue, err - } - } - } else { - // object is being deleted - // we don't pass the cancelled context here because then our deletion - // procedure will stop prematurely - deletionCtx := context.Background() - - if containsString(duros.GetFinalizers(), DurosFinalizerName) { - if err := r.cleanupResources(deletionCtx); err != nil { - return requeue, err - } - - controllerutil.RemoveFinalizer(duros, DurosFinalizerName) - if err := r.Update(deletionCtx, duros); err != nil { - return requeue, err - } - } - - return ctrl.Result{}, nil - } - p, err := r.createProjectIfNotExist(ctx, projectID) if err != nil { return requeue, err @@ -235,12 +207,3 @@ func validateDuros(duros *v1.Duros) error { } return nil } - -func containsString(slice []string, s string) bool { - for _, item := range slice { - if item == s { - return true - } - } - return false -} diff --git a/controllers/resources.go b/controllers/resources.go index 2b92317..9195624 100644 --- a/controllers/resources.go +++ b/controllers/resources.go @@ -13,7 +13,6 @@ import ( storagev1 "github.com/metal-stack/duros-controller/api/v1" apps "k8s.io/api/apps/v1" - appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" policy "k8s.io/api/policy/v1beta1" rbac "k8s.io/api/rbac/v1" @@ -1018,68 +1017,6 @@ type deletionResource struct { Object client.Object } -func (r *DurosReconciler) cleanupResources(ctx context.Context) error { - log := r.Log.WithName("storage-csi") - log.Info("cleanup csi") - - resources := []deletionResource{ - { - Key: types.NamespacedName{Name: lbCSINodeName, Namespace: namespace}, - Object: &appsv1.DaemonSet{}, - }, - { - Key: types.NamespacedName{Name: lbCSIControllerName, Namespace: namespace}, - Object: &appsv1.StatefulSet{}, - }, - { - Key: types.NamespacedName{Name: storageClassCredentialsRef, Namespace: namespace}, - Object: &corev1.Secret{}, - }, - } - - for i := range clusterRoleBindings { - crb := clusterRoleBindings[i] - resources = append(resources, deletionResource{ - Key: types.NamespacedName{Name: crb.Name, Namespace: crb.Namespace}, - Object: &rbac.ClusterRoleBinding{}, - }) - } - - for i := range clusterRoles { - cr := clusterRoles[i] - resources = append(resources, deletionResource{ - Key: types.NamespacedName{Name: cr.Name, Namespace: cr.Namespace}, - Object: &rbac.ClusterRole{}, - }) - } - - for i := range serviceAccounts { - sa := serviceAccounts[i] - resources = append(resources, deletionResource{ - Key: types.NamespacedName{Name: sa.Name, Namespace: sa.Namespace}, - Object: &corev1.ServiceAccount{}, - }) - } - - for i := range psps { - psp := psps[i] - resources = append(resources, deletionResource{ - Key: types.NamespacedName{Name: psp.Name}, - Object: &policy.PodSecurityPolicy{}, - }) - } - - // we don't clean up the storage classes and CSI driver because there can be volumes that still reference it - - for _, resource := range resources { - if err := r.deleteResourceWithWait(ctx, log, resource); err != nil { - return err - } - } - - return nil -} - func (r *DurosReconciler) deleteResourceWithWait(ctx context.Context, log logr.Logger, resource deletionResource) error { err := r.Shoot.Get(ctx, resource.Key, resource.Object) if err != nil && apierrors.IsNotFound(err) {