Skip to content

Commit

Permalink
[Controller] add pod_group_type
Browse files Browse the repository at this point in the history
  • Loading branch information
jin-xiaofeng authored and SongZhen0704 committed Oct 9, 2023
1 parent ed3c56c commit 687fcd8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
9 changes: 5 additions & 4 deletions cli/ctl/trisolaris_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,13 @@ 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 "
buffer.WriteString(fmt.Sprintf(format, data.GetId(), Uint64ToMac(data.GetMac()), data.GetEpcId(),
data.GetDeviceType(), data.GetDeviceId(), data.GetIfType(),
"PodNsId: %d, PodId: %d, PodClusterId: %d, PodGroupType: %d, NetnsId: %d, VtapId: %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.GetNetnsId(), data.GetVtapId(), data.GetIsVipInterface()))
data.GetPodClusterId(), data.GetPodGroupType(), data.GetNetnsId(),
data.GetVtapId(), data.GetIsVipInterface()))
if data.GetPodNodeId() > 0 {
buffer.WriteString(fmt.Sprintf("PodNodeId: %d ", data.GetPodNodeId()))
}
Expand Down
2 changes: 1 addition & 1 deletion cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/bitly/go-simplejson v0.5.0
github.com/deepflowio/deepflow/message v0.0.0-20230921071410-d9231da35d71
github.com/deepflowio/deepflow/message v0.0.0-20231008013346-043a0bf37f0a
github.com/deepflowio/deepflow/server v0.0.0-20230921075115-a012150912b2
github.com/golang/protobuf v1.5.3
github.com/mattn/go-runewidth v0.0.14
Expand Down
4 changes: 2 additions & 2 deletions cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,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-20230921071410-d9231da35d71 h1:lkJBAEx8uk5PwVmosZZsyawBMFaw3gg7Dijys57Tr9Y=
github.com/deepflowio/deepflow/message v0.0.0-20230921071410-d9231da35d71/go.mod h1:e+1lUMMlycCvFRKvlwt/y/0vxJnF8wVss3GyR1ARXY0=
github.com/deepflowio/deepflow/message v0.0.0-20231008013346-043a0bf37f0a h1:Ae6wZ9ZYTk12hxArLO/fcwgU7F1OJgnJYt7J/VM1n3c=
github.com/deepflowio/deepflow/message v0.0.0-20231008013346-043a0bf37f0a/go.mod h1:e+1lUMMlycCvFRKvlwt/y/0vxJnF8wVss3GyR1ARXY0=
github.com/deepflowio/deepflow/server v0.0.0-20230921075115-a012150912b2 h1:NaXvNkYkzcsAQjAK04DgrpBT1px3O3pXy9u4cLgrGfQ=
github.com/deepflowio/deepflow/server v0.0.0-20230921075115-a012150912b2/go.mod h1:A1jZv5tsLQvzE2ii/A2+DPjWLAJ0AvYZ+NbmzgvUBvU=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
Expand Down
36 changes: 36 additions & 0 deletions server/controller/trisolaris/metadata/raw_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ 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),
POD_GROUP_CLONESET: uint32(trident.AutoServiceType_AUTO_SERVICE_TYPE_POD_GROUP_CLONESET),
}

type TypeIDData struct {
LaunchServer string
LaunchServerID int
Expand Down Expand Up @@ -97,6 +106,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
Expand Down Expand Up @@ -126,6 +136,7 @@ type PlatformRawData struct {
idToPodNode map[int]*models.PodNode
idToPod map[int]*models.Pod
idToPodService map[int]*models.PodService
idToPodGroup map[int]*models.PodGroup

vmIDToVifs map[int]mapset.Set
vRouterIDToVifs map[int]mapset.Set
Expand Down Expand Up @@ -169,6 +180,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(),
Expand Down Expand Up @@ -208,6 +220,7 @@ func NewPlatformRawData() *PlatformRawData {
idToPodNode: make(map[int]*models.PodNode),
idToPod: make(map[int]*models.Pod),
idToPodService: make(map[int]*models.PodService),
idToPodGroup: make(map[int]*models.PodGroup),

vmIDToVifs: make(map[int]mapset.Set),
vRouterIDToVifs: make(map[int]mapset.Set),
Expand Down Expand Up @@ -715,6 +728,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 {
Expand Down Expand Up @@ -1095,6 +1119,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)
Expand Down Expand Up @@ -1165,6 +1190,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),
Expand All @@ -1185,6 +1215,7 @@ func (r *PlatformRawData) vInterfaceToProto(
IsVipInterface: proto.Bool(ipResourceData.isVipInterface),
NetnsId: proto.Uint32(vif.NetnsID),
VtapId: proto.Uint32(vif.VtapID),
PodGroupType: proto.Uint32(podGroupType),
}
sInterface := &trident.Interface{
Id: proto.Uint32(uint32(vif.ID)),
Expand Down Expand Up @@ -1465,6 +1496,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
Expand Down
2 changes: 1 addition & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/cornelk/hashmap v1.0.8
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-20230926080708-7bbcc933c60b
github.com/deepflowio/deepflow/message v0.0.0-20231008013346-043a0bf37f0a
github.com/deepflowio/deepflow/server/controller/cloud/kubernetes_gather/expand v0.0.0-00010101000000-000000000000
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
Expand Down
4 changes: 2 additions & 2 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,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-20230926080708-7bbcc933c60b h1:sudQZN37UiAKis3YZ5Nn2gRPHNlFt3JADRD5iLI0YOM=
github.com/deepflowio/deepflow/message v0.0.0-20230926080708-7bbcc933c60b/go.mod h1:e+1lUMMlycCvFRKvlwt/y/0vxJnF8wVss3GyR1ARXY0=
github.com/deepflowio/deepflow/message v0.0.0-20231008013346-043a0bf37f0a h1:Ae6wZ9ZYTk12hxArLO/fcwgU7F1OJgnJYt7J/VM1n3c=
github.com/deepflowio/deepflow/message v0.0.0-20231008013346-043a0bf37f0a/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=
Expand Down

0 comments on commit 687fcd8

Please sign in to comment.