From 56abc00b78176abf2d47c7a48df88d48609a51c4 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Wed, 27 Feb 2019 10:43:30 -0500 Subject: [PATCH 1/2] ceph: fix invalidArgErrorCode definition We should probably not hardcode this value here, and instead use whatever the syscall module thinks this is. Signed-off-by: Jeff Layton --- pkg/operator/ceph/cluster/mgr/dashboard.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/operator/ceph/cluster/mgr/dashboard.go b/pkg/operator/ceph/cluster/mgr/dashboard.go index 69a1da5ec..29d3592c4 100755 --- a/pkg/operator/ceph/cluster/mgr/dashboard.go +++ b/pkg/operator/ceph/cluster/mgr/dashboard.go @@ -42,7 +42,7 @@ const ( passwordLength = 10 passwordKeyName = "password" certAlreadyConfiguredErrorCode = 5 - invalidArgErrorCode = 22 + invalidArgErrorCode = int(syscall.EINVAL) ) var ( From c0910dab2cb5a15c0a070d7c9729e216aafa6f66 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Wed, 27 Feb 2019 10:12:42 -0500 Subject: [PATCH 2/2] ceph: retry "ceph orchestrator set backend rook" if command returns EINVAL Use similar method as that used by the dashboard initialization code. Fixes: https://github.com/rook/rook/issues/2617 Signed-off-by: Jeff Layton --- pkg/operator/ceph/cluster/mgr/orchestrator.go | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/operator/ceph/cluster/mgr/orchestrator.go b/pkg/operator/ceph/cluster/mgr/orchestrator.go index 0319ab9e0..a1d1e0471 100644 --- a/pkg/operator/ceph/cluster/mgr/orchestrator.go +++ b/pkg/operator/ceph/cluster/mgr/orchestrator.go @@ -19,6 +19,7 @@ package mgr import ( "fmt" + "time" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "github.com/rook/rook/pkg/daemon/ceph/client" @@ -29,6 +30,10 @@ const ( rookModuleName = "rook" ) +var ( + orchestratorInitWaitTime = 5 * time.Second +) + // Ceph docs about the orchestrator modules: http://docs.ceph.com/docs/master/mgr/orchestrator_cli/ func (c *Cluster) configureOrchestratorModules() error { if !cephv1.VersionAtLeast(c.cephVersion.Name, cephv1.Nautilus) { @@ -42,8 +47,21 @@ func (c *Cluster) configureOrchestratorModules() error { if err := client.MgrEnableModule(c.context, c.Namespace, rookModuleName, true); err != nil { return fmt.Errorf("failed to enable mgr rook module. %+v", err) } - if _, err := client.ExecuteCephCommand(c.context, c.Namespace, []string{"orchestrator", "set", "backend", "rook"}); err != nil { - return fmt.Errorf("failed to set rook as the orchestrator backend. %+v", err) + // retry a few times in the case that the mgr module is not ready to accept commands + for i := 0; i < 5; i++ { + _, err := client.ExecuteCephCommand(c.context, c.Namespace, []string{"orchestrator", "set", "backend", "rook"}) + if err != nil { + exitCode, parsed := c.exitCode(err) + if parsed { + if exitCode == invalidArgErrorCode { + logger.Infof("orchestrator module is not ready yet. trying again...") + time.Sleep(orchestratorInitWaitTime) + continue + } + } + return fmt.Errorf("failed to set rook as the orchestrator backend. %+v", err) + } + break } return nil