Skip to content

Commit

Permalink
Merge pull request #90 from silenceper/fix-sync-lock
Browse files Browse the repository at this point in the history
在后台sync namespace、service,尽量减少锁的粒度
  • Loading branch information
sevennt authored Dec 17, 2018
2 parents cffa435 + eee314b commit 5f765a4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/api/service/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,20 @@ func (k *kubeInfo) sync() {
// panic(err.Error())
log.Error("[k8s] get namespaces err", "err", err)
}
k.mtx.Lock()
k.services = make([]service, 0, len(svcs.Items))
services := make([]service, 0, len(svcs.Items))
k.wg.Add(len(svcs.Items))
for _, i := range svcs.Items {
go func(i v1.Service) {
s := service{}
s.Service = i
s.Pods = k.Pods(i.Spec.Selector)
k.services = append(k.services, s)
services = append(services, s)
k.wg.Done()
}(i)
}
k.wg.Wait()
k.mtx.Lock()
k.services = services
k.namespaces = ns.Items
k.mtx.Unlock()

Expand Down

0 comments on commit 5f765a4

Please sign in to comment.