diff --git a/.github/workflows/canary-integration-test.yml b/.github/workflows/canary-integration-test.yml index 6581ebe13..393b832d3 100644 --- a/.github/workflows/canary-integration-test.yml +++ b/.github/workflows/canary-integration-test.yml @@ -1403,9 +1403,8 @@ jobs: - name: test ceph-csi-cephfs plugin restart run: tests/scripts/github-action-helper.sh test_csi_cephfs_workload - # uncomment once https://github.com/rook/rook/issues/10812 is resolved. - # - name: test ceph-csi-nfs plugin restart - # run: tests/scripts/github-action-helper.sh test_csi_nfs_workload + - name: test ceph-csi-nfs plugin restart + run: tests/scripts/github-action-helper.sh test_csi_nfs_workload - name: collect common logs if: always() diff --git a/pkg/daemon/ceph/client/command.go b/pkg/daemon/ceph/client/command.go index 760a2c31d..5c4e761da 100644 --- a/pkg/daemon/ceph/client/command.go +++ b/pkg/daemon/ceph/client/command.go @@ -45,6 +45,8 @@ const ( Kubectl = "kubectl" // CrushTool is the name of the CLI tool for 'crushtool' CrushTool = "crushtool" + // GaneshaRadosGraceTool is the name of the CLI tool for 'ganesha-rados-grace' + GaneshaRadosGraceTool = "ganesha-rados-grace" // DefaultPGCount will cause Ceph to use the internal default PG count DefaultPGCount = "0" // CommandProxyInitContainerName is the name of the init container for proxying ceph command when multus is used @@ -62,12 +64,17 @@ func CephConfFilePath(configDir, clusterName string) string { // FinalizeCephCommandArgs builds the command line to be called func FinalizeCephCommandArgs(command string, clusterInfo *ClusterInfo, args []string, configDir string) (string, []string) { timeout := strconv.Itoa(int(exec.CephCommandsTimeout.Seconds())) + cephConfPath := CephConfFilePath(configDir, clusterInfo.Namespace) // some tools not support the '--connect-timeout' option // so we only use it for the 'ceph' command switch command { case RBDTool, CrushTool, RadosTool, "radosgw-admin": // do not add timeout flag + case GaneshaRadosGraceTool: + // do not add timeout flag + // ganesha-rados-grace uses '--cephconf' for config file path + args = append(args, fmt.Sprintf("--cephconf=%s", cephConfPath)) default: args = append(args, "--connect-timeout="+timeout) } @@ -79,14 +86,21 @@ func FinalizeCephCommandArgs(command string, clusterInfo *ClusterInfo, args []st return Kubectl, append(toolArgs, args...) } - // Append the args to find the config and keyring - keyringFile := fmt.Sprintf("%s.keyring", clusterInfo.CephCred.Username) - configArgs := []string{ - fmt.Sprintf("--cluster=%s", clusterInfo.Namespace), - fmt.Sprintf("--conf=%s", CephConfFilePath(configDir, clusterInfo.Namespace)), - fmt.Sprintf("--name=%s", clusterInfo.CephCred.Username), - fmt.Sprintf("--keyring=%s", path.Join(configDir, clusterInfo.Namespace, keyringFile)), + configArgs := []string{} + switch command { + case GaneshaRadosGraceTool: + // ganesha-rados-grace does not accept any standard flags + default: + // Append the standard flags for config and keyring + keyringFile := fmt.Sprintf("%s.keyring", clusterInfo.CephCred.Username) + configArgs = []string{ + fmt.Sprintf("--cluster=%s", clusterInfo.Namespace), + fmt.Sprintf("--conf=%s", cephConfPath), + fmt.Sprintf("--name=%s", clusterInfo.CephCred.Username), + fmt.Sprintf("--keyring=%s", path.Join(configDir, clusterInfo.Namespace, keyringFile)), + } } + return command, append(args, configArgs...) } @@ -140,6 +154,18 @@ func NewRadosCommand(context *clusterd.Context, clusterInfo *ClusterInfo, args [ return cmd } +func NewGaneshaRadosGraceCommand(context *clusterd.Context, clusterInfo *ClusterInfo, args []string) *CephToolCommand { + cmd := newCephToolCommand(GaneshaRadosGraceTool, context, clusterInfo, args) + cmd.JsonOutput = false + + // When Multus is enabled, the rados tool should run inside the proxy container + if clusterInfo.NetworkSpec.IsMultus() { + cmd.RemoteExecution = true + } + + return cmd +} + func (c *CephToolCommand) run() ([]byte, error) { // Return if the context has been canceled if c.clusterInfo.Context.Err() != nil { @@ -167,7 +193,7 @@ func (c *CephToolCommand) run() ([]byte, error) { } else { // the `rbd` tool doesn't use special flag for plain format switch c.tool { - case RBDTool, RadosTool: + case RBDTool, RadosTool, GaneshaRadosGraceTool: // do not add format option default: args = append(args, "--format", "plain") @@ -179,7 +205,7 @@ func (c *CephToolCommand) run() ([]byte, error) { // NewRBDCommand does not use the --out-file option so we only check for remote execution here // Still forcing the check for the command if the behavior changes in the future - if command == RBDTool || command == RadosTool { + if command == RBDTool || command == RadosTool || command == GaneshaRadosGraceTool { if c.RemoteExecution { output, stderr, err = c.context.RemoteExecutor.ExecCommandInContainerWithFullOutputWithTimeout(c.clusterInfo.Context, ProxyAppLabel, CommandProxyInitContainerName, c.clusterInfo.Namespace, append([]string{command}, args...)...) if err != nil { diff --git a/pkg/daemon/ceph/client/command_test.go b/pkg/daemon/ceph/client/command_test.go index ca22c8a3c..651aac6e1 100644 --- a/pkg/daemon/ceph/client/command_test.go +++ b/pkg/daemon/ceph/client/command_test.go @@ -18,7 +18,9 @@ package client import ( "context" + "fmt" "strconv" + "strings" "testing" "time" @@ -158,3 +160,71 @@ func TestNewRBDCommand(t *testing.T) { }) } + +func TestNewGaneshaRadosGraceCommand(t *testing.T) { + anyArgContains := func(substr string, args []string) bool { + for _, arg := range args { + if strings.Contains(arg, substr) { + return true + } + } + return false + } + + args := []string{"--pool", ".nfs", "--ns", "my-nfs", "add", "node"} + + timeout := time.Second + + ctx := func() *clusterd.Context { + return &clusterd.Context{ + Executor: &exectest.MockExecutor{ + MockExecuteCommandWithTimeout: func(timeout time.Duration, command string, arg ...string) (string, error) { + t.Logf("command: %s %v", command, arg) + assert.Equal(t, time.Second, timeout) + + assert.Equal(t, "ganesha-rados-grace", command) + assert.Equal(t, []string{"--pool", ".nfs", "--ns", "my-nfs", "add", "node"}, arg[0:6]) + + // ganesha-rados-grace's conf flag is --cephconf + assert.True(t, anyArgContains("--cephconf=", arg)) + // ganesha-rados-grace accepts NO standard flags + assert.False(t, anyArgContains("--cluster", arg)) + assert.False(t, anyArgContains("--conf", arg)) + assert.False(t, anyArgContains("--name", arg)) + assert.False(t, anyArgContains("--keyring", arg)) + assert.False(t, anyArgContains("--format", arg)) + + return "", nil + }, + }, + } + } + + clusterInfo := func() *ClusterInfo { + return &ClusterInfo{ + Namespace: "rook-ceph", + Context: context.Background(), + } + } + + t.Run("normal call", func(t *testing.T) { + cmd := NewGaneshaRadosGraceCommand(ctx(), clusterInfo(), args) + assert.Equal(t, false, cmd.JsonOutput) + + _, err := cmd.RunWithTimeout(timeout) + assert.NoError(t, err) + }) + + t.Run("error call", func(t *testing.T) { + ctx := ctx() + ctx.Executor = &exectest.MockExecutor{ + MockExecuteCommandWithTimeout: func(timeout time.Duration, command string, arg ...string) (string, error) { + return "", fmt.Errorf("induced error") + }, + } + + cmd := NewGaneshaRadosGraceCommand(ctx, clusterInfo(), args) + _, err := cmd.RunWithTimeout(timeout) + assert.Error(t, err) + }) +} diff --git a/pkg/operator/ceph/nfs/controller_test.go b/pkg/operator/ceph/nfs/controller_test.go index e411c4132..884470391 100644 --- a/pkg/operator/ceph/nfs/controller_test.go +++ b/pkg/operator/ceph/nfs/controller_test.go @@ -22,6 +22,7 @@ import ( "fmt" "os" "testing" + "time" "github.com/coreos/pkg/capnslog" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" @@ -100,28 +101,30 @@ func TestCephNFSController(t *testing.T) { } panic(fmt.Sprintf("unhandled command %s %v", command, args)) }, - MockExecuteCommand: func(command string, args ...string) error { - logger.Infof("mock execute: %s %v", command, args) - if command == "rados" { - assert.Equal(t, "stat", args[6]) - assert.Contains(t, []string{"conf-nfs.my-nfs", "conf-nfs.nfs2"}, args[7]) - return nil - } - panic(fmt.Sprintf("unhandled command %s %v", command, args)) - }, - MockExecuteCommandWithEnv: func(env []string, command string, args ...string) error { + MockExecuteCommandWithTimeout: func(timeout time.Duration, command string, args ...string) (string, error) { logger.Infof("mock execute: %s %v", command, args) if command == "ganesha-rados-grace" { if args[4] == "add" { - assert.Len(t, env, 1) - return nil + return "", nil } if args[4] == "remove" { - assert.Len(t, env, 1) - return nil + return "", nil } } - panic(fmt.Sprintf("unhandled command %s %v with env %v", command, args, env)) + if command == "rados" { + subc := args[4] + switch subc { + case "stat", "lock", "unlock": + return "", nil + } + assert.Condition(t, func() bool { + return stringInSlice("conf-nfs.my-nfs", args) || + stringInSlice("conf-nfs.nfs2", args) || + stringInSlice("kerberos", args) + }) + return "", nil + } + panic(fmt.Sprintf("unhandled command %s %v", command, args)) }, } } @@ -507,3 +510,12 @@ func TestGetGaneshaConfigObject(t *testing.T) { logger.Infof("Config Object for Pacific is %s", res) assert.Equal(t, expectedName, res) } + +func stringInSlice(str string, slice []string) bool { + for _, s := range slice { + if s == str { + return true + } + } + return false +} diff --git a/pkg/operator/ceph/nfs/nfs.go b/pkg/operator/ceph/nfs/nfs.go index 51b9174a4..7ac3b0558 100644 --- a/pkg/operator/ceph/nfs/nfs.go +++ b/pkg/operator/ceph/nfs/nfs.go @@ -36,7 +36,6 @@ import ( ) const ( - ganeshaRadosGraceCmd = "ganesha-rados-grace" // Default RADOS pool name after the NFS changes in Ceph postNFSChangeDefaultPoolName = ".nfs" // Default RADOS pool name before the NFS changes in Ceph @@ -182,11 +181,10 @@ func (r *ReconcileCephNFS) removeServerFromDatabase(nfs *cephv1.CephNFS, name st func (r *ReconcileCephNFS) runGaneshaRadosGrace(nfs *cephv1.CephNFS, name, action string) error { nodeID := getNFSNodeID(nfs, name) - cmd := ganeshaRadosGraceCmd args := []string{"--pool", nfs.Spec.RADOS.Pool, "--ns", nfs.Spec.RADOS.Namespace, action, nodeID} - env := []string{fmt.Sprintf("CEPH_CONF=%s", cephclient.CephConfFilePath(r.context.ConfigDir, nfs.Namespace))} - - return r.context.Executor.ExecuteCommandWithEnv(env, cmd, args...) + cmd := cephclient.NewGaneshaRadosGraceCommand(r.context, r.clusterInfo, args) + _, err := cmd.RunWithTimeout(exec.CephCommandsTimeout) + return err } func (r *ReconcileCephNFS) generateConfigMap(n *cephv1.CephNFS, name string) *v1.ConfigMap { diff --git a/tests/scripts/github-action-helper.sh b/tests/scripts/github-action-helper.sh index c6a3dd7d7..8351dd8f8 100755 --- a/tests/scripts/github-action-helper.sh +++ b/tests/scripts/github-action-helper.sh @@ -479,7 +479,6 @@ function deploy_multus_cluster() { sed -i "s|#deviceFilter:|deviceFilter: ${BLOCK/\/dev\//}|g" cluster-multus-test.yaml kubectl create -f cluster-multus-test.yaml kubectl create -f filesystem-test.yaml - # uncomment once https://github.com/rook/rook/issues/10812 is resolved. kubectl create -f nfs-test.yaml }