Skip to content

Commit 15d0631

Browse files
committed
update at 2024-08-09 14:15:25
1 parent 2f47091 commit 15d0631

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

cmd/app/cmd.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ var RootCommand = cobra.Command{
1616
Use: "tke-extend-network-controller",
1717
Short: "A network controller for TKE",
1818
Run: func(cmd *cobra.Command, args []string) {
19-
clb.Init(viper.GetString(secretId), viper.GetString(secretKey), viper.GetString(region), viper.GetString(vpcId))
19+
clb.Init(
20+
viper.GetString(secretId),
21+
viper.GetString(secretKey),
22+
viper.GetString(region),
23+
viper.GetString(vpcId),
24+
viper.GetString(clusterId),
25+
)
2026
runManager()
2127
},
2228
}
@@ -29,6 +35,7 @@ const (
2935
secretKey = "secret-key"
3036
region = "region"
3137
vpcId = "vpcid"
38+
clusterId = "clusterid"
3239
)
3340

3441
var (

pkg/clb/clb.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88

99
var credential *common.Credential
1010

11-
var defaultRegion, defaultVpcId string
11+
var defaultRegion, defaultVpcId, clusterId string
1212

13-
func Init(secretId, secretKey, region, vpcId string) {
13+
func Init(secretId, secretKey, region, vpcId, clusterID string) {
1414
if secretId == "" || secretKey == "" {
1515
panic("secretId and secretKey are required")
1616
}
@@ -23,6 +23,7 @@ func Init(secretId, secretKey, region, vpcId string) {
2323
}
2424
defaultRegion = region
2525
defaultVpcId = vpcId
26+
clusterId = clusterID
2627
}
2728

2829
func DefaultRegion() string {

pkg/clb/instance.go

+10
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ func Create(ctx context.Context, region, vpcId, name string) (lbId string, err e
5353
req := clb.NewCreateLoadBalancerRequest()
5454
req.LoadBalancerType = common.StringPtr("OPEN")
5555
req.VpcId = &vpcId
56+
req.Tags = append(req.Tags,
57+
&clb.TagInfo{
58+
TagKey: common.StringPtr("tke-clusterId"), // 与集群关联
59+
TagValue: common.StringPtr(clusterId),
60+
},
61+
&clb.TagInfo{
62+
TagKey: common.StringPtr("tke-createdBy-flag"), // 用于删除集群时自动清理集群关联的自动创建的 CLB
63+
TagValue: common.StringPtr("yes"),
64+
},
65+
)
5666
client := GetClient(region)
5767
resp, err := client.CreateLoadBalancer(req)
5868
if err != nil {

0 commit comments

Comments
 (0)