Unverified Commit 4700193b authored by Juan Miguel Olmo Martínez's avatar Juan Miguel Olmo Martínez
Browse files

ceph: dashboard - get right ssl port from ceph settings


Starting with Nautilus 14.2.1 the dashboard SSL port is readed from <<mgr/dashboard/ssl_server_port>> ceph setting.
Previous versions use the port specified in <<mgr/dashboard/server_port>>

Addressed @travisn suggestion about use of <ssl> attribute in conditional.
This suggestion drove me to change the type of the SSl attribute (from *bool to bool) in the DashboardSpec Struct.
This makes code more clean/safe and make sure that the SSL atribute has always a meaningful value.

Now if you want to run the <secure dashboard> you need to set explicitly SSL to true, as is demonstrated in unit tests.

[x] Code generation (make codegen) has been run to update object specifications
Signed-off-by: default avatarJuan Miguel Olmo Martínez <jolmomar@redhat.com>
parent 9bdc301f
Showing with 23 additions and 21 deletions
+23 -21
......@@ -112,7 +112,7 @@ type DashboardSpec struct {
// The dashboard webserver port
Port int `json:"port,omitempty"`
// Whether SSL should be used
SSL *bool `json:"ssl,omitempty"`
SSL bool `json:"ssl,omitempty"`
}
// MonitoringSpec represents the settings for Prometheus based Ceph monitoring
......
......@@ -482,7 +482,7 @@ func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) {
out.DisruptionManagement = in.DisruptionManagement
in.Mon.DeepCopyInto(&out.Mon)
out.RBDMirroring = in.RBDMirroring
in.Dashboard.DeepCopyInto(&out.Dashboard)
out.Dashboard = in.Dashboard
out.Monitoring = in.Monitoring
out.External = in.External
in.Mgr.DeepCopyInto(&out.Mgr)
......@@ -523,11 +523,6 @@ func (in *ClusterStatus) DeepCopy() *ClusterStatus {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardSpec) DeepCopyInto(out *DashboardSpec) {
*out = *in
if in.SSL != nil {
in, out := &in.SSL, &out.SSL
*out = new(bool)
**out = **in
}
return
}
......
......@@ -27,8 +27,9 @@ import (
"time"
"github.com/rook/rook/pkg/daemon/ceph/client"
cephver "github.com/rook/rook/pkg/operator/ceph/version"
"github.com/rook/rook/pkg/operator/k8sutil"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
......@@ -121,27 +122,33 @@ func (c *Cluster) configureDashboardModule(m *mgrConfig) error {
return err
}
// server port
port := strconv.Itoa(m.DashboardPort)
changed, err := client.MgrSetConfig(c.context, c.Namespace, m.DaemonID, c.clusterInfo.CephVersion, "mgr/dashboard/server_port", port, false)
// ssl support
ssl := strconv.FormatBool(c.dashboard.SSL)
changed, err := client.MgrSetConfig(c.context, c.Namespace, m.DaemonID, c.clusterInfo.CephVersion, "mgr/dashboard/ssl", ssl, false)
if err != nil {
return err
}
hasChanged = hasChanged || changed
// ssl support
var ssl string
if c.dashboard.SSL == nil {
ssl = ""
} else {
ssl = strconv.FormatBool(*c.dashboard.SSL)
}
changed, err = client.MgrSetConfig(c.context, c.Namespace, m.DaemonID, c.clusterInfo.CephVersion, "mgr/dashboard/ssl", ssl, false)
// server port
port := strconv.Itoa(m.DashboardPort)
changed, err = client.MgrSetConfig(c.context, c.Namespace, m.DaemonID, c.clusterInfo.CephVersion, "mgr/dashboard/server_port", port, false)
if err != nil {
return err
}
hasChanged = hasChanged || changed
// SSL enabled. Needed to set specifically the ssl port setting starting with Nautilus(14.2.1)
if c.dashboard.SSL {
if c.clusterInfo.CephVersion.IsAtLeast(cephver.CephVersion{Major: 14, Minor: 2, Extra: 1}) {
changed, err = client.MgrSetConfig(c.context, c.Namespace, m.DaemonID, c.clusterInfo.CephVersion, "mgr/dashboard/ssl_server_port", port, false)
if err != nil {
return err
}
hasChanged = hasChanged || changed
}
}
if hasChanged {
logger.Infof("dashboard config has changed")
return c.restartDashboard()
......@@ -158,7 +165,7 @@ func (c *Cluster) initializeSecureDashboard() error {
return fmt.Errorf("failed to generate a password. %+v", err)
}
if c.dashboard.SSL == nil || *c.dashboard.SSL {
if c.dashboard.SSL {
alreadyCreated, err := c.createSelfSignedCert()
if err != nil {
return fmt.Errorf("failed to create a self signed cert. %+v", err)
......
......@@ -102,7 +102,7 @@ func TestStartSecureDashboard(t *testing.T) {
CephVersion: cephver.Mimic,
}
c := &Cluster{clusterInfo: clusterInfo, context: &clusterd.Context{Clientset: test.New(3), Executor: executor}, Namespace: "myns",
dashboard: cephv1.DashboardSpec{Enabled: true}, cephVersion: cephv1.CephVersionSpec{Image: "ceph/ceph:v13.2.2"}}
dashboard: cephv1.DashboardSpec{Enabled: true, SSL: true}, cephVersion: cephv1.CephVersionSpec{Image: "ceph/ceph:v13.2.2"}}
c.exitCode = func(err error) (int, bool) {
if exitCodeResponse != 0 {
return exitCodeResponse, true
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment