From d076f343d5d65e035daae00d1e667b46d550a6a0 Mon Sep 17 00:00:00 2001 From: subhamkrai Date: Tue, 11 Oct 2022 16:22:21 +0530 Subject: [PATCH] osd: osdSafeToDestroy check should be after osd out currently, osdSafeToDestroy check is done before marking osd out which prevents ceph from rebalancing. With this changes, we are moving check for osdSafeToDestroy after osd is marked out. Signed-off-by: subhamkrai (cherry picked from commit 77f9e0d5b69c4a3880f82c905d8377e49e918f05) --- pkg/daemon/ceph/osd/remove.go | 70 +++++++++++++++++------------------ 1 file changed, 35 insertions(+), 35 deletions(-) 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{})