kubectl: expose context parameter in DefaultRemoteExecutor
Signed-off-by: Maciej Szulik <soltysh@gmail.com> Kubernetes-commit: 78e58b8c49fdcddba8cf939e5327440791c73a91
This commit is contained in:
parent
277c37ab57
commit
e4ccb76c1a
|
@ -114,18 +114,26 @@ func NewCmdExec(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Co
|
||||||
|
|
||||||
// RemoteExecutor defines the interface accepted by the Exec command - provided for test stubbing
|
// RemoteExecutor defines the interface accepted by the Exec command - provided for test stubbing
|
||||||
type RemoteExecutor interface {
|
type RemoteExecutor interface {
|
||||||
|
// Execute supports executing remote command in a pod.
|
||||||
Execute(url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error
|
Execute(url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error
|
||||||
|
|
||||||
|
// ExecuteWithContext, in contrast to Execute, supports stopping the remote command via context cancellation.
|
||||||
|
ExecuteWithContext(ctx context.Context, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultRemoteExecutor is the standard implementation of remote command execution
|
// DefaultRemoteExecutor is the standard implementation of remote command execution
|
||||||
type DefaultRemoteExecutor struct{}
|
type DefaultRemoteExecutor struct{}
|
||||||
|
|
||||||
func (*DefaultRemoteExecutor) Execute(url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error {
|
func (d *DefaultRemoteExecutor) Execute(url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error {
|
||||||
|
return d.ExecuteWithContext(context.Background(), url, config, stdin, stdout, stderr, tty, terminalSizeQueue)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DefaultRemoteExecutor) ExecuteWithContext(ctx context.Context, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error {
|
||||||
exec, err := createExecutor(url, config)
|
exec, err := createExecutor(url, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return exec.StreamWithContext(context.Background(), remotecommand.StreamOptions{
|
return exec.StreamWithContext(ctx, remotecommand.StreamOptions{
|
||||||
Stdin: stdin,
|
Stdin: stdin,
|
||||||
Stdout: stdout,
|
Stdout: stdout,
|
||||||
Stderr: stderr,
|
Stderr: stderr,
|
||||||
|
|
|
@ -18,6 +18,7 @@ package exec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -45,6 +46,10 @@ type fakeRemoteExecutor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *fakeRemoteExecutor) Execute(url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error {
|
func (f *fakeRemoteExecutor) Execute(url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error {
|
||||||
|
return f.ExecuteWithContext(context.Background(), url, config, stdin, stdout, stderr, tty, terminalSizeQueue)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeRemoteExecutor) ExecuteWithContext(ctx context.Context, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error {
|
||||||
f.url = url
|
f.url = url
|
||||||
return f.execErr
|
return f.execErr
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue