Skip to content

Commit fa87ea5

Browse files
committed
change command from string to []string
1 parent cf97426 commit fa87ea5

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

pkg/skbn/kube.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

pkg/skbn/skbn.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"log"
66
"math"
77
"path/filepath"
8-
"strings"
98

109
"github.com/maorfr/skbn/pkg/utils"
1110
)
@@ -152,11 +151,6 @@ func PerformCopy(srcClient, dstClient interface{}, srcPrefix, dstPrefix string,
152151
currentLinePadded := utils.LeftPad2Len(currentLine, 0, totalDigits)
153152

154153
go func(srcClient, dstClient interface{}, srcPrefix, fromPath, dstPrefix, toPath, currentLinePadded string, totalFiles int) {
155-
if strings.Contains(fromPath, " ") {
156-
bwg.Done()
157-
log.Printf("file [%s/%d] skip: %s", currentLinePadded, totalFiles, fromPath)
158-
return
159-
}
160154
buffer, err := Download(srcClient, srcPrefix, fromPath)
161155
if err != nil {
162156
bwg.Done()

0 commit comments

Comments
 (0)