diff --git a/pkg/daemon/ceph/osd/remove.go b/pkg/daemon/ceph/osd/remove.go index bae12a8d5..a733d4dce 100644 --- a/pkg/daemon/ceph/osd/remove.go +++ b/pkg/daemon/ceph/osd/remove.go @@ -62,46 +62,13 @@ func RemoveOSDs(context *clusterd.Context, clusterInfo *client.ClusterInfo, osds logger.Infof("osd.%d is marked 'DOWN'", osdID) } - // Check we can remove the OSD - // Loop forever until the osd is safe-to-destroy - for { - isSafeToDestroy, err := client.OsdSafeToDestroy(context, clusterInfo, osdID) - if err != nil { - // If we want to force remove the OSD and there was an error let's break outside of - // the loop and proceed with the OSD removal - if forceOSDRemoval { - logger.Errorf("failed to check if osd %d is safe to destroy, but force removal is enabled so proceeding with removal. %v", osdID, err) - break - } else { - logger.Errorf("failed to check if osd %d is safe to destroy, retrying in 1m. %v", osdID, err) - time.Sleep(1 * time.Minute) - continue - } - } - - // If no error and the OSD is safe to destroy, we can proceed with the OSD removal - if isSafeToDestroy { - logger.Infof("osd.%d is safe to destroy, proceeding", osdID) - break - } else { - // If we arrive here and forceOSDRemoval is true, we should proceed with the OSD removal - if forceOSDRemoval { - logger.Infof("osd.%d is NOT be ok to destroy but force removal is enabled so proceeding with removal", osdID) - break - } - // Else we wait until the OSD can be removed - logger.Warningf("osd.%d is NOT be ok to destroy, retrying in 1m until success", osdID) - time.Sleep(1 * time.Minute) - } - } - - removeOSD(context, clusterInfo, osdID, preservePVC) + removeOSD(context, clusterInfo, osdID, preservePVC, forceOSDRemoval) } return nil } -func removeOSD(clusterdContext *clusterd.Context, clusterInfo *client.ClusterInfo, osdID int, preservePVC bool) { +func removeOSD(clusterdContext *clusterd.Context, clusterInfo *client.ClusterInfo, osdID int, preservePVC, forceOSDRemoval bool) { // Get the host where the OSD is found hostName, err := client.GetCrushHostName(clusterdContext, clusterInfo, osdID) if err != nil { @@ -116,6 +83,39 @@ func removeOSD(clusterdContext *clusterd.Context, clusterInfo *client.ClusterInf logger.Errorf("failed to exclude osd.%d out of the crush map. %v", osdID, err) } + // Check we can remove the OSD + // Loop forever until the osd is safe-to-destroy + for { + isSafeToDestroy, err := client.OsdSafeToDestroy(clusterdContext, clusterInfo, osdID) + if err != nil { + // If we want to force remove the OSD and there was an error let's break outside of + // the loop and proceed with the OSD removal + if forceOSDRemoval { + logger.Errorf("failed to check if osd %d is safe to destroy, but force removal is enabled so proceeding with removal. %v", osdID, err) + break + } else { + logger.Errorf("failed to check if osd %d is safe to destroy, retrying in 1m. %v", osdID, err) + time.Sleep(1 * time.Minute) + continue + } + } + + // If no error and the OSD is safe to destroy, we can proceed with the OSD removal + if isSafeToDestroy { + logger.Infof("osd.%d is safe to destroy, proceeding", osdID) + break + } else { + // If we arrive here and forceOSDRemoval is true, we should proceed with the OSD removal + if forceOSDRemoval { + logger.Infof("osd.%d is NOT be ok to destroy but force removal is enabled so proceeding with removal", osdID) + break + } + // Else we wait until the OSD can be removed + logger.Warningf("osd.%d is NOT be ok to destroy, retrying in 1m until success", osdID) + time.Sleep(1 * time.Minute) + } + } + // Remove the OSD deployment deploymentName := fmt.Sprintf("rook-ceph-osd-%d", osdID) deployment, err := clusterdContext.Clientset.AppsV1().Deployments(clusterInfo.Namespace).Get(clusterInfo.Context, deploymentName, metav1.GetOptions{})