Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use goroutine for sync #2378

Merged
merged 1 commit into from
Jul 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/skaffold/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/bmatcuk/doublestar"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -150,6 +151,7 @@ func matchSyncRules(syncRules []*latest.SyncRule, relPath, containerWd string) (
}

func Perform(ctx context.Context, image string, files syncMap, cmdFn func(context.Context, v1.Pod, v1.Container, map[string][]string) []*exec.Cmd, namespaces []string) error {
errs, ctx := errgroup.WithContext(ctx)
if len(files) == 0 {
return nil
}
Expand All @@ -174,9 +176,10 @@ func Perform(ctx context.Context, image string, files syncMap, cmdFn func(contex

cmds := cmdFn(ctx, p, c, files)
for _, cmd := range cmds {
if _, err := util.RunCmdOut(cmd); err != nil {
errs.Go(func() error {
_, err := util.RunCmdOut(cmd)
return err
}
})
numSynced++
}
}
Expand All @@ -187,5 +190,5 @@ func Perform(ctx context.Context, image string, files syncMap, cmdFn func(contex
return errors.New("didn't sync any files")
}

return nil
return errs.Wait()
}