From 02ccb33bdcf218cd2937e9d06ebaa25009394c86 Mon Sep 17 00:00:00 2001 From: Charlie Getzen Date: Thu, 3 Oct 2019 12:00:53 -0700 Subject: [PATCH] use WaitGroup instead of channels and counters Signed-off-by: Charlie Getzen --- pkg/kube/client.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 222c6b331..a9bfee163 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -26,6 +26,7 @@ import ( "log" "sort" "strings" + "sync" "time" "k8s.io/apimachinery/pkg/api/meta" @@ -563,27 +564,18 @@ func perform(infos Result, fn ResourceActorFunc) error { } func batchPerform(infos Result, fn ResourceActorFunc, errs chan<- error) { - if len(infos) == 0 { - return - } - - finished := make(chan bool, 10000) - kind := infos[0].Object.GetObjectKind().GroupVersionKind().Kind - counter := 0 + var kind string + var wg sync.WaitGroup for _, info := range infos { currentKind := info.Object.GetObjectKind().GroupVersionKind().Kind if kind != currentKind { - // Wait until the previous kind has finished - for i := 0; i < counter; i++ { - <-finished - } - counter = 0 + wg.Wait() kind = currentKind } - counter = counter + 1 + wg.Add(1) go func(i *resource.Info) { errs <- fn(i) - finished <- true + wg.Done() }(info) } }