@@ -104,7 +104,7 @@ func containerToAttachTo(container string, pod *v1.Pod) (*v1.Container, error) {
104104}
105105
106106// attach attaches to a given pod, outputting to stdout and stderr
107- func attach (kubeconfig string , pod * v1.Pod , stdin io.Reader , stdout , stderr io.Writer ) error {
107+ func attach (kubeconfig string , pod * v1.Pod , attachOptions * v1. PodAttachOptions , stdin io.Reader , stdout , stderr io.Writer ) error {
108108 clientset , config , err := getKubeClient (kubeconfig )
109109 if err != nil {
110110 log .Fatalf ("cannot get clientset: %v" , err )
@@ -121,33 +121,26 @@ func attach(kubeconfig string, pod *v1.Pod, stdin io.Reader, stdout, stderr io.W
121121 Namespace (pod .Namespace ).
122122 SubResource ("attach" )
123123
124- req .VersionedParams (& v1.PodAttachOptions {
125- Container : container .Name ,
126- Stdin : true ,
127- Stdout : true ,
128- Stderr : true ,
129- TTY : false ,
130- }, scheme .ParameterCodec )
124+ attachOptions .Container = container .Name
125+ req .VersionedParams (attachOptions , scheme .ParameterCodec )
131126
132- err = startStream ("POST" , req .URL (), config , stdin , stdout , stderr , false )
127+ streamOptions := getStreamOptions (attachOptions , stdin , stdout , stderr )
128+
129+ err = startStream ("POST" , req .URL (), config , streamOptions )
133130 if err != nil {
134131 return fmt .Errorf ("error executing: %v" , err )
135132 }
136133
137134 return nil
138135}
139136
140- func startStream (method string , url * url.URL , config * restclient.Config , stdin io. Reader , stdout , stderr io. Writer , tty bool ) error {
137+ func startStream (method string , url * url.URL , config * restclient.Config , streamOptions remotecommand. StreamOptions ) error {
141138 exec , err := remotecommand .NewSPDYExecutor (config , method , url )
142139 if err != nil {
143140 return err
144141 }
145- return exec .Stream (remotecommand.StreamOptions {
146- Stdin : stdin ,
147- Stdout : stdout ,
148- Stderr : stderr ,
149- Tty : tty ,
150- })
142+
143+ return exec .Stream (streamOptions )
151144}
152145
153146// watchPod waits until the created pod is in running state
@@ -179,3 +172,20 @@ func watchPod(kubeconfig string, pod *v1.Pod) {
179172
180173 controller .Run (stop )
181174}
175+
176+ func getStreamOptions (attachOptions * v1.PodAttachOptions , stdin io.Reader , stdout , stderr io.Writer ) remotecommand.StreamOptions {
177+ var streamOptions remotecommand.StreamOptions
178+ if attachOptions .Stdin {
179+ streamOptions .Stdin = stdin
180+ }
181+
182+ if attachOptions .Stdout {
183+ streamOptions .Stdout = stdout
184+ }
185+
186+ if attachOptions .Stderr {
187+ streamOptions .Stderr = stderr
188+ }
189+
190+ return streamOptions
191+ }
0 commit comments