File tree 2 files changed +13
-21
lines changed
2 files changed +13
-21
lines changed Original file line number Diff line number Diff line change 15
15
package handler
16
16
17
17
import (
18
+ "github.com/gin-gonic/gin"
18
19
"github.com/xiaomi/naftis/src/api/bootstrap"
19
20
"github.com/xiaomi/naftis/src/api/service"
20
21
"github.com/xiaomi/naftis/src/api/util"
21
-
22
- "github.com/gin-gonic/gin"
23
22
)
24
23
25
24
// Services returns all available services.
Original file line number Diff line number Diff line change @@ -352,39 +352,32 @@ func (k *kubeInfo) sync() {
352
352
353
353
// get services' and pods' data from Kubernetes
354
354
var serviceCh = make (chan service , 200 )
355
- var podCh = make (chan v1.Pod , 100 )
356
-
357
355
k .wg .Add (len (svcs .Items ))
358
356
for _ , i := range svcs .Items {
359
357
go func (i v1.Service ) {
360
358
s := service {}
361
359
s .Service = i
362
360
s .Pods = k .podsFromK8S (i .Spec .Selector )
363
- for _ , p := range s .Pods {
364
- podCh <- p
365
- }
366
361
serviceCh <- s
367
- k .wg .Done ()
368
362
}(i )
369
363
}
370
- go func () {
371
- k .wg .Wait ()
372
- close (serviceCh )
373
- close (podCh )
374
- }()
375
364
376
365
services := make ([]service , 0 , len (svcs .Items ))
377
- for s := range serviceCh {
378
- services = append (services , s )
379
- }
380
-
381
366
tmpPods := make (map [string ]v1.Pod )
382
367
pods := make (pods , 0 )
383
- for p := range podCh {
384
- if _ , ok := tmpPods [string (p .UID )]; ! ok {
385
- pods = append (pods , p )
368
+ go func () {
369
+ for s := range serviceCh {
370
+ services = append (services , s )
371
+ for _ , p := range s .Pods {
372
+ if _ , ok := tmpPods [string (p .UID )]; ! ok {
373
+ pods = append (pods , p )
374
+ }
375
+ }
376
+ k .wg .Done ()
386
377
}
387
- }
378
+ }()
379
+ k .wg .Wait ()
380
+ close (serviceCh )
388
381
389
382
k .mtx .Lock ()
390
383
k .services = services
You can’t perform that action at this time.
0 commit comments