Commit 02ccb33b authored by Charlie Getzen's avatar Charlie Getzen

use WaitGroup instead of channels and counters

Signed-off-by: 's avatarCharlie Getzen <charlie.getzen@procore.com>
parent 8dd89867
...@@ -26,6 +26,7 @@ import ( ...@@ -26,6 +26,7 @@ import (
"log" "log"
"sort" "sort"
"strings" "strings"
"sync"
"time" "time"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
...@@ -563,27 +564,18 @@ func perform(infos Result, fn ResourceActorFunc) error { ...@@ -563,27 +564,18 @@ func perform(infos Result, fn ResourceActorFunc) error {
} }
func batchPerform(infos Result, fn ResourceActorFunc, errs chan<- error) { func batchPerform(infos Result, fn ResourceActorFunc, errs chan<- error) {
if len(infos) == 0 { var kind string
return var wg sync.WaitGroup
}
finished := make(chan bool, 10000)
kind := infos[0].Object.GetObjectKind().GroupVersionKind().Kind
counter := 0
for _, info := range infos { for _, info := range infos {
currentKind := info.Object.GetObjectKind().GroupVersionKind().Kind currentKind := info.Object.GetObjectKind().GroupVersionKind().Kind
if kind != currentKind { if kind != currentKind {
// Wait until the previous kind has finished wg.Wait()
for i := 0; i < counter; i++ {
<-finished
}
counter = 0
kind = currentKind kind = currentKind
} }
counter = counter + 1 wg.Add(1)
go func(i *resource.Info) { go func(i *resource.Info) {
errs <- fn(i) errs <- fn(i)
finished <- true wg.Done()
}(info) }(info)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment