88
99 "github.com/redhat-best-practices-for-k8s/certsuite-qe/tests/globalhelper"
1010 "github.com/redhat-best-practices-for-k8s/certsuite-qe/tests/utils/pod"
11- "k8s.io/client-go/kubernetes/scheme"
12- "k8s.io/client-go/tools/remotecommand"
1311 klog "k8s.io/klog/v2"
1412 "k8s.io/utils/ptr"
1513
@@ -20,6 +18,8 @@ import (
2018 k8serrors "k8s.io/apimachinery/pkg/api/errors"
2119 "k8s.io/apimachinery/pkg/api/resource"
2220 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
22+ egiPod "github.com/openshift-kni/eco-goinfra/pkg/pod"
2323)
2424
2525func DefineExclusivePod (podName string , namespace string , image string , label map [string ]string ) * corev1.Pod {
@@ -140,46 +140,26 @@ func ExecCommandContainer(
140140
141141 var buffOut bytes.Buffer
142142
143- var buffErr bytes.Buffer
144-
145143 podName := pod .Name
146144 podNamespace := pod .Namespace
147- container := pod .Spec .Containers [0 ].Name
148145
146+ containerName := pod .Spec .Containers [0 ].Name
149147 klog .V (5 ).Infof ("execute command on ns=%s, pod=%s container=%s, cmd: %s" ,
150- podNamespace , podName , container , strings .Join (commandStr , " " ))
151-
152- req := globalhelper .GetAPIClient ().CoreV1Interface .RESTClient ().
153- Post ().
154- Namespace (podNamespace ).
155- Resource ("pods" ).
156- Name (podName ).
157- SubResource ("exec" ).
158- VersionedParams (& corev1.PodExecOptions {
159- Container : container ,
160- Command : commandStr ,
161- Stdin : false ,
162- Stdout : true ,
163- Stderr : true ,
164- TTY : false ,
165- }, scheme .ParameterCodec )
166-
167- exec , err := remotecommand .NewSPDYExecutor (globalhelper .GetAPIClient ().Config , "POST" , req .URL ())
148+ podNamespace , podName , containerName , strings .Join (commandStr , " " ))
149+
150+ builder , err := egiPod .Pull (globalhelper .GetEcoGoinfraClient (), podName , podNamespace )
168151 if err != nil {
169152 klog .ErrorS (err , "failed to create SPDY executor" )
170153
171- return stdout , stderr , err
154+ return "" , "" , err
172155 }
173156
174- err = exec .StreamWithContext (context .TODO (), remotecommand.StreamOptions {
175- Stdout : & buffOut ,
176- Stderr : & buffErr ,
177- })
178-
179- stdout , stderr = buffOut .String (), buffErr .String ()
157+ buffOut , err = builder .ExecCommand (commandStr )
158+ stdout = buffOut .String ()
159+ // stderr is not captured by eco-goinfra ExecCommand; leave empty
180160
181161 if err != nil {
182- klog .ErrorS (err , "exec stream failed" , "url" , req . URL (), " command" , command , "stderr" , stderr , "stdout" , stdout )
162+ klog .ErrorS (err , "exec stream failed" , "command" , command , "stderr" , stderr , "stdout" , stdout )
183163
184164 return stdout , stderr , err
185165 }
0 commit comments