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

multus: do not build all the args to remote exec cmd #8860

Merged
merged 1 commit into from Sep 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
21 changes: 19 additions & 2 deletions pkg/daemon/ceph/client/command.go
Expand Up @@ -126,10 +126,27 @@ func NewRBDCommand(context *clusterd.Context, clusterInfo *ClusterInfo, args []s
}

func (c *CephToolCommand) run() ([]byte, error) {
command, args := FinalizeCephCommandArgs(c.tool, c.clusterInfo, c.args, c.context.ConfigDir)
// Return if the context has been canceled
if c.clusterInfo.Context.Err() != nil {
return nil, c.clusterInfo.Context.Err()
}

// Initialize the command and args
command := c.tool
args := c.args

// If this is a remote execution, we don't want to build the full set of args. For instance all
// these args are not needed since those paths don't exist inside the cmd-proxy container:
// --cluster=openshift-storage
// --conf=/var/lib/rook/openshift-storage/openshift-storage.config
// --name=client.admin
// --keyring=/var/lib/rook/openshift-storage/client.admin.keyring
//
// The cmd-proxy container will take care of the rest with the help of the env CEPH_ARGS
if !c.RemoteExecution {
command, args = FinalizeCephCommandArgs(c.tool, c.clusterInfo, c.args, c.context.ConfigDir)
}

if c.JsonOutput {
args = append(args, "--format", "json")
} else {
Expand All @@ -147,7 +164,7 @@ func (c *CephToolCommand) run() ([]byte, error) {
if command == RBDTool {
if c.RemoteExecution {
output, stderr, err = c.context.RemoteExecutor.ExecCommandInContainerWithFullOutputWithTimeout(ProxyAppLabel, CommandProxyInitContainerName, c.clusterInfo.Namespace, append([]string{command}, args...)...)
output = fmt.Sprintf("%s.%s", output, stderr)
output = fmt.Sprintf("%s. %s", output, stderr)
} else if c.timeout == 0 {
output, err = c.context.Executor.ExecuteCommandWithOutput(command, args...)
} else {
Expand Down
2 changes: 2 additions & 0 deletions pkg/daemon/ceph/client/command_test.go
Expand Up @@ -116,6 +116,7 @@ func TestNewRBDCommand(t *testing.T) {
executor.MockExecuteCommandWithOutput = func(command string, args ...string) (string, error) {
switch {
case command == "rbd" && args[0] == "create":
assert.Len(t, args, 8)
return "success", nil
}
return "", errors.Errorf("unexpected ceph command %q", args)
Expand All @@ -137,6 +138,7 @@ func TestNewRBDCommand(t *testing.T) {
assert.True(t, cmd.RemoteExecution)
_, err := cmd.Run()
assert.Error(t, err)
assert.Len(t, cmd.args, 4)
// This is not the best but it shows we go through the right codepath
assert.EqualError(t, err, "no pods found with selector \"rook-ceph-mgr\"")
})
Expand Down