@@ -66,7 +66,7 @@ func GetListOfFilesFromK8s(iClient interface{}, path, findType, findName string)
6666 return nil , err
6767 }
6868 namespace , podName , containerName , findPath := initK8sVariables (pSplit )
69- command := fmt . Sprintf ( "find %s -type %s -name %s " , findPath , findType , findName )
69+ command := [] string { "find" , findPath , " -type" , findType , " -name" , findName }
7070
7171 attempts := 3
7272 attempt := 0
@@ -111,7 +111,7 @@ func DownloadFromK8s(iClient interface{}, path string) ([]byte, error) {
111111 return nil , err
112112 }
113113 namespace , podName , containerName , pathToCopy := initK8sVariables (pSplit )
114- command := fmt . Sprintf ( "cat %s " , pathToCopy )
114+ command := [] string { "cat" , pathToCopy }
115115
116116 attempts := 3
117117 attempt := 0
@@ -154,7 +154,7 @@ func UploadToK8s(iClient interface{}, toPath, fromPath string, buffer []byte) er
154154 for attempt < attempts {
155155 attempt ++
156156 dir , _ := filepath .Split (pathToCopy )
157- command := fmt . Sprintf ( "mkdir -p %s " , dir )
157+ command := [] string { "mkdir" , "-p " , dir }
158158 _ , stderr , err := Exec (client , namespace , podName , containerName , command , nil )
159159
160160 if len (stderr ) != 0 {
@@ -173,24 +173,25 @@ func UploadToK8s(iClient interface{}, toPath, fromPath string, buffer []byte) er
173173 }
174174
175175 chunkSize := 16777215
176+ command = []string {"dd" , "if=/dev/stdin" , "of=" + pathToCopy }
176177
177- command = fmt . Sprintf ( "dd if=/dev/stdin of=%s" , pathToCopy )
178+ // Implement upload using chunks
178179 for i := 0 ; i < len (buffer ); i += chunkSize {
179180 end := i + chunkSize
180181 if end > len (buffer ) {
181182 end = len (buffer )
182183 }
183184 stdin := bytes .NewReader (buffer [i :end ])
184- _ , _ , err = Exec (client , namespace , podName , containerName , command , stdin )
185- command = fmt . Sprintf ( "dd if=/dev/stdin of=%s oflag=append conv=notrunc" , pathToCopy )
186-
187- // if len(stderr) != 0 {
188- // if attempt == attempts {
189- // return fmt.Errorf("STDERR: " + (string)(stderr))
190- // }
191- // utils.Sleep(attempt)
192- // continue
193- // }
185+ _ , stderr , err = Exec (client , namespace , podName , containerName , command , stdin )
186+ command = [] string { "dd" , " if=/dev/stdin" , " of=" + pathToCopy , " oflag=append" , " conv=notrunc"}
187+
188+ if len (stderr ) != 0 {
189+ if attempt == attempts {
190+ return fmt .Errorf ("STDERR: " + (string )(stderr ))
191+ }
192+ utils .Sleep (attempt )
193+ continue
194+ }
194195 if err != nil {
195196 if attempt == attempts {
196197 return err
@@ -206,7 +207,7 @@ func UploadToK8s(iClient interface{}, toPath, fromPath string, buffer []byte) er
206207}
207208
208209// Exec executes a command in a given container
209- func Exec (client K8sClient , namespace , podName , containerName , command string , stdin io.Reader ) ([]byte , []byte , error ) {
210+ func Exec (client K8sClient , namespace , podName , containerName string , command [] string , stdin io.Reader ) ([]byte , []byte , error ) {
210211 clientset , config := client .ClientSet , client .Config
211212
212213 req := clientset .Core ().RESTClient ().Post ().
@@ -221,7 +222,7 @@ func Exec(client K8sClient, namespace, podName, containerName, command string, s
221222
222223 parameterCodec := runtime .NewParameterCodec (scheme )
223224 req .VersionedParams (& core_v1.PodExecOptions {
224- Command : strings . Fields ( command ) ,
225+ Command : command ,
225226 Container : containerName ,
226227 Stdin : stdin != nil ,
227228 Stdout : true ,
0 commit comments