@@ -114,18 +114,26 @@ func NewCmdExec(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Co
114
114
115
115
// RemoteExecutor defines the interface accepted by the Exec command - provided for test stubbing
116
116
type RemoteExecutor interface {
117
+ // Execute supports executing remote command in a pod.
117
118
Execute (url * url.URL , config * restclient.Config , stdin io.Reader , stdout , stderr io.Writer , tty bool , terminalSizeQueue remotecommand.TerminalSizeQueue ) error
119
+
120
+ // ExecuteWithContext, in contrast to Execute, supports stopping the remote command via context cancellation.
121
+ ExecuteWithContext (ctx context.Context , url * url.URL , config * restclient.Config , stdin io.Reader , stdout , stderr io.Writer , tty bool , terminalSizeQueue remotecommand.TerminalSizeQueue ) error
118
122
}
119
123
120
124
// DefaultRemoteExecutor is the standard implementation of remote command execution
121
125
type DefaultRemoteExecutor struct {}
122
126
123
- func (* DefaultRemoteExecutor ) Execute (url * url.URL , config * restclient.Config , stdin io.Reader , stdout , stderr io.Writer , tty bool , terminalSizeQueue remotecommand.TerminalSizeQueue ) error {
127
+ func (d * DefaultRemoteExecutor ) Execute (url * url.URL , config * restclient.Config , stdin io.Reader , stdout , stderr io.Writer , tty bool , terminalSizeQueue remotecommand.TerminalSizeQueue ) error {
128
+ return d .ExecuteWithContext (context .Background (), url , config , stdin , stdout , stderr , tty , terminalSizeQueue )
129
+ }
130
+
131
+ 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 {
124
132
exec , err := createExecutor (url , config )
125
133
if err != nil {
126
134
return err
127
135
}
128
- return exec .StreamWithContext (context . Background () , remotecommand.StreamOptions {
136
+ return exec .StreamWithContext (ctx , remotecommand.StreamOptions {
129
137
Stdin : stdin ,
130
138
Stdout : stdout ,
131
139
Stderr : stderr ,
0 commit comments