Files
my-rook-config/pkg/daemon/ceph/client/mgr.go
T

181 lines
5.5 KiB
Go
Raw Normal View History

2019-01-25 17:46:57 +01:00
/*
Copyright 2019 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2017-10-30 17:33:17 +01:00
package client
import (
"encoding/json"
2019-12-16 17:17:32 +05:30
"time"
2017-10-30 17:33:17 +01:00
2019-10-08 12:51:36 +02:00
"github.com/pkg/errors"
2017-10-30 17:33:17 +01:00
"github.com/rook/rook/pkg/clusterd"
)
2019-12-16 17:17:32 +05:30
var (
moduleEnableWaitTime = 5 * time.Second
)
2021-02-12 17:41:40 -07:00
func CephMgrMap(context *clusterd.Context, clusterInfo *ClusterInfo) (*MgrMap, error) {
args := []string{"mgr", "dump"}
buf, err := NewCephCommand(context, clusterInfo, args).Run()
if err != nil {
if len(buf) > 0 {
2021-02-12 17:41:40 -07:00
return nil, errors.Wrapf(err, "failed to get mgr dump. %s", string(buf))
}
2021-02-12 17:41:40 -07:00
return nil, errors.Wrap(err, "failed to get mgr dump")
}
var mgrMap MgrMap
if err := json.Unmarshal([]byte(buf), &mgrMap); err != nil {
2021-02-12 17:41:40 -07:00
return nil, errors.Wrap(err, "failed to unmarshal mgr dump")
}
2021-02-12 17:41:40 -07:00
return &mgrMap, nil
}
func CephMgrStat(context *clusterd.Context, clusterInfo *ClusterInfo) (*MgrStat, error) {
args := []string{"mgr", "stat"}
buf, err := NewCephCommand(context, clusterInfo, args).Run()
if err != nil {
if len(buf) > 0 {
return nil, errors.Wrapf(err, "failed to get mgr stat. %s", string(buf))
}
return nil, errors.Wrap(err, "failed to get mgr stat")
}
var mgrStat MgrStat
if err := json.Unmarshal([]byte(buf), &mgrStat); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal mgr stat")
}
return &mgrStat, nil
}
2018-06-07 15:08:58 -07:00
// MgrEnableModule enables a mgr module
func MgrEnableModule(context *clusterd.Context, clusterInfo *ClusterInfo, name string, force bool) error {
2019-12-16 17:17:32 +05:30
retryCount := 5
2020-01-30 19:31:53 +01:00
var err error
2019-12-16 17:17:32 +05:30
for i := 0; i < retryCount; i++ {
2022-07-01 10:38:15 -06:00
if name == "balancer" {
2023-11-14 09:05:27 -07:00
logger.Debug("balancer module is always 'on', doing nothing", name)
return nil
2020-01-30 19:31:53 +01:00
} else {
err = enableModule(context, clusterInfo, name, force, "enable")
2020-01-30 19:31:53 +01:00
}
2019-12-16 17:17:32 +05:30
if err != nil {
if i < retryCount-1 {
logger.Warningf("failed to enable mgr module %q. trying again...", name)
time.Sleep(moduleEnableWaitTime)
continue
} else {
return errors.Wrapf(err, "failed to enable mgr module %q even after %d retries", name, retryCount)
}
}
break
}
return nil
2018-06-07 15:08:58 -07:00
}
// MgrDisableModule disables a mgr module
func MgrDisableModule(context *clusterd.Context, clusterInfo *ClusterInfo, name string) error {
2020-01-30 19:31:53 +01:00
if name == "balancer" {
return enableDisableBalancerModule(context, clusterInfo, "off")
2020-01-30 19:31:53 +01:00
}
return enableModule(context, clusterInfo, name, false, "disable")
2018-06-07 15:08:58 -07:00
}
func enableModule(context *clusterd.Context, clusterInfo *ClusterInfo, name string, force bool, action string) error {
2018-06-07 15:08:58 -07:00
args := []string{"mgr", "module", action, name}
2017-10-30 17:33:17 +01:00
if force {
args = append(args, "--force")
}
2019-12-16 17:17:32 +05:30
_, err := NewCephCommand(context, clusterInfo, args).Run()
2017-10-30 17:33:17 +01:00
if err != nil {
2019-12-16 17:17:32 +05:30
return errors.Wrapf(err, "failed to enable mgr module %q", name)
2017-10-30 17:33:17 +01:00
}
return nil
}
2020-01-30 19:31:53 +01:00
// enableDisableBalancerModule enables the ceph balancer module
func enableDisableBalancerModule(context *clusterd.Context, clusterInfo *ClusterInfo, action string) error {
2020-01-30 19:31:53 +01:00
args := []string{"balancer", action}
_, err := NewCephCommand(context, clusterInfo, args).Run()
2020-01-30 19:31:53 +01:00
if err != nil {
return errors.Wrapf(err, "failed to turn %q the balancer module", action)
}
return nil
}
func setBalancerMode(context *clusterd.Context, clusterInfo *ClusterInfo, mode string) error {
2020-01-30 19:31:53 +01:00
args := []string{"balancer", "mode", mode}
_, err := NewCephCommand(context, clusterInfo, args).Run()
2020-01-30 19:31:53 +01:00
if err != nil {
return errors.Wrapf(err, "failed to set balancer mode %q", mode)
}
return nil
}
2020-06-09 15:42:15 +02:00
// setMinCompatClientLuminous set the minimum compatibility for clients to Luminous
func setMinCompatClientLuminous(context *clusterd.Context, clusterInfo *ClusterInfo) error {
args := []string{"osd", "set-require-min-compat-client", "luminous", "--yes-i-really-mean-it"}
_, err := NewCephCommand(context, clusterInfo, args).Run()
2020-01-30 19:31:53 +01:00
if err != nil {
return errors.Wrap(err, "failed to set set-require-min-compat-client to luminous")
}
return nil
}
2020-06-09 15:42:15 +02:00
// mgrSetBalancerMode sets the given mode to the balancer module
func mgrSetBalancerMode(context *clusterd.Context, clusterInfo *ClusterInfo, balancerModuleMode string) error {
2020-01-30 19:31:53 +01:00
retryCount := 5
for i := 0; i < retryCount; i++ {
err := setBalancerMode(context, clusterInfo, balancerModuleMode)
2020-01-30 19:31:53 +01:00
if err != nil {
if i < retryCount-1 {
logger.Warningf("failed to set mgr module mode %q. trying again...", balancerModuleMode)
time.Sleep(moduleEnableWaitTime)
continue
} else {
return errors.Wrapf(err, "failed to set mgr module mode %q even after %d retries", balancerModuleMode, retryCount)
}
}
break
}
return nil
}
2020-06-09 15:42:15 +02:00
// ConfigureBalancerModule configures the balancer module
func ConfigureBalancerModule(context *clusterd.Context, clusterInfo *ClusterInfo, balancerModuleMode string) error {
2020-06-09 15:42:15 +02:00
// Set min compat client to luminous before enabling the balancer mode "upmap"
err := setMinCompatClientLuminous(context, clusterInfo)
2020-06-09 15:42:15 +02:00
if err != nil {
return errors.Wrap(err, "failed to set minimum compatibility client")
}
// Set balancer module mode
err = mgrSetBalancerMode(context, clusterInfo, balancerModuleMode)
2020-06-09 15:42:15 +02:00
if err != nil {
return errors.Wrapf(err, "failed to set balancer module mode to %q", balancerModuleMode)
}
return nil
}