From b0cb722638af8a0d2fa466bb082ccda5dcc620be Mon Sep 17 00:00:00 2001 From: sp98 Date: Tue, 20 Feb 2024 15:11:23 +0530 Subject: [PATCH] mon: set mon pdb max unavailable as 2 in case of 5 or more mons If the spec.mon.count is 5 or more, then create mon pdbs with maxUnavailable count as 2. We can afford to have more than 1 mons down while draining the nodes in this case. Signed-off-by: sp98 (cherry picked from commit a4866b4b066ec87c26cee0ba930338e8b5c467a4) --- pkg/operator/ceph/cluster/mon/drain.go | 14 +++++++++++--- pkg/operator/ceph/cluster/mon/drain_test.go | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/operator/ceph/cluster/mon/drain.go b/pkg/operator/ceph/cluster/mon/drain.go index d1b745fdf..08e8b511a 100644 --- a/pkg/operator/ceph/cluster/mon/drain.go +++ b/pkg/operator/ceph/cluster/mon/drain.go @@ -43,7 +43,7 @@ func (c *Cluster) reconcileMonPDB() error { return nil } - op, err := c.createOrUpdateMonPDB(1) + op, err := c.createOrUpdateMonPDB(c.getMaxUnavailableMonPodCount()) if err != nil { return errors.Wrapf(err, "failed to reconcile mon pdb on op %q", op) } @@ -108,10 +108,18 @@ func (c *Cluster) allowMonDrain(request types.NamespacedName) error { return nil } logger.Info("allow voluntary mon drain after failover") - // change MaxUnavailable mon PDB to 1 - _, err := c.createOrUpdateMonPDB(1) + _, err := c.createOrUpdateMonPDB(c.getMaxUnavailableMonPodCount()) if err != nil { return errors.Wrapf(err, "failed to update MaxUnavailable for mon PDB %q", request.Name) } return nil } + +func (c *Cluster) getMaxUnavailableMonPodCount() int32 { + if c.spec.Mon.Count >= 5 { + logger.Debug("setting the mon pdb max unavailable count to 2 in case there are 5 or more mons") + return 2 + } + + return 1 +} diff --git a/pkg/operator/ceph/cluster/mon/drain_test.go b/pkg/operator/ceph/cluster/mon/drain_test.go index 0bff39bec..c2024d965 100644 --- a/pkg/operator/ceph/cluster/mon/drain_test.go +++ b/pkg/operator/ceph/cluster/mon/drain_test.go @@ -102,7 +102,7 @@ func TestReconcileMonPDB(t *testing.T) { }, }, }, - expectedMaxUnAvailable: 1, + expectedMaxUnAvailable: 2, errorExpected: false, }, }