Skip to content

Commit

Permalink
core: add context parameter in functions executing commands in container
Browse files Browse the repository at this point in the history
This commit adds context parameter to function
ExecCommandInContainerWithFullOutPut(). The context parameter is used
while getting the list of pods.

Closes: rook#8701
Signed-off-by: Divyansh Kamboj <dkamboj@redhat.com>
  • Loading branch information
weirdwiz committed Feb 2, 2022
1 parent b407616 commit 01af385
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/daemon/ceph/client/command.go
Expand Up @@ -165,7 +165,7 @@ func (c *CephToolCommand) run() ([]byte, error) {
// Still forcing the check for the command if the behavior changes in the future
if command == RBDTool {
if c.RemoteExecution {
output, stderr, err = c.context.RemoteExecutor.ExecCommandInContainerWithFullOutputWithTimeout(ProxyAppLabel, CommandProxyInitContainerName, c.clusterInfo.Namespace, append([]string{command}, args...)...)
output, stderr, err = c.context.RemoteExecutor.ExecCommandInContainerWithFullOutputWithTimeout(c.clusterInfo.Context, ProxyAppLabel, CommandProxyInitContainerName, c.clusterInfo.Namespace, append([]string{command}, args...)...)
if stderr != "" || err != nil {
err = errors.Errorf("%s. %s", err.Error(), stderr)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/ceph/object/admin.go
Expand Up @@ -216,7 +216,7 @@ func RunAdminCommandNoMultisite(c *Context, expectJSON bool, args ...string) (st

// If Multus is enabled we proxy all the command to the mgr sidecar
if c.CephClusterSpec.Network.IsMultus() {
output, stderr, err = c.Context.RemoteExecutor.ExecCommandInContainerWithFullOutputWithTimeout(cephclient.ProxyAppLabel, cephclient.CommandProxyInitContainerName, c.clusterInfo.Namespace, append([]string{"radosgw-admin"}, args...)...)
output, stderr, err = c.Context.RemoteExecutor.ExecCommandInContainerWithFullOutputWithTimeout(c.clusterInfo.Context, cephclient.ProxyAppLabel, cephclient.CommandProxyInitContainerName, c.clusterInfo.Namespace, append([]string{"radosgw-admin"}, args...)...)
} else {
command, args := cephclient.FinalizeCephCommandArgs("radosgw-admin", c.clusterInfo, args, c.Context.ConfigDir)
output, err = c.Context.Executor.ExecuteCommandWithTimeout(exec.CephCommandsTimeout, command, args...)
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/exec/exec_pod.go
Expand Up @@ -92,9 +92,9 @@ func (e *RemotePodCommandExecutor) ExecWithOptions(options ExecOptions) (string,

// ExecCommandInContainerWithFullOutput executes a command in the
// specified container and return stdout, stderr and error
func (e *RemotePodCommandExecutor) ExecCommandInContainerWithFullOutput(appLabel, containerName, namespace string, cmd ...string) (string, string, error) {
func (e *RemotePodCommandExecutor) ExecCommandInContainerWithFullOutput(ctx context.Context, appLabel, containerName, namespace string, cmd ...string) (string, string, error) {
options := metav1.ListOptions{LabelSelector: fmt.Sprintf("app=%s", appLabel)}
pods, err := e.ClientSet.CoreV1().Pods(namespace).List(context.TODO(), options)
pods, err := e.ClientSet.CoreV1().Pods(namespace).List(ctx, options)
if err != nil {
return "", "", err
}
Expand Down Expand Up @@ -130,6 +130,6 @@ func execute(method string, url *url.URL, config *rest.Config, stdin io.Reader,
})
}

func (e *RemotePodCommandExecutor) ExecCommandInContainerWithFullOutputWithTimeout(appLabel, containerName, namespace string, cmd ...string) (string, string, error) {
return e.ExecCommandInContainerWithFullOutput(appLabel, containerName, namespace, append([]string{"timeout", strconv.Itoa(int(CephCommandsTimeout.Seconds()))}, cmd...)...)
func (e *RemotePodCommandExecutor) ExecCommandInContainerWithFullOutputWithTimeout(ctx context.Context, appLabel, containerName, namespace string, cmd ...string) (string, string, error) {
return e.ExecCommandInContainerWithFullOutput(ctx, appLabel, containerName, namespace, append([]string{"timeout", strconv.Itoa(int(CephCommandsTimeout.Seconds()))}, cmd...)...)
}
2 changes: 1 addition & 1 deletion tests/framework/utils/k8s_helper.go
Expand Up @@ -222,7 +222,7 @@ func (k8sh *K8sHelper) ExecRemoteWithRetry(retries int, namespace, command strin
var output, stderr string
cliFinal := append([]string{command}, commandArgs...)
for i := 0; i < retries; i++ {
output, stderr, err = k8sh.remoteExecutor.ExecCommandInContainerWithFullOutput("rook-ceph-tools", "rook-ceph-tools", namespace, cliFinal...)
output, stderr, err = k8sh.remoteExecutor.ExecCommandInContainerWithFullOutput(context.TODO(), "rook-ceph-tools", "rook-ceph-tools", namespace, cliFinal...)
if err == nil {
return output, nil
}
Expand Down

0 comments on commit 01af385

Please sign in to comment.