@@ -31,6 +31,8 @@ import (
31
31
32
32
type Syncer struct {}
33
33
34
+ var syncedDirs map [string ]struct {}
35
+
34
36
func (k * Syncer ) Sync (ctx context.Context , s * sync.Item ) error {
35
37
logrus .Infoln ("Copying files:" , s .Copy , "to" , s .Image )
36
38
@@ -54,7 +56,11 @@ func deleteFileFn(ctx context.Context, pod v1.Pod, container v1.Container, src,
54
56
55
57
func copyFileFn (ctx context.Context , pod v1.Pod , container v1.Container , src , dst string ) []* exec.Cmd {
56
58
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
+ }
58
64
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 )
60
66
}
0 commit comments