Merge pull request #8590 from travisn/mon-store-config
ceph: Consolidate the calls to set mon config
This commit is contained in:
7 files changed
+49
-55
No files matched your search
@@ -300,31 +300,3 @@ func WriteCephConfig(context *clusterd.Context, clusterInfo *ClusterInfo) error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetConfig applies a setting for a single mgr daemon
|
||||
func SetConfig(context *clusterd.Context, clusterInfo *ClusterInfo, daemonID string, key, val string, force bool) (bool, error) {
|
||||
var getArgs, setArgs []string
|
||||
getArgs = append(getArgs, "config", "get", daemonID, key)
|
||||
if val == "" {
|
||||
setArgs = append(setArgs, "config", "rm", daemonID, key)
|
||||
} else {
|
||||
setArgs = append(setArgs, "config", "set", daemonID, key, val)
|
||||
}
|
||||
if force {
|
||||
setArgs = append(setArgs, "--force")
|
||||
}
|
||||
|
||||
// Retrieve previous value to monitor changes
|
||||
var prevVal string
|
||||
buf, err := NewCephCommand(context, clusterInfo, getArgs).Run()
|
||||
if err == nil {
|
||||
prevVal = strings.TrimSpace(string(buf))
|
||||
}
|
||||
|
||||
if _, err := NewCephCommand(context, clusterInfo, setArgs).Run(); err != nil {
|
||||
return false, errors.Wrapf(err, "failed to set config key %s to %q", key, val)
|
||||
}
|
||||
|
||||
hasChanged := prevVal != val
|
||||
return hasChanged, nil
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
cephclient "github.com/rook/rook/pkg/daemon/ceph/client"
|
||||
"github.com/rook/rook/pkg/operator/ceph/config"
|
||||
opcontroller "github.com/rook/rook/pkg/operator/ceph/controller"
|
||||
"github.com/rook/rook/pkg/operator/ceph/reporting"
|
||||
cephver "github.com/rook/rook/pkg/operator/ceph/version"
|
||||
@@ -158,7 +159,8 @@ func (c *cephStatusChecker) configureHealthSettings(status cephclient.CephStatus
|
||||
if _, ok := status.Health.Checks["AUTH_INSECURE_GLOBAL_ID_RECLAIM_ALLOWED"]; ok {
|
||||
if _, ok := status.Health.Checks["AUTH_INSECURE_GLOBAL_ID_RECLAIM"]; !ok {
|
||||
logger.Info("Disabling the insecure global ID as no legacy clients are currently connected. If you still require the insecure connections, see the CVE to suppress the health warning and re-enable the insecure connections. https://docs.ceph.com/en/latest/security/CVE-2021-20288/")
|
||||
if _, err := cephclient.SetConfig(c.context, c.clusterInfo, "mon", "auth_allow_insecure_global_id_reclaim", "false", false); err != nil {
|
||||
monStore := config.GetMonStore(c.context, c.clusterInfo)
|
||||
if err := monStore.Set("mon", "auth_allow_insecure_global_id_reclaim", "false"); err != nil {
|
||||
logger.Warningf("failed to disable the insecure global ID. %v", err)
|
||||
} else {
|
||||
logger.Info("insecure global ID is now disabled")
|
||||
|
||||
@@ -161,22 +161,17 @@ func TestConfigureHealthSettings(t *testing.T) {
|
||||
context: &clusterd.Context{},
|
||||
clusterInfo: cephclient.AdminClusterInfo("ns"),
|
||||
}
|
||||
getGlobalIDReclaim := false
|
||||
setGlobalIDReclaim := false
|
||||
c.context.Executor = &exectest.MockExecutor{
|
||||
MockExecuteCommandWithOutput: func(command string, args ...string) (string, error) {
|
||||
logger.Infof("Command: %s %v", command, args)
|
||||
if args[0] == "config" && args[3] == "auth_allow_insecure_global_id_reclaim" {
|
||||
if args[1] == "get" {
|
||||
getGlobalIDReclaim = true
|
||||
return "", nil
|
||||
}
|
||||
if args[1] == "set" {
|
||||
setGlobalIDReclaim = true
|
||||
return "", nil
|
||||
}
|
||||
}
|
||||
return "", errors.New("mock error to simulate failure of SetConfig() function")
|
||||
return "", errors.New("mock error to simulate failure of mon store config")
|
||||
},
|
||||
}
|
||||
noActionOneWarningStatus := cephclient.CephStatus{
|
||||
@@ -224,24 +219,21 @@ func TestConfigureHealthSettings(t *testing.T) {
|
||||
|
||||
type args struct {
|
||||
status cephclient.CephStatus
|
||||
expectedGetGlobalIDSetting bool
|
||||
expectedSetGlobalIDSetting bool
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
}{
|
||||
{"no-warnings", args{cephclient.CephStatus{}, false, false}},
|
||||
{"no-action-one-warning", args{noActionOneWarningStatus, false, false}},
|
||||
{"disable-insecure-global-id", args{disableInsecureGlobalIDStatus, true, true}},
|
||||
{"no-disable-insecure-global-id", args{noDisableInsecureGlobalIDStatus, false, false}},
|
||||
{"no-warnings", args{cephclient.CephStatus{}, false}},
|
||||
{"no-action-one-warning", args{noActionOneWarningStatus, false}},
|
||||
{"disable-insecure-global-id", args{disableInsecureGlobalIDStatus, true}},
|
||||
{"no-disable-insecure-global-id", args{noDisableInsecureGlobalIDStatus, false}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
getGlobalIDReclaim = false
|
||||
setGlobalIDReclaim = false
|
||||
c.configureHealthSettings(tt.args.status)
|
||||
assert.Equal(t, tt.args.expectedGetGlobalIDSetting, getGlobalIDReclaim)
|
||||
assert.Equal(t, tt.args.expectedSetGlobalIDSetting, setGlobalIDReclaim)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rook/rook/pkg/daemon/ceph/client"
|
||||
"github.com/rook/rook/pkg/operator/ceph/config"
|
||||
cephver "github.com/rook/rook/pkg/operator/ceph/version"
|
||||
"github.com/rook/rook/pkg/operator/k8sutil"
|
||||
"github.com/rook/rook/pkg/util/exec"
|
||||
@@ -111,17 +112,19 @@ func (c *Cluster) configureDashboardModules() error {
|
||||
}
|
||||
|
||||
func (c *Cluster) configureDashboardModuleSettings(daemonID string) (bool, error) {
|
||||
monStore := config.GetMonStore(c.context, c.clusterInfo)
|
||||
|
||||
daemonID = fmt.Sprintf("mgr.%s", daemonID)
|
||||
|
||||
// url prefix
|
||||
hasChanged, err := client.SetConfig(c.context, c.clusterInfo, daemonID, "mgr/dashboard/url_prefix", c.spec.Dashboard.URLPrefix, false)
|
||||
hasChanged, err := monStore.SetIfChanged(daemonID, "mgr/dashboard/url_prefix", c.spec.Dashboard.URLPrefix)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// ssl support
|
||||
ssl := strconv.FormatBool(c.spec.Dashboard.SSL)
|
||||
changed, err := client.SetConfig(c.context, c.clusterInfo, daemonID, "mgr/dashboard/ssl", ssl, false)
|
||||
changed, err := monStore.SetIfChanged(daemonID, "mgr/dashboard/ssl", ssl)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -129,7 +132,7 @@ func (c *Cluster) configureDashboardModuleSettings(daemonID string) (bool, error
|
||||
|
||||
// server port
|
||||
port := strconv.Itoa(c.dashboardPort())
|
||||
changed, err = client.SetConfig(c.context, c.clusterInfo, daemonID, "mgr/dashboard/server_port", port, false)
|
||||
changed, err = monStore.SetIfChanged(daemonID, "mgr/dashboard/server_port", port)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -137,7 +140,7 @@ func (c *Cluster) configureDashboardModuleSettings(daemonID string) (bool, error
|
||||
|
||||
// SSL enabled. Needed to set specifically the ssl port setting
|
||||
if c.spec.Dashboard.SSL {
|
||||
changed, err = client.SetConfig(c.context, c.clusterInfo, daemonID, "mgr/dashboard/ssl_server_port", port, false)
|
||||
changed, err = monStore.SetIfChanged(daemonID, "mgr/dashboard/ssl_server_port", port)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -52,6 +52,22 @@ type Option struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
func (m *MonStore) SetIfChanged(who, option, value string) (bool, error) {
|
||||
currentVal, err := m.Get(who, option)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to get value %q", option)
|
||||
}
|
||||
if currentVal == value {
|
||||
// no need to update the setting
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if err := m.Set(who, option, value); err != nil {
|
||||
return false, errors.Wrapf(err, "failed to set value %s=%s", option, value)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Set sets a config in the centralized mon configuration database.
|
||||
// https://docs.ceph.com/docs/master/rados/configuration/ceph-conf/#monitor-configuration-database
|
||||
func (m *MonStore) Set(who, option, value string) error {
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
"github.com/rook/rook/pkg/operator/ceph/cluster/mgr"
|
||||
"github.com/rook/rook/pkg/operator/ceph/cluster/mon"
|
||||
"github.com/rook/rook/pkg/operator/ceph/config"
|
||||
opcontroller "github.com/rook/rook/pkg/operator/ceph/controller"
|
||||
"github.com/rook/rook/pkg/operator/k8sutil"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
@@ -382,7 +383,12 @@ func configureRBDStats(clusterContext *clusterd.Context, clusterInfo *cephclient
|
||||
}
|
||||
}
|
||||
logger.Debugf("RBD per-image IO statistics will be collected for pools: %v", enableStatsForPools)
|
||||
_, err = cephclient.SetConfig(clusterContext, clusterInfo, "mgr.", "mgr/prometheus/rbd_stats_pools", strings.Join(enableStatsForPools, ","), false)
|
||||
monStore := config.GetMonStore(clusterContext, clusterInfo)
|
||||
if len(enableStatsForPools) == 0 {
|
||||
err = monStore.Delete("mgr.", "mgr/prometheus/rbd_stats_pools")
|
||||
} else {
|
||||
err = monStore.Set("mgr.", "mgr/prometheus/rbd_stats_pools", strings.Join(enableStatsForPools, ","))
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to enable rbd_stats_pools")
|
||||
}
|
||||
|
||||
@@ -445,13 +445,16 @@ func TestConfigureRBDStats(t *testing.T) {
|
||||
executor := &exectest.MockExecutor{
|
||||
MockExecuteCommandWithOutput: func(command string, args ...string) (string, error) {
|
||||
logger.Infof("Command: %s %v", command, args)
|
||||
switch {
|
||||
case args[0] == "config" && args[1] == "set" && args[2] == "mgr." && args[3] == "mgr/prometheus/rbd_stats_pools" && args[4] != "":
|
||||
return "", nil
|
||||
case args[0] == "config" && args[1] == "get" && args[2] == "mgr." && args[3] == "mgr/prometheus/rbd_stats_pools":
|
||||
return "", nil
|
||||
case args[0] == "config" && args[1] == "rm" && args[2] == "mgr." && args[3] == "mgr/prometheus/rbd_stats_pools":
|
||||
return "", nil
|
||||
if args[0] == "config" && args[2] == "mgr." && args[3] == "mgr/prometheus/rbd_stats_pools" {
|
||||
if args[1] == "set" && args[4] != "" {
|
||||
return "", nil
|
||||
}
|
||||
if args[1] == "get" {
|
||||
return "", nil
|
||||
}
|
||||
if args[1] == "rm" {
|
||||
return "", nil
|
||||
}
|
||||
}
|
||||
return "", errors.Errorf("unexpected arguments %q", args)
|
||||
},
|
||||
@@ -509,7 +512,7 @@ func TestConfigureRBDStats(t *testing.T) {
|
||||
context.Executor = &exectest.MockExecutor{
|
||||
MockExecuteCommandWithOutput: func(command string, args ...string) (string, error) {
|
||||
logger.Infof("Command: %s %v", command, args)
|
||||
return "", errors.New("mock error to simulate failure of SetConfig() function")
|
||||
return "", errors.New("mock error to simulate failure of mon store Set() function")
|
||||
},
|
||||
}
|
||||
err = configureRBDStats(context, clusterInfo)
|
||||
|
||||
Reference in new issue
Block a user