Skip to content

Commit 30946d0

Browse files
ZhengYa-0110xiaochaoren1
authored andcommitted
feat: implement business service in trisolaris
1 parent 4182e23 commit 30946d0

12 files changed

Lines changed: 125 additions & 37 deletions

File tree

server/controller/common/const.go

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

790790
const (
791-
CUSTOM_SERVICE_TYPE_IP = 1
792-
CUSTOM_SERVICE_TYPE_PORT = 2
791+
CUSTOM_SERVICE_TYPE_IP = 1
792+
CUSTOM_SERVICE_TYPE_PORT = 2
793+
CUSTOM_SERVICE_TYPE_CHOST = 3
794+
CUSTOM_SERVICE_TYPE_POD_SERVICE = 4
795+
CUSTOM_SERVICE_TYPE_POD_GROUP = 5
796+
797+
CUSTOM_SERVICE_MATCH_TYPE_NAME = 1
798+
CUSTOM_SERVICE_MATCH_TYPE_UID = 2
793799
)

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/metadb/migrator/schema/rawsql/mysql/init.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ CREATE TABLE IF NOT EXISTS pod_cluster (
728728
region CHAR(64) DEFAULT '',
729729
sub_domain CHAR(64) DEFAULT '',
730730
domain CHAR(64) DEFAULT '',
731+
uid CHAR(64) DEFAULT '',
731732
lcuuid CHAR(64) DEFAULT '',
732733
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
733734
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@@ -859,6 +860,7 @@ CREATE TABLE IF NOT EXISTS pod_namespace (
859860
region CHAR(64) DEFAULT '',
860861
sub_domain CHAR(64) DEFAULT '',
861862
domain CHAR(64) DEFAULT '',
863+
uid CHAR(64) DEFAULT '',
862864
lcuuid CHAR(64) DEFAULT '',
863865
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
864866
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@@ -2727,7 +2729,7 @@ CREATE TABLE IF NOT EXISTS custom_service (
27272729
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
27282730
name VARCHAR(128) NOT NULL,
27292731
type INTEGER DEFAULT 0 COMMENT '0: unknown 1: IP 2: PORT 3: chost 4: pod_service 5: pod_group',
2730-
match_type INTEGER DEFAULT 0 COMMENT '0: unkonwn 1: name match 2: uid match',
2732+
match_type INTEGER DEFAULT 1 COMMENT '0: unkonwn 1: name match 2: uid match',
27312733
epc_id INTEGER DEFAULT 0,
27322734
pod_cluster_id INTEGER DEFAULT 0,
27332735
pod_namespace_id INTEGER DEFAULT 0,

server/controller/db/metadb/migrator/schema/rawsql/mysql/issu/7.1.0.9.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='7.1.0.9';

server/controller/db/metadb/migrator/schema/rawsql/postgres/init.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ CREATE TABLE IF NOT EXISTS pod_cluster (
617617
region VARCHAR(64) DEFAULT '',
618618
sub_domain VARCHAR(64) DEFAULT '',
619619
domain VARCHAR(64) DEFAULT '',
620+
uid VARCHAR(64) DEFAULT '',
620621
lcuuid VARCHAR(64) DEFAULT '',
621622
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
622623
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -678,6 +679,7 @@ CREATE TABLE IF NOT EXISTS pod_namespace (
678679
region VARCHAR(64) DEFAULT '',
679680
sub_domain VARCHAR(64) DEFAULT '',
680681
domain VARCHAR(64) DEFAULT '',
682+
uid VARCHAR(64) DEFAULT '',
681683
lcuuid VARCHAR(64) DEFAULT '',
682684
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
683685
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -2907,7 +2909,7 @@ CREATE TABLE IF NOT EXISTS custom_service (
29072909
id SERIAL PRIMARY KEY,
29082910
name VARCHAR(128) NOT NULL,
29092911
type INTEGER DEFAULT 0,
2910-
match_type INTEGER DEFAULT 0,
2912+
match_type INTEGER DEFAULT 1,
29112913
resource TEXT,
29122914
epc_id INTEGER DEFAULT 0,
29132915
pod_cluster_id INTEGER DEFAULT 0,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ type PodCluster struct {
760760
Region string `gorm:"column:region;type:char(64);default:''" json:"REGION" mapstructure:"REGION"`
761761
SubDomain string `gorm:"column:sub_domain;type:char(64);default:''" json:"SUB_DOMAIN" mapstructure:"SUB_DOMAIN"`
762762
Domain string `gorm:"column:domain;type:char(64);not null" json:"DOMAIN" mapstructure:"DOMAIN"`
763+
UID string `gorm:"column:uid;type:char(64);default:''" json:"UID" mapstructure:"UID"`
763764
}
764765

765766
func (p PodCluster) GetDomainLcuuid() string {
@@ -781,6 +782,7 @@ type PodNamespace struct {
781782
Domain string `gorm:"column:domain;type:char(64);not null" json:"DOMAIN" mapstructure:"DOMAIN"`
782783
LearnedCloudTags map[string]string `gorm:"column:learned_cloud_tags;type:text;default:'';serializer:json" json:"LEARNED_CLOUD_TAGS" mapstructure:"LEARNED_CLOUD_TAGS"`
783784
CustomCloudTags map[string]string `gorm:"column:custom_cloud_tags;type:text;default:'';serializer:json" json:"CUSTOM_CLOUD_TAGS" mapstructure:"CUSTOM_CLOUD_TAGS"`
785+
UID string `gorm:"column:uid;type:char(64);default:''" json:"UID" mapstructure:"UID"`
784786
}
785787

786788
func (p PodNamespace) GetDomainLcuuid() string {
@@ -1102,7 +1104,7 @@ type CustomService struct {
11021104
OperatedTime `gorm:"embedded" mapstructure:",squash"`
11031105
Name string `gorm:"column:name;type:varchar(128);default:''" json:"NAME" mapstructure:"NAME"`
11041106
Type int `gorm:"column:type;type:int;default:0" json:"TYPE" mapstructure:"TYPE"`
1105-
MatchType int `gorm:"column:match_type;type:int;default:0" json:"MATCH_TYPE" mapstructure:"MATCH_TYPE"`
1107+
MatchType int `gorm:"column:match_type;type:int;default:1" json:"MATCH_TYPE" mapstructure:"MATCH_TYPE"`
11061108
VPCID int `gorm:"column:epc_id;type:int;default:0" json:"EPC_ID" mapstructure:"EPC_ID"`
11071109
PodClusterID int `gorm:"column:pod_cluster_id;type:int;default:0" json:"POD_CLUSTER_ID" mapstructure:"POD_CLUSTER_ID"`
11081110
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) (*met
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) (*metadbm
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 := &metadbmodel.PodGroup{
116113
Name: cloudItem.Name,
117114
Type: cloudItem.Type,
@@ -127,6 +124,7 @@ func (p *PodGroup) generateDBItemToAdd(cloudItem *cloudmodel.PodGroup) (*metadbm
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) (*met
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 := &metadbmodel.PodService{
134131
Name: cloudItem.Name,
135132
Label: cloudItem.Label,
@@ -150,7 +147,7 @@ func (s *PodService) generateDBItemToAdd(cloudItem *cloudmodel.PodService) (*met
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)