mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 18:28:13 +00:00 
			
		
		
		
	Merge pull request #130747 from soltysh/exec_context
kubectl: expose context parameter in DefaultRemoteExecutor
This commit is contained in:
		| @@ -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 | ||||
| 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 | ||||
|  | ||||
| 	// 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 | ||||
| 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) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return exec.StreamWithContext(context.Background(), remotecommand.StreamOptions{ | ||||
| 	return exec.StreamWithContext(ctx, remotecommand.StreamOptions{ | ||||
| 		Stdin:             stdin, | ||||
| 		Stdout:            stdout, | ||||
| 		Stderr:            stderr, | ||||
|   | ||||
| @@ -18,6 +18,7 @@ package exec | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"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 { | ||||
| 	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 | ||||
| 	return f.execErr | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kubernetes Prow Robot
					Kubernetes Prow Robot