1717package kubernetes_gather
1818
1919import (
20+ "errors"
2021 "regexp"
2122 "strings"
2223 "time"
@@ -33,6 +34,7 @@ import (
3334 "github.com/deepflowio/deepflow/server/controller/db/metadb"
3435 metadbmodel "github.com/deepflowio/deepflow/server/controller/db/metadb/model"
3536 "github.com/deepflowio/deepflow/server/controller/genesis"
37+ cmodel "github.com/deepflowio/deepflow/server/controller/model"
3638 "github.com/deepflowio/deepflow/server/controller/statsd"
3739 "github.com/deepflowio/deepflow/server/libs/logger"
3840)
@@ -63,6 +65,7 @@ type KubernetesGather struct {
6365 podGroupLcuuids mapset.Set
6466 podNetworkLcuuidCIDRs networkLcuuidCIDRs
6567 nodeNetworkLcuuidCIDRs networkLcuuidCIDRs
68+ vinterfaceData []cmodel.GenesisVinterface
6669 podIPToLcuuid map [string ]string
6770 nodeIPToLcuuid map [string ]string
6871 namespaceToLcuuid map [string ]string
@@ -96,6 +99,10 @@ func NewKubernetesGather(db *metadb.DB, domain *metadbmodel.Domain, subDomain *m
9699 var err error
97100
98101 domainConfigJson , err = simplejson .NewJson ([]byte (domain .Config ))
102+ if err != nil {
103+ log .Error (err , logger .NewORGPrefix (db .ORGID ))
104+ return nil
105+ }
99106 portNameRegex := domainConfigJson .Get ("node_port_name_regex" ).MustString ()
100107 if portNameRegex == "" {
101108 portNameRegex = common .DEFAULT_PORT_NAME_REGEX
@@ -202,6 +209,7 @@ func NewKubernetesGather(db *metadb.DB, domain *metadbmodel.Domain, subDomain *m
202209 customTagLenMax : cfg .CustomTagLenMax ,
203210 isSubDomain : isSubDomain ,
204211 podGroupLcuuids : mapset .NewSet (),
212+ vinterfaceData : []cmodel.GenesisVinterface {},
205213 nodeNetworkLcuuidCIDRs : networkLcuuidCIDRs {},
206214 podNetworkLcuuidCIDRs : networkLcuuidCIDRs {},
207215 podIPToLcuuid : map [string ]string {},
@@ -277,7 +285,7 @@ func (k *KubernetesGather) pgSpecGenerateConnections(nsName, pgName, pgLcuuid st
277285 if ! ok {
278286 continue
279287 }
280- cmName := ref .Get ("Name " ).MustString ()
288+ cmName := ref .Get ("name " ).MustString ()
281289 cmLcuuid , ok := k .configMapToLcuuid [[2 ]string {nsName , cmName }]
282290 if ! ok {
283291 log .Infof ("pod group (%s) imported env config map (%s) not found" , pgName , cmName , logger .NewORGPrefix (k .orgID ))
@@ -328,6 +336,7 @@ func (k *KubernetesGather) GetKubernetesGatherData() (model.KubernetesGatherReso
328336 // 任务循环的是同一个实例,所以这里要对关联关系进行初始化
329337 k .azLcuuid = ""
330338 k .k8sEntries = nil
339+ k .vinterfaceData = []cmodel.GenesisVinterface {}
331340 k .podNetworkLcuuidCIDRs = networkLcuuidCIDRs {}
332341 k .nodeNetworkLcuuidCIDRs = networkLcuuidCIDRs {}
333342 k .podGroupLcuuids = mapset .NewSet ()
@@ -345,6 +354,39 @@ func (k *KubernetesGather) GetKubernetesGatherData() (model.KubernetesGatherReso
345354 k .nsServiceNameToService = map [string ]map [string ]map [string ]int {}
346355 k .cloudStatsd = statsd .NewCloudStatsd ()
347356
357+ if genesis .GenesisService == nil {
358+ errMsg := "genesis service is nil"
359+ log .Warning (errMsg , logger .NewORGPrefix (k .orgID ))
360+ return model.KubernetesGatherResource {
361+ ErrorState : common .RESOURCE_STATE_CODE_EXIT ,
362+ ErrorMessage : errMsg ,
363+ }, errors .New (errMsg )
364+ }
365+
366+ k8sEntries , err := k .getKubernetesEntries ()
367+ if err != nil {
368+ log .Warning (err .Error (), logger .NewORGPrefix (k .orgID ))
369+ return model.KubernetesGatherResource {
370+ ErrorState : common .RESOURCE_STATE_CODE_WARNING ,
371+ ErrorMessage : err .Error (),
372+ }, err
373+ }
374+ k .k8sEntries = k8sEntries
375+
376+ gsData , err := genesis .GenesisService .GetGenesisSyncResponse (k .orgID )
377+ if err != nil {
378+ return model.KubernetesGatherResource {
379+ ErrorState : common .RESOURCE_STATE_CODE_EXIT ,
380+ ErrorMessage : err .Error (),
381+ }, err
382+ }
383+ for _ , v := range gsData .Vinterfaces {
384+ if v .KubernetesClusterID != k .ClusterID {
385+ continue
386+ }
387+ k .vinterfaceData = append (k .vinterfaceData , v )
388+ }
389+
348390 region , err := k .getRegion ()
349391 if err != nil {
350392 return model.KubernetesGatherResource {}, err
@@ -368,15 +410,6 @@ func (k *KubernetesGather) GetKubernetesGatherData() (model.KubernetesGatherReso
368410 }, err
369411 }
370412
371- k .k8sEntries , err = k .getKubernetesEntries ()
372- if err != nil {
373- log .Warning (err .Error (), logger .NewORGPrefix (k .orgID ))
374- return model.KubernetesGatherResource {
375- ErrorState : common .RESOURCE_STATE_CODE_WARNING ,
376- ErrorMessage : err .Error (),
377- }, err
378- }
379-
380413 podCluster , err := k .getPodCluster ()
381414 if err != nil {
382415 return model.KubernetesGatherResource {}, err
0 commit comments