From d73e4f90e8197b7e8bcd5793d4c93442d1addd10 Mon Sep 17 00:00:00 2001 From: Travis Nielsen Date: Wed, 26 Oct 2022 14:17:03 -0600 Subject: [PATCH] core: remove finalizer from cluster cr last Removing the finalizers from cluster resources can intermittently fail in the CI if other updates are made at similar times. The controller runtime will retry after the failure, but if something external removes the finalizer on the cephcluster CR, the deletion will not continue with the removal of finalizers from the other configmap and secret critical resources. Signed-off-by: Travis Nielsen (cherry picked from commit 0ede2946a8cd093f2e8a5866c6f8c9694730a318) --- pkg/operator/ceph/cluster/controller.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pkg/operator/ceph/cluster/controller.go b/pkg/operator/ceph/cluster/controller.go index 3e66fde2f..cdfd141f2 100644 --- a/pkg/operator/ceph/cluster/controller.go +++ b/pkg/operator/ceph/cluster/controller.go @@ -478,26 +478,28 @@ func (c *ClusterController) checkPVPresentInCluster(drivers []string, clusterID return false, nil } -func (r *ReconcileCephCluster) removeFinalizers(client client.Client, name types.NamespacedName) error { - // Remove cephcluster finalizer - err := r.removeFinalizer(client, name, &cephv1.CephCluster{}, "") - if err != nil { - return errors.Wrap(err, "failed to remove cephcluster finalizer") - } +func (r *ReconcileCephCluster) removeFinalizers(client client.Client, clusterName types.NamespacedName) error { // Remove finalizer for rook-ceph-mon secret - name = types.NamespacedName{Name: mon.AppName, Namespace: name.Namespace} - err = r.removeFinalizer(client, name, &corev1.Secret{}, mon.DisasterProtectionFinalizerName) + name := types.NamespacedName{Name: mon.AppName, Namespace: clusterName.Namespace} + err := r.removeFinalizer(client, name, &corev1.Secret{}, mon.DisasterProtectionFinalizerName) if err != nil { return errors.Wrapf(err, "failed to remove finalizer for the secret %q", name.Name) } // Remove finalizer for rook-ceph-mon-endpoints configmap - name = types.NamespacedName{Name: mon.EndpointConfigMapName, Namespace: name.Namespace} + name = types.NamespacedName{Name: mon.EndpointConfigMapName, Namespace: clusterName.Namespace} err = r.removeFinalizer(client, name, &corev1.ConfigMap{}, mon.DisasterProtectionFinalizerName) if err != nil { return errors.Wrapf(err, "failed to remove finalizer for the configmap %q", name.Name) } + + // Remove cephcluster finalizer + err = r.removeFinalizer(client, clusterName, &cephv1.CephCluster{}, "") + if err != nil { + return errors.Wrap(err, "failed to remove cephcluster finalizer") + } + return nil }