Merge pull request #1915 from laevilgenius/dashboard_url_prefix
Add urlPrefix setting for ceph dashboard
This commit is contained in:
9 files changed
+83
-5
No files matched your search
Regular → Executable
+1
@@ -52,6 +52,7 @@ Settings can be specified at the global level to apply to the cluster as a whole
|
||||
If this value is empty, each pod will get an ephemeral directory to store their config files that is tied to the lifetime of the pod running on that node. More details can be found in the Kubernetes [empty dir docs](https://kubernetes.io/docs/concepts/storage/volumes/#emptydir).
|
||||
- `dashboard`: Settings for the Ceph dashboard. To view the dashboard in your browser see the [dashboard guide](ceph-dashboard.md).
|
||||
- `enabled`: Whether to enable the dashboard to view cluster status
|
||||
- `urlPrefix`: Allows to serve the dashboard under a subpath (useful when you are accessing the dashboard via a reverse proxy)
|
||||
- `serviceAccount`: The service account under which the OSD pods will run that will give access to ConfigMaps in the cluster's namespace. If not set, the default of `rook-ceph-cluster` will be used.
|
||||
- `network`: The network settings for the cluster
|
||||
- `hostNetwork`: uses network of the hosts instead of using the SDN below the containers.
|
||||
|
||||
Regular → Executable
+10
@@ -49,6 +49,16 @@ To retrieve the generated password, you can run the following:
|
||||
kubectl -n rook-ceph get secret rook-ceph-dashboard-password -o yaml | grep "password:" | awk '{print $2}' | base64 --decode
|
||||
```
|
||||
|
||||
## Configure the Dashboard
|
||||
|
||||
If you are accessing the dashboard via a reverse proxy, you may wish to serve it under a URL prefix.
|
||||
To get the dashboard to use hyperlinks that include your prefix, you can set the `urlPrefix` setting:
|
||||
```yaml
|
||||
spec:
|
||||
dashboard:
|
||||
urlPrefix: /ceph-dashboard
|
||||
```
|
||||
|
||||
## Viewing the Dashboard External to the Cluster
|
||||
|
||||
Commonly you will want to view the dashboard from outside the cluster. For example, on a development machine with the
|
||||
|
||||
Regular → Executable
+2
@@ -78,6 +78,8 @@ spec:
|
||||
# enable the ceph dashboard for viewing cluster status
|
||||
dashboard:
|
||||
enabled: true
|
||||
# serve the dashboard under a subpath (useful when you are accessing the dashboard via a reverse proxy)
|
||||
# urlPrefix: /ceph-dashboard
|
||||
network:
|
||||
# toggle to use hostNetwork
|
||||
hostNetwork: false
|
||||
|
||||
Regular → Executable
+2
@@ -36,6 +36,8 @@ spec:
|
||||
properties:
|
||||
enabled:
|
||||
type: boolean
|
||||
urlPrefix:
|
||||
type: string
|
||||
dataDirHostPath:
|
||||
pattern: ^/(\S+)
|
||||
type: string
|
||||
|
||||
Regular → Executable
+2
@@ -92,6 +92,8 @@ type CephVersionSpec struct {
|
||||
type DashboardSpec struct {
|
||||
// Whether to enable the dashboard
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
// A prefix for all URLs to use the dashboard with a reverse proxy
|
||||
UrlPrefix string `json:"urlPrefix,omitempty"`
|
||||
}
|
||||
|
||||
type ClusterStatus struct {
|
||||
|
||||
Regular → Executable
+36
@@ -2,7 +2,9 @@ package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
cephv1beta1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1beta1"
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
)
|
||||
|
||||
@@ -16,6 +18,40 @@ func MgrDisableModule(context *clusterd.Context, clusterName, name string) error
|
||||
return enableModule(context, clusterName, name, false, "disable")
|
||||
}
|
||||
|
||||
func MgrSetConfig(context *clusterd.Context, clusterName, cephVersionName, key, val string) (bool, error) {
|
||||
var getArgs, setArgs []string
|
||||
|
||||
if cephVersionName == cephv1beta1.Luminous || cephVersionName == "" {
|
||||
getArgs = append(getArgs, "config-key", "get", key)
|
||||
if val == "" {
|
||||
setArgs = append(setArgs, "config-key", "del", key)
|
||||
} else {
|
||||
setArgs = append(setArgs, "config-key", "set", key, val)
|
||||
}
|
||||
} else {
|
||||
getArgs = append(getArgs, "config", "get", "mgr.", key)
|
||||
if val == "" {
|
||||
setArgs = append(setArgs, "config", "rm", "mgr", key)
|
||||
} else {
|
||||
setArgs = append(setArgs, "config", "set", "mgr", key, val)
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve previous value to monitor changes
|
||||
var prevVal string
|
||||
buf, err := ExecuteCephCommand(context, clusterName, getArgs)
|
||||
if err == nil {
|
||||
prevVal = strings.TrimSpace(string(buf))
|
||||
}
|
||||
|
||||
if _, err := ExecuteCephCommand(context, clusterName, setArgs); err != nil {
|
||||
return false, fmt.Errorf("failed to set mgr config key %s to \"%s\": %+v", key, val, err)
|
||||
}
|
||||
|
||||
hasChanged := prevVal != val
|
||||
return hasChanged, nil
|
||||
}
|
||||
|
||||
func enableModule(context *clusterd.Context, clusterName, name string, force bool, action string) error {
|
||||
args := []string{"mgr", "module", action, name}
|
||||
if force {
|
||||
|
||||
Regular → Executable
+4
@@ -267,6 +267,10 @@ func clusterChanged(oldCluster, newCluster cephv1beta1.ClusterSpec, clusterRef *
|
||||
logger.Infof("dashboard enabled has changed from %t to %t", oldCluster.Dashboard.Enabled, newCluster.Dashboard.Enabled)
|
||||
changeFound = true
|
||||
}
|
||||
if oldCluster.Dashboard.UrlPrefix != newCluster.Dashboard.UrlPrefix {
|
||||
logger.Infof("dashboard url prefix has changed from \"%s\" to \"%s\"", oldCluster.Dashboard.UrlPrefix, newCluster.Dashboard.UrlPrefix)
|
||||
changeFound = true
|
||||
}
|
||||
|
||||
if oldCluster.Mon.Count != newCluster.Mon.Count {
|
||||
logger.Infof("number of mons have changed from %d to %d. The health check will update the mons...", oldCluster.Mon.Count, newCluster.Mon.Count)
|
||||
|
||||
Regular → Executable
+21
-5
@@ -53,8 +53,8 @@ func init() {
|
||||
|
||||
func (c *Cluster) configureDashboard(port int) error {
|
||||
// enable or disable the dashboard module
|
||||
if err := c.configureDashboardModule(); err != nil {
|
||||
return fmt.Errorf("failed to enable mgr dashboard module. %+v", err)
|
||||
if err := c.toggleDashboardModule(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dashboardService := c.makeDashboardService(appName, port)
|
||||
@@ -80,15 +80,19 @@ func (c *Cluster) configureDashboard(port int) error {
|
||||
}
|
||||
|
||||
// Ceph docs about the dashboard module: http://docs.ceph.com/docs/luminous/mgr/dashboard/
|
||||
func (c *Cluster) configureDashboardModule() error {
|
||||
func (c *Cluster) toggleDashboardModule() error {
|
||||
if c.dashboard.Enabled {
|
||||
if err := client.MgrEnableModule(c.context, c.Namespace, dashboardModuleName, true); err != nil {
|
||||
return fmt.Errorf("failed to enable mgr dashboard module. %+v", err)
|
||||
}
|
||||
|
||||
if err := c.initializeDashboard(); err != nil {
|
||||
if err := c.initializeSecureDashboard(); err != nil {
|
||||
return fmt.Errorf("failed to initialize dashboard. %+v", err)
|
||||
}
|
||||
|
||||
if err := c.configureDashboardModule(); err != nil {
|
||||
return fmt.Errorf("failed to configure mgr dashboard module. %+v", err)
|
||||
}
|
||||
} else {
|
||||
if err := client.MgrDisableModule(c.context, c.Namespace, dashboardModuleName); err != nil {
|
||||
logger.Errorf("failed to disable mgr dashboard module. %+v", err)
|
||||
@@ -97,7 +101,19 @@ func (c *Cluster) configureDashboardModule() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cluster) initializeDashboard() error {
|
||||
func (c *Cluster) configureDashboardModule() error {
|
||||
hasChanged, err := client.MgrSetConfig(c.context, c.Namespace, c.cephVersion.Name, "mgr/dashboard/url_prefix", c.dashboard.UrlPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if hasChanged {
|
||||
logger.Infof("dashboard config has changed")
|
||||
return c.restartDashboard()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cluster) initializeSecureDashboard() error {
|
||||
if c.cephVersion.Name == cephv1beta1.Luminous || c.cephVersion.Name == "" {
|
||||
logger.Infof("skipping cert and user configuration on luminous")
|
||||
return nil
|
||||
|
||||
Regular → Executable
+5
@@ -53,6 +53,11 @@ func TestStartMGR(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
validateStart(t, c)
|
||||
|
||||
c.dashboard.UrlPrefix = "/test"
|
||||
err = c.Start()
|
||||
assert.Nil(t, err)
|
||||
validateStart(t, c)
|
||||
|
||||
// starting again with more replicas
|
||||
c.Replicas = 3
|
||||
c.dashboard.Enabled = false
|
||||
|
||||
Reference in new issue
Block a user