Skip to content

Commit 17bfa3e

Browse files
author
Priya Wadhwa
committed
Save synced dirs in memory
Save synced dirs in memory so that `kubectl exec` is only called when a new directory may need to be created in the container.
1 parent 6619dcf commit 17bfa3e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pkg/skaffold/sync/kubectl/kubectl.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import (
3131

3232
type Syncer struct{}
3333

34+
var syncedDirs map[string]struct{}
35+
3436
func (k *Syncer) Sync(ctx context.Context, s *sync.Item) error {
3537
logrus.Infoln("Copying files:", s.Copy, "to", s.Image)
3638

@@ -54,7 +56,11 @@ func deleteFileFn(ctx context.Context, pod v1.Pod, container v1.Container, src,
5456

5557
func copyFileFn(ctx context.Context, pod v1.Pod, container v1.Container, src, dst string) []*exec.Cmd {
5658
dir := filepath.Dir(dst)
57-
makeDir := exec.CommandContext(ctx, "kubectl", "exec", pod.Name, "-c", container.Name, "-n", pod.Namespace, "--", "mkdir", "-p", dir)
59+
var cmds []*exec.Cmd
60+
if _, ok := syncedDirs[dir]; !ok {
61+
cmds = []*exec.Cmd{exec.CommandContext(ctx, "kubectl", "exec", pod.Name, "-c", container.Name, "-n", pod.Namespace, "--", "mkdir", "-p", dir)}
62+
syncedDirs[dir] = struct{}{}
63+
}
5864
copy := exec.CommandContext(ctx, "kubectl", "cp", src, fmt.Sprintf("%s/%s:%s", pod.Namespace, pod.Name, dst), "-c", container.Name)
59-
return []*exec.Cmd{makeDir, copy}
65+
return append(cmds, copy)
6066
}

0 commit comments

Comments
 (0)