MCPcopy Create free account
hub / github.com/deepflowio/deepflow / runKubernetesGatherTask

Method runKubernetesGatherTask

server/controller/cloud/cloud.go:450–558  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

448}
449
450func (c *Cloud) runKubernetesGatherTask() {
451 var domain metadbmodel.Domain
452 err := c.db.DB.Where("lcuuid = ?", c.basicInfo.Lcuuid).First(&domain).Error
453 if err != nil {
454 log.Errorf("get domain (%s) failed: %s", c.basicInfo.Name, err.Error(), logger.NewORGPrefix(c.orgID))
455 return
456 }
457
458 if c.basicInfo.Type == common.KUBERNETES {
459 // Kubernetes平台,只会有一个KubernetesGatherTask
460 // - 如果已存在KubernetesGatherTask,则无需启动新的Task
461 // Kubernetes平台,无需考虑KubernetesGatherTask的更新/删除,会在Cloud层面统一处理
462 if len(c.kubernetesGatherTaskMap) != 0 {
463 return
464 }
465 kubernetesGatherTask := NewKubernetesGatherTask(c.cCtx, c.db, &domain, nil, c.cfg, false)
466 if kubernetesGatherTask == nil {
467 return
468 }
469 c.mutex.Lock()
470 c.kubernetesGatherTaskMap[domain.Lcuuid] = kubernetesGatherTask
471 c.kubernetesGatherTaskMap[domain.Lcuuid].Start(c.domainRefreshSignal)
472 c.mutex.Unlock()
473
474 } else {
475 // 附属容器集群的处理
476 var subDomains []metadbmodel.SubDomain
477 var oldSubDomains = mapset.NewSet()
478 var newSubDomains = mapset.NewSet()
479 var delSubDomains = mapset.NewSet()
480 var addSubDomains = mapset.NewSet()
481 var intersectSubDomains = mapset.NewSet()
482
483 for lcuuid := range c.kubernetesGatherTaskMap {
484 oldSubDomains.Add(lcuuid)
485 }
486
487 c.db.DB.Where(map[string]interface{}{"domain": c.basicInfo.Lcuuid}).Where(
488 "enabled = ? AND state != ?",
489 common.DOMAIN_ENABLED_TRUE, common.RESOURCE_STATE_CODE_NO_LICENSE,
490 ).Find(&subDomains)
491 lcuuidToSubDomain := make(map[string]*metadbmodel.SubDomain)
492 for index, subDomain := range subDomains {
493 lcuuidToSubDomain[subDomain.Lcuuid] = &subDomains[index]
494 newSubDomains.Add(subDomain.Lcuuid)
495 }
496
497 // 对于删除的subDomain,停止Task,并移除管理
498 delSubDomains = oldSubDomains.Difference(newSubDomains)
499 for _, subDomain := range delSubDomains.ToSlice() {
500 lcuuid := subDomain.(string)
501 c.kubernetesGatherTaskMap[lcuuid].Stop()
502 c.mutex.Lock()
503 delete(c.kubernetesGatherTaskMap, lcuuid)
504 c.mutex.Unlock()
505 kGatherQueue, ok := c.subDomainRefreshSignals.Get(lcuuid)
506 if ok {
507 kGatherQueue.Close()

Callers 1

Calls 13

NewKubernetesGatherTaskFunction · 0.85
ErrorMethod · 0.65
StartMethod · 0.65
StopMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.65
ErrorfMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45
AddMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected