From cfa0f43f612fa2e6354d4469a38017905abfe0a1 Mon Sep 17 00:00:00 2001 From: travisn Date: Mon, 8 Oct 2018 21:31:50 -0400 Subject: [PATCH] check available nodes for mons only when necessary Signed-off-by: travisn --- pkg/operator/ceph/cluster/mon/mon.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/operator/ceph/cluster/mon/mon.go b/pkg/operator/ceph/cluster/mon/mon.go index 2e556063c..7701b4478 100644 --- a/pkg/operator/ceph/cluster/mon/mon.go +++ b/pkg/operator/ceph/cluster/mon/mon.go @@ -171,6 +171,7 @@ func (c *Cluster) startMons() error { if endIndex < c.Size { endIndex++ } + logger.Infof("looping to start mons. i=%d, endIndex=%d, c.Size=%d", i, endIndex, c.Size) // Init the mon IPs if err := c.initMonIPs(mons[0:endIndex]); err != nil { @@ -319,11 +320,6 @@ func (c *Cluster) assignMons(mons []*monConfig) error { return fmt.Errorf("failed to get available nodes for mons. %+v", err) } - // if all nodes already have mons return error as we don't place two mons on one node - if len(availableNodes) == 0 { - return fmt.Errorf("no nodes available for mon placement") - } - nodeIndex := 0 for _, m := range mons { if _, ok := c.mapping.Node[m.DaemonName]; ok { @@ -331,6 +327,11 @@ func (c *Cluster) assignMons(mons []*monConfig) error { continue } + // if we need to place a new mon and don't have any more nodes available, we fail to add the mon + if len(availableNodes) == 0 { + return fmt.Errorf("no nodes available for mon placement") + } + // pick one of the available nodes where the mon will be assigned node := availableNodes[nodeIndex%len(availableNodes)] logger.Debugf("mon %s assigned to node %s", m.DaemonName, node.Name)