From 7bd05d0d7ca26caf3fcfefd4b4a514664559db33 Mon Sep 17 00:00:00 2001 From: Santosh Pillai Date: Tue, 16 Mar 2021 11:31:31 +0530 Subject: [PATCH] ceph: skip cleanup if cluster is not configured correctly deletion of cluster is stuck when cluster is not configured. The PR skips the cleanup and removes the finalizers if the cluster was not configured, that is, if clusterInfo could not be loaded. Signed-off-by: Santosh Pillai --- pkg/operator/ceph/cluster/controller.go | 31 +++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/operator/ceph/cluster/controller.go b/pkg/operator/ceph/cluster/controller.go index 00a2e1492..641b739bc 100644 --- a/pkg/operator/ceph/cluster/controller.go +++ b/pkg/operator/ceph/cluster/controller.go @@ -255,6 +255,7 @@ func (r *ReconcileCephCluster) reconcile(request reconcile.Request) (reconcile.R // DELETE: the CR was deleted if !cephCluster.GetDeletionTimestamp().IsZero() { + doCleanup := true logger.Infof("deleting ceph cluster %q", cephCluster.Name) // Start cluster clean up only if cleanupPolicy is applied to the ceph cluster @@ -265,22 +266,28 @@ func (r *ReconcileCephCluster) reconcile(request reconcile.Request) (reconcile.R monSecret, clusterFSID, err := r.clusterController.getCleanUpDetails(cephCluster.Namespace) if err != nil { - return reconcile.Result{}, errors.Wrap(err, "failed to get mon secret, no cleanup") + logger.Warningf("failed to get mon secret. Skip cluster cleanup and remove finalizer. %v", err) + doCleanup = false } - cephHosts, err := r.clusterController.getCephHosts(cephCluster.Namespace) - if err != nil { - return reconcile.Result{}, errors.Wrapf(err, "failed to find valid ceph hosts in the cluster %q", cephCluster.Namespace) + + if doCleanup { + cephHosts, err := r.clusterController.getCephHosts(cephCluster.Namespace) + if err != nil { + return reconcile.Result{}, errors.Wrapf(err, "failed to find valid ceph hosts in the cluster %q", cephCluster.Namespace) + } + go r.clusterController.startClusterCleanUp(stopCleanupCh, cephCluster, cephHosts, monSecret, clusterFSID) } - go r.clusterController.startClusterCleanUp(stopCleanupCh, cephCluster, cephHosts, monSecret, clusterFSID) } - // Run delete sequence - response, ok := r.clusterController.requestClusterDelete(cephCluster) - if !ok { - // If the cluster cannot be deleted, requeue the request for deletion to see if the conditions - // will eventually be satisfied such as the volumes being removed - close(stopCleanupCh) - return response, nil + if doCleanup { + // Run delete sequence + response, ok := r.clusterController.requestClusterDelete(cephCluster) + if !ok { + // If the cluster cannot be deleted, requeue the request for deletion to see if the conditions + // will eventually be satisfied such as the volumes being removed + close(stopCleanupCh) + return response, nil + } } // Remove finalizer