Skip to content

Commit a2e3ca8

Browse files
ZhengYa-0110SongZhen0704
authored andcommitted
feat: implement business service in trisolaris
1 parent fd477b7 commit a2e3ca8

12 files changed

Lines changed: 123 additions & 37 deletions

File tree

server/controller/common/const.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,12 @@ const CLICK_HOUSE_VERSION = "24"
747747
const TAP_TYPE_VALUE_CLOUD_NETWORK = 3
748748

749749
const (
750-
CUSTOM_SERVICE_TYPE_IP = 1
751-
CUSTOM_SERVICE_TYPE_PORT = 2
750+
CUSTOM_SERVICE_TYPE_IP = 1
751+
CUSTOM_SERVICE_TYPE_PORT = 2
752+
CUSTOM_SERVICE_TYPE_CHOST = 3
753+
CUSTOM_SERVICE_TYPE_POD_SERVICE = 4
754+
CUSTOM_SERVICE_TYPE_POD_GROUP = 5
755+
756+
CUSTOM_SERVICE_MATCH_TYPE_NAME = 1
757+
CUSTOM_SERVICE_MATCH_TYPE_UID = 2
752758
)

server/controller/common/resource_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const (
4848
RESOURCE_TYPE_POD_NODE_EN = "pod_node"
4949
RESOURCE_TYPE_VM_POD_NODE_CONNECTION_EN = "vm_pod_node_connection"
5050
RESOURCE_TYPE_POD_NAMESPACE_EN = "pod_namespace"
51+
RESOURCE_TYPE_POD_NS_EN = "pod_ns" // pod_ns is alias of pod_namespace
5152
RESOURCE_TYPE_POD_INGRESS_EN = "pod_ingress"
5253
RESOURCE_TYPE_POD_INGRESS_RULE_EN = "pod_ingress_rule"
5354
RESOURCE_TYPE_POD_INGRESS_RULE_BACKEND_EN = "pod_ingress_rule_backend"

server/controller/db/mysql/migrator/schema/rawsql/init.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ CREATE TABLE IF NOT EXISTS pod_cluster (
732732
region CHAR(64) DEFAULT '',
733733
sub_domain CHAR(64) DEFAULT '',
734734
domain CHAR(64) DEFAULT '',
735+
uid CHAR(64) DEFAULT '',
735736
lcuuid CHAR(64) DEFAULT '',
736737
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
737738
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@@ -863,6 +864,7 @@ CREATE TABLE IF NOT EXISTS pod_namespace (
863864
region CHAR(64) DEFAULT '',
864865
sub_domain CHAR(64) DEFAULT '',
865866
domain CHAR(64) DEFAULT '',
867+
uid CHAR(64) DEFAULT '',
866868
lcuuid CHAR(64) DEFAULT '',
867869
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
868870
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@@ -2729,7 +2731,7 @@ CREATE TABLE IF NOT EXISTS custom_service (
27292731
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
27302732
name VARCHAR(128) NOT NULL,
27312733
type INTEGER DEFAULT 0 COMMENT '0: unknown 1: IP 2: PORT 3: chost 4: pod_service 5: pod_group',
2732-
match_type INTEGER DEFAULT 0 COMMENT '0: unkonwn 1: name match 2: uid match',
2734+
match_type INTEGER DEFAULT 1 COMMENT '0: unkonwn 1: name match 2: uid match',
27332735
epc_id INTEGER DEFAULT 0,
27342736
pod_cluster_id INTEGER DEFAULT 0,
27352737
pod_namespace_id INTEGER DEFAULT 0,

server/controller/db/mysql/migrator/schema/rawsql/issu/6.6.1.53.sql

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ BEGIN
2424
END IF;
2525
END;
2626

27+
CALL AddColumnIfNotExists('pod_cluster', 'uid', "CHAR(64) DEFAULT ''", 'domain');
28+
CALL AddColumnIfNotExists('pod_namespace', 'uid', "CHAR(64) DEFAULT ''", 'domain');
2729
CALL AddColumnIfNotExists('pod_service', 'uid', "CHAR(64) DEFAULT ''", 'domain');
2830
CALL AddColumnIfNotExists('pod_group', 'uid', "CHAR(64) DEFAULT ''", 'domain');
2931
CALL AddColumnIfNotExists('custom_service', 'match_type', "INTEGER DEFAULT 0 COMMENT '0: unkonwn 1: name match 2: uid match'", 'type');
@@ -33,6 +35,13 @@ CALL AddColumnIfNotExists('custom_service', 'pod_cluster_id', "INTEGER DEFAULT 0
3335
DROP PROCEDURE AddColumnIfNotExists;
3436

3537
ALTER TABLE custom_service MODIFY COLUMN type INTEGER DEFAULT 0 COMMENT '0: unknown 1: IP 2: PORT 3: chost 4: pod_service 5: pod_group';
36-
ALTER TABLE custom_service MODIFY COLUMN match_type INTEGER DEFAULT 0 COMMENT '0: unkonwn 1: name match 2: uid match';
38+
ALTER TABLE custom_service MODIFY COLUMN match_type INTEGER DEFAULT 1 COMMENT '0: unkonwn 1: name match 2: uid match';
39+
40+
UPDATE pod_cluster SET uid = CONCAT('pod_cluster-', UUID_SHORT()) WHERE uid IS NULL OR uid = '';
41+
UPDATE pod_namespace SET uid = CONCAT('pod_ns-', UUID_SHORT()) WHERE uid IS NULL OR uid = '';
42+
UPDATE pod_service SET uid = CONCAT('pod_service-', UUID_SHORT()) WHERE uid IS NULL OR uid = '';
43+
UPDATE pod_group SET uid = CONCAT('pod_group-', UUID_SHORT()) WHERE uid IS NULL OR uid = '';
44+
UPDATE vm SET uid = CONCAT('chost-', UUID_SHORT()) WHERE uid IS NULL OR uid = '';
45+
UPDATE epc SET uid = CONCAT('vpc-', UUID_SHORT()) WHERE uid IS NULL OR uid = '';
3746

3847
UPDATE db_version SET version='6.6.1.53';

server/controller/db/mysql/migrator/schema/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package schema
1818

1919
const (
2020
DB_VERSION_TABLE = "db_version"
21-
DB_VERSION_EXPECTED = "6.6.1.52"
21+
DB_VERSION_EXPECTED = "6.6.1.53"
2222
)
2323

2424
const (

server/controller/db/mysql/model/platform_rsc_model.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ type PodCluster struct {
743743
Region string `gorm:"column:region;type:char(64);default:''" json:"REGION" mapstructure:"REGION"`
744744
SubDomain string `gorm:"column:sub_domain;type:char(64);default:''" json:"SUB_DOMAIN" mapstructure:"SUB_DOMAIN"`
745745
Domain string `gorm:"column:domain;type:char(64);not null" json:"DOMAIN" mapstructure:"DOMAIN"`
746+
UID string `gorm:"column:uid;type:char(64);default:''" json:"UID" mapstructure:"UID"`
746747
}
747748

748749
func (p PodCluster) GetDomainLcuuid() string {
@@ -764,6 +765,7 @@ type PodNamespace struct {
764765
Domain string `gorm:"column:domain;type:char(64);not null" json:"DOMAIN" mapstructure:"DOMAIN"`
765766
LearnedCloudTags map[string]string `gorm:"column:learned_cloud_tags;type:text;default:'';serializer:json" json:"LEARNED_CLOUD_TAGS" mapstructure:"LEARNED_CLOUD_TAGS"`
766767
CustomCloudTags map[string]string `gorm:"column:custom_cloud_tags;type:text;default:'';serializer:json" json:"CUSTOM_CLOUD_TAGS" mapstructure:"CUSTOM_CLOUD_TAGS"`
768+
UID string `gorm:"column:uid;type:char(64);default:''" json:"UID" mapstructure:"UID"`
767769
}
768770

769771
func (p PodNamespace) GetDomainLcuuid() string {
@@ -1085,7 +1087,7 @@ type CustomService struct {
10851087
OperatedTime `gorm:"embedded" mapstructure:",squash"`
10861088
Name string `gorm:"column:name;type:varchar(128);default:''" json:"NAME" mapstructure:"NAME"`
10871089
Type int `gorm:"column:type;type:int;default:0" json:"TYPE" mapstructure:"TYPE"`
1088-
MatchType int `gorm:"column:match_type;type:int;default:0" json:"MATCH_TYPE" mapstructure:"MATCH_TYPE"`
1090+
MatchType int `gorm:"column:match_type;type:int;default:1" json:"MATCH_TYPE" mapstructure:"MATCH_TYPE"`
10891091
VPCID int `gorm:"column:epc_id;type:int;default:0" json:"EPC_ID" mapstructure:"EPC_ID"`
10901092
PodClusterID int `gorm:"column:pod_cluster_id;type:int;default:0" json:"POD_CLUSTER_ID" mapstructure:"POD_CLUSTER_ID"`
10911093
PodNamespaceID int `gorm:"column:pod_namespace_id;type:int;default:0" json:"POD_NAMESPACE_ID" mapstructure:"POD_NAMESPACE_ID"`

server/controller/recorder/updater/pod_cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func (c *PodCluster) generateDBItemToAdd(cloudItem *cloudmodel.PodCluster) (*mys
9696
Region: cloudItem.RegionLcuuid,
9797
AZ: cloudItem.AZLcuuid,
9898
VPCID: vpcID,
99+
UID: ctrlrcommon.GenerateResourceShortUUID(ctrlrcommon.RESOURCE_TYPE_POD_CLUSTER_EN),
99100
}
100101
dbItem.Lcuuid = cloudItem.Lcuuid
101102
return dbItem, true

server/controller/recorder/updater/pod_group.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ func (p *PodGroup) generateDBItemToAdd(cloudItem *cloudmodel.PodGroup) (*mysqlmo
108108
log.Errorf("failed to convert %s spec JSON to YAML: %s", p.resourceType, cloudItem.Spec, p.metadata.LogPrefixes)
109109
return nil, false
110110
}
111-
// TODO is label required
112-
if cloudItem.Label == "" {
113-
cloudItem.Label = ctrlrcommon.GenerateResourceShortUUID(ctrlrcommon.RESOURCE_TYPE_CHOST_EN)
114-
}
111+
115112
dbItem := &mysqlmodel.PodGroup{
116113
Name: cloudItem.Name,
117114
Type: cloudItem.Type,
@@ -127,6 +124,7 @@ func (p *PodGroup) generateDBItemToAdd(cloudItem *cloudmodel.PodGroup) (*mysqlmo
127124
Domain: p.metadata.GetDomainLcuuid(),
128125
Region: cloudItem.RegionLcuuid,
129126
AZ: cloudItem.AZLcuuid,
127+
UID: ctrlrcommon.GenerateResourceShortUUID(ctrlrcommon.RESOURCE_TYPE_POD_GROUP_EN),
130128
}
131129
dbItem.Lcuuid = cloudItem.Lcuuid
132130
return dbItem, true
@@ -149,13 +147,6 @@ func (p *PodGroup) generateUpdateInfo(diffBase *diffbase.PodGroup, cloudItem *cl
149147
structInfo.PodNum.Set(diffBase.PodNum, cloudItem.PodNum)
150148
}
151149

152-
if cloudItem.Label == "" {
153-
if diffBase.Label == "" {
154-
cloudItem.Label = ctrlrcommon.GenerateResourceShortUUID(ctrlrcommon.RESOURCE_TYPE_CHOST_EN)
155-
} else {
156-
cloudItem.Label = diffBase.Label
157-
}
158-
}
159150
if diffBase.Label != cloudItem.Label {
160151
mapInfo["label"] = cloudItem.Label
161152
structInfo.Label.Set(diffBase.Label, cloudItem.Label)

server/controller/recorder/updater/pod_namespace.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func (n *PodNamespace) generateDBItemToAdd(cloudItem *cloudmodel.PodNamespace) (
103103
AZ: cloudItem.AZLcuuid,
104104
LearnedCloudTags: cloudTags,
105105
CustomCloudTags: make(map[string]string),
106+
UID: ctrlrcommon.GenerateResourceShortUUID(ctrlrcommon.RESOURCE_TYPE_POD_NAMESPACE_EN),
106107
}
107108
dbItem.Lcuuid = cloudItem.Lcuuid
108109
return dbItem, true

server/controller/recorder/updater/pod_service.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ func (s *PodService) generateDBItemToAdd(cloudItem *cloudmodel.PodService) (*mys
126126
log.Errorf("failed to convert %s spec JSON to YAML: %s", s.resourceType, cloudItem.Spec, s.metadata.LogPrefixes)
127127
return nil, false
128128
}
129-
// TODO is label required
130-
if cloudItem.Label == "" {
131-
cloudItem.Label = ctrlrcommon.GenerateResourceShortUUID(ctrlrcommon.RESOURCE_TYPE_CHOST_EN)
132-
}
129+
133130
dbItem := &mysqlmodel.PodService{
134131
Name: cloudItem.Name,
135132
Label: cloudItem.Label,
@@ -150,7 +147,7 @@ func (s *PodService) generateDBItemToAdd(cloudItem *cloudmodel.PodService) (*mys
150147
Region: cloudItem.RegionLcuuid,
151148
AZ: cloudItem.AZLcuuid,
152149
VPCID: vpcID,
153-
UID: cloudItem.Label,
150+
UID: ctrlrcommon.GenerateResourceShortUUID(ctrlrcommon.RESOURCE_TYPE_POD_SERVICE_EN),
154151
}
155152
dbItem.Lcuuid = cloudItem.Lcuuid
156153
return dbItem, true
@@ -181,13 +178,6 @@ func (s *PodService) generateUpdateInfo(diffBase *diffbase.PodService, cloudItem
181178
structInfo.Name.Set(diffBase.Name, cloudItem.Name)
182179
}
183180

184-
if cloudItem.Label == "" {
185-
if diffBase.Label == "" {
186-
cloudItem.Label = ctrlrcommon.GenerateResourceShortUUID(ctrlrcommon.RESOURCE_TYPE_CHOST_EN)
187-
} else {
188-
cloudItem.Label = diffBase.Label
189-
}
190-
}
191181
if diffBase.Label != cloudItem.Label {
192182
mapInfo["label"] = cloudItem.Label
193183
structInfo.Label.Set(diffBase.Label, cloudItem.Label)

0 commit comments

Comments
 (0)