mon: refactor helper to assimilate mon store settings
More settings can use the assimilate command if refactored
to a different go package.
Signed-off-by: Travis Nielsen <tnielsen@redhat.com>
(cherry picked from commit 0514547d56)
This commit is contained in:
1 parent
343a3c9709
commit
4e0e3f62fc
2 files changed
+69
-69
No files matched your search
@@ -20,8 +20,6 @@ package cluster
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strconv"
|
||||
@@ -29,9 +27,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/ini.v1"
|
||||
|
||||
"github.com/rook/rook/cmd/rook/rook"
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
"github.com/rook/rook/pkg/daemon/ceph/client"
|
||||
@@ -46,7 +42,6 @@ import (
|
||||
"github.com/rook/rook/pkg/operator/ceph/csi"
|
||||
cephver "github.com/rook/rook/pkg/operator/ceph/version"
|
||||
"github.com/rook/rook/pkg/operator/k8sutil"
|
||||
pkgexec "github.com/rook/rook/pkg/util/exec"
|
||||
rookversion "github.com/rook/rook/pkg/version"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
@@ -600,74 +595,13 @@ func (c *cluster) reportTelemetry() {
|
||||
telemetry.ReportKeyValue(c.context, c.ClusterInfo, telemetry.ExternalModeEnabledKey, strconv.FormatBool(c.Spec.External.Enable))
|
||||
}
|
||||
|
||||
func (c *cluster) addSettingsToMonDB(clientName string, settings map[string]string) error {
|
||||
|
||||
assimilateConfPath, err := ioutil.TempFile("", "")
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to create assimilateConf temp dir for %s.", clientName)
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(assimilateConfPath.Name(), []byte(""), 0600)
|
||||
if err != nil {
|
||||
rook.TerminateFatal(errors.Wrapf(err, "failed to write config file"))
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := os.Remove(assimilateConfPath.Name())
|
||||
if err != nil {
|
||||
logger.Errorf("failed to remove file %q. %v", assimilateConfPath.Name(), err)
|
||||
}
|
||||
}()
|
||||
|
||||
configFile := ini.Empty()
|
||||
s, err := configFile.NewSection(clientName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, val := range settings {
|
||||
if _, err := s.NewKey(key, val); err != nil {
|
||||
return errors.Wrapf(err, "failed to add key %s", key)
|
||||
}
|
||||
}
|
||||
|
||||
if err := configFile.SaveTo(assimilateConfPath.Name()); err != nil {
|
||||
return errors.Wrapf(err, "failed to save config file %s", assimilateConfPath.Name())
|
||||
}
|
||||
|
||||
fileContent, err := ioutil.ReadFile(assimilateConfPath.Name())
|
||||
if err != nil {
|
||||
logger.Errorf("failed to open assimilate input file %s. %c", assimilateConfPath.Name(), err)
|
||||
}
|
||||
logger.Infof("applying ceph settings:\n%s", string(fileContent))
|
||||
|
||||
args := []string{"config", "assimilate-conf", "-i", assimilateConfPath.Name(), "-o", assimilateConfPath.Name() + ".out"}
|
||||
cephCmd := client.NewCephCommand(c.context, c.ClusterInfo, args)
|
||||
|
||||
out, err := cephCmd.RunWithTimeout(pkgexec.CephCommandsTimeout)
|
||||
if err != nil {
|
||||
logger.Errorf("failed to run command ceph %s", args)
|
||||
|
||||
fileContent, err := ioutil.ReadFile(assimilateConfPath.Name() + ".out")
|
||||
if err != nil {
|
||||
logger.Errorf("failed to open assimilate output file %s.out. %v", assimilateConfPath.Name(), err)
|
||||
}
|
||||
logger.Infof("failed to apply ceph settings:\n%s", string(fileContent))
|
||||
|
||||
return errors.Wrapf(err, "failed to set ceph config in the centralized mon configuration database; "+
|
||||
"output: %s", string(out))
|
||||
}
|
||||
|
||||
logger.Info("successfully applied settings to the mon configuration database")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *cluster) configureMsgr2() error {
|
||||
if c.Spec.Network.Connections == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Set network encryption
|
||||
monStore := config.GetMonStore(c.context, c.ClusterInfo)
|
||||
if c.Spec.Network.Connections.Encryption != nil {
|
||||
encryptionSetting := "crc secure"
|
||||
if c.Spec.Network.Connections.Encryption.Enabled {
|
||||
@@ -681,7 +615,7 @@ func (c *cluster) configureMsgr2() error {
|
||||
}
|
||||
|
||||
logger.Infof("setting msgr2 encryption mode to %q", encryptionSetting)
|
||||
if err := c.addSettingsToMonDB("global", globalConfigSettings); err != nil {
|
||||
if err := monStore.AddSettingsToMonDB("global", globalConfigSettings); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -697,7 +631,7 @@ func (c *cluster) configureMsgr2() error {
|
||||
"ms_osd_compress_mode": compressionSetting,
|
||||
}
|
||||
logger.Infof("setting msgr2 compression mode to %q", compressionSetting)
|
||||
if err := c.addSettingsToMonDB("global", globalConfigSettings); err != nil {
|
||||
if err := monStore.AddSettingsToMonDB("global", globalConfigSettings); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -18,12 +18,16 @@ package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rook/rook/cmd/rook/rook"
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
"github.com/rook/rook/pkg/daemon/ceph/client"
|
||||
"github.com/rook/rook/pkg/util/exec"
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
// MonStore provides methods for setting Ceph configurations in the centralized mon
|
||||
@@ -207,3 +211,65 @@ func (m *MonStore) SetKeyValue(key, value string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MonStore) AddSettingsToMonDB(clientName string, settings map[string]string) error {
|
||||
|
||||
assimilateConfPath, err := ioutil.TempFile("", "")
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to create assimilateConf temp dir for %s.", clientName)
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(assimilateConfPath.Name(), []byte(""), 0600)
|
||||
if err != nil {
|
||||
rook.TerminateFatal(errors.Wrapf(err, "failed to write config file"))
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := os.Remove(assimilateConfPath.Name())
|
||||
if err != nil {
|
||||
logger.Errorf("failed to remove file %q. %v", assimilateConfPath.Name(), err)
|
||||
}
|
||||
}()
|
||||
|
||||
configFile := ini.Empty()
|
||||
s, err := configFile.NewSection(clientName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, val := range settings {
|
||||
if _, err := s.NewKey(key, val); err != nil {
|
||||
return errors.Wrapf(err, "failed to add key %s", key)
|
||||
}
|
||||
}
|
||||
|
||||
if err := configFile.SaveTo(assimilateConfPath.Name()); err != nil {
|
||||
return errors.Wrapf(err, "failed to save config file %s", assimilateConfPath.Name())
|
||||
}
|
||||
|
||||
fileContent, err := ioutil.ReadFile(assimilateConfPath.Name())
|
||||
if err != nil {
|
||||
logger.Errorf("failed to open assimilate input file %s. %c", assimilateConfPath.Name(), err)
|
||||
}
|
||||
logger.Infof("applying ceph settings:\n%s", string(fileContent))
|
||||
|
||||
args := []string{"config", "assimilate-conf", "-i", assimilateConfPath.Name(), "-o", assimilateConfPath.Name() + ".out"}
|
||||
cephCmd := client.NewCephCommand(m.context, m.clusterInfo, args)
|
||||
|
||||
out, err := cephCmd.RunWithTimeout(exec.CephCommandsTimeout)
|
||||
if err != nil {
|
||||
logger.Errorf("failed to run command ceph %s", args)
|
||||
|
||||
fileContent, err := ioutil.ReadFile(assimilateConfPath.Name() + ".out")
|
||||
if err != nil {
|
||||
logger.Errorf("failed to open assimilate output file %s.out. %v", assimilateConfPath.Name(), err)
|
||||
}
|
||||
logger.Infof("failed to apply ceph settings:\n%s", string(fileContent))
|
||||
|
||||
return errors.Wrapf(err, "failed to set ceph config in the centralized mon configuration database; "+
|
||||
"output: %s", string(out))
|
||||
}
|
||||
|
||||
logger.Info("successfully applied settings to the mon configuration database")
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user