Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mgr: do not set the balancer mode on pacific #9063

Merged
merged 1 commit into from Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions pkg/operator/ceph/cluster/mgr/mgr.go
Expand Up @@ -361,14 +361,18 @@ func (c *Cluster) enableCrashModule() error {
func (c *Cluster) enableBalancerModule() error {
// The order MATTERS, always configure this module first, then turn it on

// This sets min compat client to luminous and the balancer module mode
err := cephclient.ConfigureBalancerModule(c.context, c.clusterInfo, balancerModuleMode)
if err != nil {
return errors.Wrapf(err, "failed to configure module %q", balancerModuleName)
// This enables the balancer module mode only in versions older than Pacific
// This let's the user change the default mode if desired
if !c.clusterInfo.CephVersion.IsAtLeastPacific() {
// This sets min compat client to luminous and the balancer module mode
err := cephclient.ConfigureBalancerModule(c.context, c.clusterInfo, balancerModuleMode)
if err != nil {
return errors.Wrapf(err, "failed to configure module %q", balancerModuleName)
}
}

// This turns "on" the balancer
err = cephclient.MgrEnableModule(c.context, c.clusterInfo, balancerModuleName, false)
err := cephclient.MgrEnableModule(c.context, c.clusterInfo, balancerModuleName, false)
if err != nil {
return errors.Wrapf(err, "failed to turn on mgr %q module", balancerModuleName)
}
Expand Down
67 changes: 61 additions & 6 deletions pkg/operator/ceph/cluster/mgr/mgr_test.go
Expand Up @@ -24,14 +24,13 @@ import (
"testing"
"time"

"github.com/pkg/errors"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"github.com/rook/rook/pkg/client/clientset/versioned/scheme"
"github.com/rook/rook/pkg/clusterd"
cephclient "github.com/rook/rook/pkg/daemon/ceph/client"
cephver "github.com/rook/rook/pkg/operator/ceph/version"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
testopk8s "github.com/rook/rook/pkg/operator/k8sutil/test"
testop "github.com/rook/rook/pkg/operator/test"
exectest "github.com/rook/rook/pkg/util/exec/test"
Expand All @@ -40,8 +39,9 @@ import (
apps "k8s.io/api/apps/v1"
policyv1 "k8s.io/api/policy/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func TestStartMgr(t *testing.T) {
Expand Down Expand Up @@ -172,7 +172,7 @@ func validateServices(t *testing.T, c *Cluster) {
assert.Equal(t, ds.Spec.Ports[0].Port, int32(c.spec.Dashboard.Port))
}
} else {
assert.True(t, errors.IsNotFound(err))
assert.True(t, kerrors.IsNotFound(err))
}
}

Expand Down Expand Up @@ -227,7 +227,7 @@ func TestMgrSidecarReconcile(t *testing.T) {
assert.True(t, calledMgrStat)
assert.False(t, calledMgrDump)
_, err = c.context.Clientset.CoreV1().Services(c.clusterInfo.Namespace).Get(context.TODO(), "rook-ceph-mgr", metav1.GetOptions{})
assert.True(t, errors.IsNotFound(err))
assert.True(t, kerrors.IsNotFound(err))

// nothing is updated when the requested mgr is not the active mgr
activeMgr = "b"
Expand Down Expand Up @@ -378,3 +378,58 @@ func TestApplyMonitoringLabels(t *testing.T) {
applyMonitoringLabels(c, sm)
assert.Nil(t, sm.Spec.Endpoints[0].RelabelConfigs)
}

func TestCluster_enableBalancerModule(t *testing.T) {
c := &Cluster{
context: &clusterd.Context{Executor: &exectest.MockExecutor{}, Clientset: testop.New(t, 3)},
clusterInfo: cephclient.AdminClusterInfo("mycluster"),
}

t.Run("on octopus we configure the balancer AND enable the upmap mode", func(t *testing.T) {
c.clusterInfo.CephVersion = cephver.Octopus
executor := &exectest.MockExecutor{
MockExecuteCommandWithOutput: func(command string, args ...string) (string, error) {
logger.Infof("Command: %s %v", command, args)
if command == "ceph" {
if args[0] == "osd" && args[1] == "set-require-min-compat-client" {
return "", nil
}
if args[0] == "balancer" && args[1] == "mode" {
return "", nil
}
if args[0] == "balancer" && args[1] == "on" {
return "", nil
}
}
return "", errors.New("unknown command")
},
}
c.context.Executor = executor
err := c.enableBalancerModule()
assert.NoError(t, err)
})

t.Run("on pacific we configure the balancer ONLY and don't set a mode", func(t *testing.T) {
c.clusterInfo.CephVersion = cephver.Pacific
executor := &exectest.MockExecutor{
MockExecuteCommandWithOutput: func(command string, args ...string) (string, error) {
logger.Infof("Command: %s %v", command, args)
if command == "ceph" {
if args[0] == "osd" && args[1] == "set-require-min-compat-client" {
return "", nil
}
if args[0] == "balancer" && args[1] == "mode" {
return "", errors.New("balancer mode must not be set")
}
if args[0] == "balancer" && args[1] == "on" {
return "", nil
}
}
return "", errors.New("unknown command")
},
}
c.context.Executor = executor
err := c.enableBalancerModule()
assert.NoError(t, err)
})
}