From 1c58c90177d0fc033f4404df8d225f7e7bddd7c0 Mon Sep 17 00:00:00 2001 From: zc Date: Thu, 6 Apr 2023 14:35:39 +0800 Subject: [PATCH] mgr: failed to update the port of mgr's dashboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit if port was used by other daemon,the dashboard will start failed and the status of the ceph will be err,then we update the port to a unused port,the operator can not deal with it Signed-off-by: zc (cherry picked from commit caf7b8c7536436f985799f44669e8f56ae90e9a3) --- pkg/operator/ceph/cluster/mgr/dashboard.go | 18 +++++++++++------- .../ceph/cluster/mgr/dashboard_test.go | 8 ++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/pkg/operator/ceph/cluster/mgr/dashboard.go b/pkg/operator/ceph/cluster/mgr/dashboard.go index 4d8441c43..7f0d68977 100644 --- a/pkg/operator/ceph/cluster/mgr/dashboard.go +++ b/pkg/operator/ceph/cluster/mgr/dashboard.go @@ -88,11 +88,12 @@ func (c *Cluster) configureDashboardModules() error { return nil } - hasChanged, err := c.initializeSecureDashboard() + err := c.initializeSecureDashboard() if err != nil { return errors.Wrap(err, "failed to initialize dashboard") } + var hasChanged bool for _, daemonID := range c.getDaemonIDs() { changed, err := c.configureDashboardModuleSettings(daemonID) if err != nil { @@ -148,30 +149,33 @@ func (c *Cluster) configureDashboardModuleSettings(daemonID string) (bool, error return hasChanged, nil } -func (c *Cluster) initializeSecureDashboard() (bool, error) { +func (c *Cluster) initializeSecureDashboard() error { // we need to wait a short period after enabling the module before we can call the `ceph dashboard` commands. time.Sleep(dashboardInitWaitTime) password, err := c.getOrGenerateDashboardPassword() if err != nil { - return false, errors.Wrap(err, "failed to generate a password for the ceph dashboard") + return errors.Wrap(err, "failed to generate a password for the ceph dashboard") } if c.spec.Dashboard.SSL { alreadyCreated, err := c.createSelfSignedCert() if err != nil { - return false, errors.Wrap(err, "failed to create a self signed cert for the ceph dashboard") + return errors.Wrap(err, "failed to create a self signed cert for the ceph dashboard") } if alreadyCreated { - return false, nil + return nil + } + if err := c.restartMgrModule(dashboardModuleName); err != nil { + logger.Warningf("failed to restart dashboard after generating ssl cert. %v", err) } } if err := c.setLoginCredentials(password); err != nil { - return false, errors.Wrap(err, "failed to set login credentials for the ceph dashboard") + return errors.Wrap(err, "failed to set login credentials for the ceph dashboard") } - return false, nil + return nil } func (c *Cluster) createSelfSignedCert() (bool, error) { diff --git a/pkg/operator/ceph/cluster/mgr/dashboard_test.go b/pkg/operator/ceph/cluster/mgr/dashboard_test.go index 965be9a6e..6c86fa602 100644 --- a/pkg/operator/ceph/cluster/mgr/dashboard_test.go +++ b/pkg/operator/ceph/cluster/mgr/dashboard_test.go @@ -136,8 +136,8 @@ func TestStartSecureDashboard(t *testing.T) { err = c.configureDashboardModules() assert.NoError(t, err) // the dashboard is enabled once with the new dashboard and modules - assert.Equal(t, 2, enables) - assert.Equal(t, 1, disables) + assert.Equal(t, 3, enables) + assert.Equal(t, 2, disables) assert.Equal(t, 2, moduleRetries) svc, err := c.context.Clientset.CoreV1().Services(clusterInfo.Namespace).Get(ctx, "rook-ceph-mgr-dashboard", metav1.GetOptions{}) @@ -152,8 +152,8 @@ func TestStartSecureDashboard(t *testing.T) { assert.Nil(t, err) err = c.configureDashboardModules() assert.NoError(t, err) - assert.Equal(t, 2, enables) - assert.Equal(t, 2, disables) + assert.Equal(t, 3, enables) + assert.Equal(t, 3, disables) svc, err = c.context.Clientset.CoreV1().Services(clusterInfo.Namespace).Get(ctx, "rook-ceph-mgr-dashboard", metav1.GetOptions{}) assert.NotNil(t, err)