Skip to content

Commit

Permalink
[Server] support pod update pod_group_id
Browse files Browse the repository at this point in the history
  • Loading branch information
roryye committed Aug 21, 2023
1 parent 9b9555a commit 0420c10
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
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-20230817060816-3afabb00f81d
github.com/deepflowio/deepflow/message v0.0.0-20230821033337-4663bbf77a09
github.com/deepflowio/deepflow/server v0.0.0-20230815065845-7ac50b3813a0
github.com/golang/protobuf v1.5.2
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-20230817060816-3afabb00f81d h1:tN6goO31muH5vHstnJudlxMrx2RKiC2vA75teuYenko=
github.com/deepflowio/deepflow/message v0.0.0-20230817060816-3afabb00f81d/go.mod h1:e+1lUMMlycCvFRKvlwt/y/0vxJnF8wVss3GyR1ARXY0=
github.com/deepflowio/deepflow/message v0.0.0-20230821033337-4663bbf77a09 h1:dbzcL76KK8UatqGSLaU8ZtiAWkSlwvysjsf3+FzX9FY=
github.com/deepflowio/deepflow/message v0.0.0-20230821033337-4663bbf77a09/go.mod h1:e+1lUMMlycCvFRKvlwt/y/0vxJnF8wVss3GyR1ARXY0=
github.com/deepflowio/deepflow/server v0.0.0-20230815065845-7ac50b3813a0 h1:Od5pJCiQm8Kx/SFfFZ0/23szh5kUxgMlxD+lmxZoV+I=
github.com/deepflowio/deepflow/server v0.0.0-20230815065845-7ac50b3813a0/go.mod h1:b+6fxzwFrdgNGxYt/lvGkerQhSBNoPHbyOoBtci/GSY=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
Expand Down
7 changes: 7 additions & 0 deletions server/controller/recorder/cache/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func (b *DiffBaseDataSet) addPod(dbItem *mysql.Pod, seq int, toolDataSet *ToolDa
if dbItem.PodReplicaSetID != 0 {
podReplicaSetLcuuid, _ = toolDataSet.GetPodReplicaSetLcuuidByID(dbItem.PodReplicaSetID)
}
var podGroupLcuuid string
if dbItem.PodGroupID != 0 {
podGroupLcuuid, _ = toolDataSet.GetPodGroupLcuuidByID(dbItem.PodGroupID)
}
vpcLcuuid, _ := toolDataSet.GetVPCLcuuidByID(dbItem.VPCID)
b.Pods[dbItem.Lcuuid] = &Pod{
DiffBase: DiffBase{
Expand All @@ -45,6 +49,7 @@ func (b *DiffBaseDataSet) addPod(dbItem *mysql.Pod, seq int, toolDataSet *ToolDa
CreatedAt: dbItem.CreatedAt,
PodNodeLcuuid: podNodeLcuuid,
PodReplicaSetLcuuid: podReplicaSetLcuuid,
PodGroupLcuuid: podGroupLcuuid,
VPCLcuuid: vpcLcuuid,
RegionLcuuid: dbItem.Region,
AZLcuuid: dbItem.AZ,
Expand All @@ -69,6 +74,7 @@ type Pod struct {
CreatedAt time.Time `json:"created_at"`
PodNodeLcuuid string `json:"pod_node_lcuuid"`
PodReplicaSetLcuuid string `json:"pod_replica_set_lcuuid"`
PodGroupLcuuid string `json:"pod_group_lcuuid"`
VPCLcuuid string `json:"vpc_lcuuid"`
RegionLcuuid string `json:"region_lcuuid"`
AZLcuuid string `json:"az_lcuuid"`
Expand All @@ -85,6 +91,7 @@ func (p *Pod) Update(cloudItem *cloudmodel.Pod) {
p.CreatedAt = cloudItem.CreatedAt
p.PodNodeLcuuid = cloudItem.PodNodeLcuuid
p.PodReplicaSetLcuuid = cloudItem.PodReplicaSetLcuuid
p.PodGroupLcuuid = cloudItem.PodGroupLcuuid
p.VPCLcuuid = cloudItem.VPCLcuuid
p.RegionLcuuid = cloudItem.RegionLcuuid
p.AZLcuuid = cloudItem.AZLcuuid
Expand Down
22 changes: 22 additions & 0 deletions server/controller/recorder/cache/tool_data_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type ToolDataSet struct {
podServiceLcuuidToID map[string]int

podGroupLcuuidToID map[string]int
podGroupIDToLcuuid map[int]string

podReplicaSetLcuuidToID map[string]int
podReplicaSetIDToLcuuid map[int]string
Expand Down Expand Up @@ -179,6 +180,7 @@ func NewToolDataSet() ToolDataSet {
podServiceLcuuidToID: make(map[string]int),

podGroupLcuuidToID: make(map[string]int),
podGroupIDToLcuuid: make(map[int]string),

podReplicaSetLcuuidToID: make(map[string]int),
podReplicaSetIDToLcuuid: make(map[int]string),
Expand Down Expand Up @@ -915,10 +917,13 @@ func (t *ToolDataSet) deletePodService(lcuuid string) {

func (t *ToolDataSet) addPodGroup(item *mysql.PodGroup) {
t.podGroupLcuuidToID[item.Lcuuid] = item.ID
t.podGroupIDToLcuuid[item.ID] = item.Lcuuid
t.GetLogFunc()(addToToolMap(RESOURCE_TYPE_POD_GROUP_EN, item.Lcuuid))
}

func (t *ToolDataSet) deletePodGroup(lcuuid string) {
id, _ := t.podGroupLcuuidToID[lcuuid]
delete(t.podGroupIDToLcuuid, id)
delete(t.podGroupLcuuidToID, lcuuid)
log.Info(deleteFromToolMap(RESOURCE_TYPE_POD_GROUP_EN, lcuuid))
}
Expand Down Expand Up @@ -1640,6 +1645,23 @@ func (t *ToolDataSet) GetPodGroupIDByLcuuid(lcuuid string) (int, bool) {
}
}

func (t *ToolDataSet) GetPodGroupLcuuidByID(id int) (string, bool) {
lcuuid, exists := t.podGroupIDToLcuuid[id]
if exists {
return lcuuid, true
}
log.Warning(cacheLcuuidByIDNotFound(RESOURCE_TYPE_POD_GROUP_EN, id))
var podGroup mysql.PodGroup
result := mysql.Db.Where("id = ?", id).Find(&podGroup)
if result.RowsAffected == 1 {
t.addPodGroup(&podGroup)
return podGroup.Lcuuid, true
} else {
log.Error(dbResourceByIDNotFound(RESOURCE_TYPE_POD_GROUP_EN, id))
return lcuuid, false
}
}

func (t *ToolDataSet) GetPodReplicaSetIDByLcuuid(lcuuid string) (int, bool) {
id, exists := t.podReplicaSetLcuuidToID[lcuuid]
if exists {
Expand Down
11 changes: 11 additions & 0 deletions server/controller/recorder/updater/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ func (p *Pod) generateUpdateInfo(diffBase *cache.Pod, cloudItem *cloudmodel.Pod)
}
updateInfo["pod_rs_id"] = podReplicaSetID
}
if diffBase.PodGroupLcuuid != cloudItem.PodGroupLcuuid {
podGroupID, exists := p.cache.ToolDataSet.GetPodGroupIDByLcuuid(cloudItem.PodGroupLcuuid)
if !exists {
log.Errorf(resourceAForResourceBNotFound(
common.RESOURCE_TYPE_POD_GROUP_EN, cloudItem.PodGroupLcuuid,
common.RESOURCE_TYPE_POD_EN, cloudItem.Lcuuid,
))
return nil, false
}
updateInfo["pod_group_id"] = podGroupID
}
if diffBase.Name != cloudItem.Name {
updateInfo["name"] = cloudItem.Name
}
Expand Down

0 comments on commit 0420c10

Please sign in to comment.