From e19636075324c3bce644a3ad7baf5d26b9432a72 Mon Sep 17 00:00:00 2001 From: JIN XiaoFeng Date: Wed, 27 Sep 2023 16:05:42 +0800 Subject: [PATCH] [Controller] add pod_group_type --- cli/ctl/trisolaris_check.go | 4 +-- cli/go.mod | 2 +- cli/go.sum | 4 +-- .../trisolaris/metadata/raw_data.go | 35 +++++++++++++++++++ server/go.mod | 2 +- server/go.sum | 4 +-- 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/cli/ctl/trisolaris_check.go b/cli/ctl/trisolaris_check.go index 50e4d381912..4632c989197 100644 --- a/cli/ctl/trisolaris_check.go +++ b/cli/ctl/trisolaris_check.go @@ -257,12 +257,12 @@ func formatString(data *trident.Interface) string { buffer := bytes.Buffer{} format := "Id: %d Mac: %s EpcId: %d DeviceType: %d DeviceId: %d IfType: %d" + " LaunchServer: %s LaunchServerId: %d RegionId: %d AzId: %d, PodGroupId: %d, " + - "PodNsId: %d, PodId: %d, PodClusterId: %d, NetnsId: %d, VtapId: %d, IsVipInterface: %t " + "PodNsId: %d, PodId: %d, PodClusterId: %d, PodGroupType: %d, IsVipInterface: %t " buffer.WriteString(fmt.Sprintf(format, data.GetId(), Uint64ToMac(data.GetMac()), data.GetEpcId(), data.GetDeviceType(), data.GetDeviceId(), data.GetIfType(), data.GetLaunchServer(), data.GetLaunchServerId(), data.GetRegionId(), data.GetAzId(), data.GetPodGroupId(), data.GetPodNsId(), data.GetPodId(), - data.GetPodClusterId(), data.GetIsVipInterface())) + data.GetPodClusterId(), data.GetPodGroupType(), data.GetIsVipInterface())) if data.GetPodNodeId() > 0 { buffer.WriteString(fmt.Sprintf("PodNodeId: %d ", data.GetPodNodeId())) } diff --git a/cli/go.mod b/cli/go.mod index 93a0dda12cd..b5f120bac32 100644 --- a/cli/go.mod +++ b/cli/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/bitly/go-simplejson v0.5.0 - github.com/deepflowio/deepflow/message v0.0.0-20230818083014-9c0740ae7cc8 + github.com/deepflowio/deepflow/message v0.0.0-20231008013903-d0394ae13f57 github.com/deepflowio/deepflow/server v0.0.0-20230215120846-d4b50f72597d github.com/ghodss/yaml v1.0.0 github.com/golang/protobuf v1.5.2 diff --git a/cli/go.sum b/cli/go.sum index bfaa2e3221f..dfd74011f6b 100644 --- a/cli/go.sum +++ b/cli/go.sum @@ -88,8 +88,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deepflowio/deepflow/message v0.0.0-20230818083014-9c0740ae7cc8 h1:P4M8KqtX+SNazJ6LZTpQsHXTHQOpIfZZBNosq7fS6JQ= -github.com/deepflowio/deepflow/message v0.0.0-20230818083014-9c0740ae7cc8/go.mod h1:e+1lUMMlycCvFRKvlwt/y/0vxJnF8wVss3GyR1ARXY0= +github.com/deepflowio/deepflow/message v0.0.0-20231008013903-d0394ae13f57 h1:Jz4dZtzF32jq6smaiLBZc3hdYnmsv7jZIAIWJbjTUh0= +github.com/deepflowio/deepflow/message v0.0.0-20231008013903-d0394ae13f57/go.mod h1:e+1lUMMlycCvFRKvlwt/y/0vxJnF8wVss3GyR1ARXY0= github.com/deepflowio/deepflow/server v0.0.0-20230215120846-d4b50f72597d h1:mNkEWaK6IsZgzXATGOquVnl6EFIDnoAO1YP+0BomUHE= github.com/deepflowio/deepflow/server v0.0.0-20230215120846-d4b50f72597d/go.mod h1:LRviMJ1kGzHOixRz5cteI2BnaxbuSQhmQvexguo9P+s= github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= diff --git a/server/controller/trisolaris/metadata/raw_data.go b/server/controller/trisolaris/metadata/raw_data.go index 295a145c6e6..1946341cccf 100644 --- a/server/controller/trisolaris/metadata/raw_data.go +++ b/server/controller/trisolaris/metadata/raw_data.go @@ -30,6 +30,14 @@ import ( . "github.com/deepflowio/deepflow/server/controller/trisolaris/utils" ) +var PodGroupTypeMap = map[int]uint32{ + POD_GROUP_DEPLOYMENT: uint32(trident.AutoServiceType_AUTO_SERVICE_TYPE_POD_GROUP_DEPLOYMENT), + POD_GROUP_STATEFULSET: uint32(trident.AutoServiceType_AUTO_SERVICE_TYPE_POD_GROUP_STATEFULSET), + POD_GROUP_RC: uint32(trident.AutoServiceType_AUTO_SERVICE_TYPE_POD_GROUP_RC), + POD_GROUP_DAEMON_SET: uint32(trident.AutoServiceType_AUTO_SERVICE_TYPE_POD_GROUP_DAEMON_SET), + POD_GROUP_REPLICASET_CONTROLLER: uint32(trident.AutoServiceType_AUTO_SERVICE_TYPE_POD_GROUP_REPLICASET_CONTROLLER), +} + type TypeIDData struct { LaunchServer string LaunchServerID int @@ -97,6 +105,7 @@ type PlatformRawData struct { peerConnIDs mapset.Set cenIDs mapset.Set podServiceIDs mapset.Set + podGroupIDs mapset.Set redisInstanceIDs mapset.Set rdsInstanceIDs mapset.Set podNodeIDs mapset.Set @@ -119,6 +128,7 @@ type PlatformRawData struct { podServiceIDToPorts map[int][]*models.PodServicePort idToPodNode map[int]*models.PodNode idToPodService map[int]*models.PodService + idToPodGroup map[int]*models.PodGroup vmIDToVifs map[int]mapset.Set vRouterIDToVifs map[int]mapset.Set @@ -162,6 +172,7 @@ func NewPlatformRawData() *PlatformRawData { peerConnIDs: mapset.NewSet(), cenIDs: mapset.NewSet(), podServiceIDs: mapset.NewSet(), + podGroupIDs: mapset.NewSet(), redisInstanceIDs: mapset.NewSet(), rdsInstanceIDs: mapset.NewSet(), podNodeIDs: mapset.NewSet(), @@ -194,6 +205,7 @@ func NewPlatformRawData() *PlatformRawData { vInterfaceIDToSimpleIP: make(map[int][]*trident.IpResource), idToPodNode: make(map[int]*models.PodNode), idToPodService: make(map[int]*models.PodService), + idToPodGroup: make(map[int]*models.PodGroup), vmIDToVifs: make(map[int]mapset.Set), vRouterIDToVifs: make(map[int]mapset.Set), @@ -700,6 +712,17 @@ func (r *PlatformRawData) ConvertDBPodService(dbDataCache *DBDataCache) { } } +func (r *PlatformRawData) ConvertDBPodGroup(dbDataCache *DBDataCache) { + podGroups := dbDataCache.GetPodGroups() + if podGroups == nil { + return + } + for _, pg := range podGroups { + r.idToPodGroup[pg.ID] = pg + r.podGroupIDs.Add(pg.ID) + } +} + func (r *PlatformRawData) ConvertDBPodServicePort(dbDataCache *DBDataCache) { podServicePorts := dbDataCache.GetPodServicePorts() if podServicePorts == nil { @@ -1037,6 +1060,7 @@ func (r *PlatformRawData) ConvertDBCache(dbDataCache *DBDataCache) { r.ConvertDBPeerConnection(dbDataCache) r.ConvertDBCEN(dbDataCache) r.ConvertDBPodService(dbDataCache) + r.ConvertDBPodGroup(dbDataCache) r.ConvertDBPodServicePort(dbDataCache) r.ConvertDBRedisInstance(dbDataCache) r.ConvertDBRdsInstance(dbDataCache) @@ -1096,6 +1120,11 @@ func (r *PlatformRawData) vInterfaceToProto( if err != nil { log.Error(err, vif.Mac) } + podGroupType := uint32(0) + podGroup := r.idToPodGroup[device.PodGroupID] + if podGroup != nil { + podGroupType = PodGroupTypeMap[podGroup.Type] + } aInterface := &trident.Interface{ Id: proto.Uint32(uint32(vif.ID)), Mac: proto.Uint64(macU64), @@ -1114,6 +1143,7 @@ func (r *PlatformRawData) vInterfaceToProto( PodNodeId: proto.Uint32(uint32(device.PodNodeID)), PodId: proto.Uint32(uint32(device.PodID)), IsVipInterface: proto.Bool(ipResourceData.isVipInterface), + PodGroupType: proto.Uint32(podGroupType), } sInterface := &trident.Interface{ @@ -1387,6 +1417,11 @@ func (r *PlatformRawData) equal(o *PlatformRawData) bool { return false } + if !r.podGroupIDs.Equal(o.podGroupIDs) { + log.Info("platform pod group changed") + return false + } + if !r.redisInstanceIDs.Equal(o.redisInstanceIDs) { log.Info("platform redis instance changed") return false diff --git a/server/go.mod b/server/go.mod index 760eca63171..78c8956a671 100644 --- a/server/go.mod +++ b/server/go.mod @@ -30,7 +30,7 @@ require ( github.com/cactus/go-statsd-client/v5 v5.0.0 github.com/deckarep/golang-set v1.8.0 github.com/deckarep/golang-set/v2 v2.1.0 - github.com/deepflowio/deepflow/message v0.0.0-20230907024218-d3e82c775457 + github.com/deepflowio/deepflow/message v0.0.0-20231008013903-d0394ae13f57 github.com/deepflowio/deepflow/server/controller/cloud/platform v0.0.0-00010101000000-000000000000 github.com/deepflowio/deepflow/server/controller/db/mysql/migrator v0.0.0-00010101000000-000000000000 github.com/deepflowio/deepflow/server/controller/monitor/license v0.0.0-00010101000000-000000000000 diff --git a/server/go.sum b/server/go.sum index 3211680c1b6..f9f515886af 100644 --- a/server/go.sum +++ b/server/go.sum @@ -138,8 +138,8 @@ github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsP github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI= github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= -github.com/deepflowio/deepflow/message v0.0.0-20230907024218-d3e82c775457 h1:JQ8zwSyoJHqsXHkSEk4/H0anWBqPP+rDkxw8LOTh40I= -github.com/deepflowio/deepflow/message v0.0.0-20230907024218-d3e82c775457/go.mod h1:e+1lUMMlycCvFRKvlwt/y/0vxJnF8wVss3GyR1ARXY0= +github.com/deepflowio/deepflow/message v0.0.0-20231008013903-d0394ae13f57 h1:Jz4dZtzF32jq6smaiLBZc3hdYnmsv7jZIAIWJbjTUh0= +github.com/deepflowio/deepflow/message v0.0.0-20231008013903-d0394ae13f57/go.mod h1:e+1lUMMlycCvFRKvlwt/y/0vxJnF8wVss3GyR1ARXY0= github.com/deepflowio/tempopb v0.0.0-20230215110519-15853baf3a79 h1:erRwXyZiUZxxZX/Q1QHesZXgxjiunZUFy+ggCRimkD4= github.com/deepflowio/tempopb v0.0.0-20230215110519-15853baf3a79/go.mod h1:h2rkZ319TExIUGuK8a2dlcGd8qc6wdhsrcpXWaJQaQE= github.com/dennwc/varint v1.0.0 h1:kGNFFSSw8ToIy3obO/kKr8U9GZYUAxQEVuix4zfDWzE=