diff --git a/pkg/operator/ceph/cluster/mon/mon.go b/pkg/operator/ceph/cluster/mon/mon.go index 17258a532..8375163e8 100644 --- a/pkg/operator/ceph/cluster/mon/mon.go +++ b/pkg/operator/ceph/cluster/mon/mon.go @@ -1068,7 +1068,16 @@ func (c *Cluster) startDeployments(mons []*monConfig, requireAllInQuorum bool) e } func (c *Cluster) checkForExtraMonResources(mons []*monConfig, deployments []apps.Deployment) string { + // If there are fewer mon deployments than the desired count, no need to remove an extra. if len(deployments) <= c.spec.Mon.Count || len(deployments) <= len(mons) { + logger.Debug("no extra mon deployments to remove") + return "" + } + // If there are fewer mons in the list than expected, either new mons are being created for + // a new cluster, or a mon failover is in progress and the list of mons only + // includes the single mon that was just started + if len(mons) < c.spec.Mon.Count { + logger.Debug("new cluster or mon failover in progress, not checking for extra mon deployments") return "" } diff --git a/pkg/operator/ceph/cluster/mon/mon_test.go b/pkg/operator/ceph/cluster/mon/mon_test.go index e5918745a..b4c5e0f5b 100644 --- a/pkg/operator/ceph/cluster/mon/mon_test.go +++ b/pkg/operator/ceph/cluster/mon/mon_test.go @@ -718,6 +718,24 @@ func TestRemoveExtraMonDeployments(t *testing.T) { c.spec.Mon.Count = 3 removed = c.checkForExtraMonResources(mons, deployments) assert.Equal(t, "", removed) + + // Do not remove a mon when it was during failover and only a single mon is in the list, even if extra deployments exist + mons = []*monConfig{ + {ResourceName: "rook-ceph-mon-d", DaemonName: "d"}, + } + deployments = append(deployments, apps.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "rook-ceph-mon-c", + Labels: map[string]string{"ceph_daemon_id": "c"}, + }}) + deployments = append(deployments, apps.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "rook-ceph-mon-d", + Labels: map[string]string{"ceph_daemon_id": "d"}, + }}) + c.spec.Mon.Count = 3 + removed = c.checkForExtraMonResources(mons, deployments) + assert.Equal(t, "", removed) } func TestStretchMonVolumeClaimTemplate(t *testing.T) {