mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #15013 from ioito/hotfix/qx-system-tags
fix(region): qcloud and google system tag
This commit is contained in:
@@ -2449,7 +2449,7 @@ func (self *SHost) SyncHostVMs(ctx context.Context, userCred mcclient.TokenCrede
|
||||
}
|
||||
|
||||
skipFunc := func(ext cloudprovider.ICloudVM) (bool, string) {
|
||||
if len(options.Options.SkipServerBySysTagKeys) == 0 {
|
||||
if len(options.Options.SkipServerBySysTagKeys) == 0 && len(options.Options.SkipServerBySysTagKeys) == 0 {
|
||||
return false, ""
|
||||
}
|
||||
keys := strings.Split(options.Options.SkipServerBySysTagKeys, ",")
|
||||
@@ -2458,6 +2458,13 @@ func (self *SHost) SyncHostVMs(ctx context.Context, userCred mcclient.TokenCrede
|
||||
return true, key
|
||||
}
|
||||
}
|
||||
userKeys := strings.Split(options.Options.SkipServerByUserTagKeys, ",")
|
||||
tags, _ := ext.GetTags()
|
||||
for key := range tags {
|
||||
if utils.IsInStringArray(key, userKeys) {
|
||||
return true, key
|
||||
}
|
||||
}
|
||||
return false, ""
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,8 @@ type ComputeOptions struct {
|
||||
DefaultIPAllocationDirection string `help:"default IP allocation direction" default:"stepdown"`
|
||||
|
||||
// 弹性伸缩中的ecs一般会有特殊的系统标签,通过指定这些标签可以忽略这部分ecs的同步, 指定多个key需要以 ',' 分隔
|
||||
SkipServerBySysTagKeys string `help:"skip server sync and create with system tags" default:"acs:autoscaling:scalingGroupId"`
|
||||
SkipServerBySysTagKeys string `help:"skip server sync and create with system tags" default:"acs:autoscaling:scalingGroupId"`
|
||||
SkipServerByUserTagKeys string `help:"skip server sync and create with user tags" default:""`
|
||||
|
||||
EnableAwsMonitorAgent bool `help:"enable aws monitor agent" default:"true"`
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ type QcloudTags struct {
|
||||
ResourceTags []STag
|
||||
}
|
||||
|
||||
func (self *QcloudTags) GetTags() (map[string]string, error) {
|
||||
func (self *QcloudTags) getTags() (map[string]string, error) {
|
||||
ret := map[string]string{}
|
||||
for _, tag := range self.TagSet {
|
||||
if tag.Value == "null" {
|
||||
@@ -95,8 +95,25 @@ func (self *QcloudTags) GetTags() (map[string]string, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *QcloudTags) GetTags() (map[string]string, error) {
|
||||
tags, _ := self.getTags()
|
||||
for k := range tags {
|
||||
if strings.HasPrefix(k, "tencentcloud:") {
|
||||
delete(tags, k)
|
||||
}
|
||||
}
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (self *QcloudTags) GetSysTags() map[string]string {
|
||||
return nil
|
||||
tags, _ := self.getTags()
|
||||
ret := map[string]string{}
|
||||
for k, v := range tags {
|
||||
if strings.HasPrefix(k, "tencentcloud:") {
|
||||
ret[k] = v
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *QcloudTags) SetTags(tags map[string]string, replace bool) error {
|
||||
@@ -124,7 +141,8 @@ func (self *AliyunTags) GetTags() (map[string]string, error) {
|
||||
ret := map[string]string{}
|
||||
for _, tag := range self.Tags.Tag {
|
||||
if strings.HasPrefix(tag.TagKey, "aliyun") || strings.HasPrefix(tag.TagKey, "acs:") ||
|
||||
strings.HasSuffix(tag.Key, "aliyun") || strings.HasPrefix(tag.Key, "acs:") {
|
||||
strings.HasSuffix(tag.Key, "aliyun") || strings.HasPrefix(tag.Key, "acs:") ||
|
||||
strings.HasSuffix(tag.Key, "ack.") { // k8s
|
||||
continue
|
||||
}
|
||||
if len(tag.TagKey) > 0 {
|
||||
@@ -141,7 +159,8 @@ func (self *AliyunTags) GetSysTags() map[string]string {
|
||||
ret := map[string]string{}
|
||||
for _, tag := range self.Tags.Tag {
|
||||
if strings.HasPrefix(tag.TagKey, "aliyun") || strings.HasPrefix(tag.TagKey, "acs:") ||
|
||||
strings.HasPrefix(tag.Key, "aliyun") || strings.HasPrefix(tag.Key, "acs:") {
|
||||
strings.HasPrefix(tag.Key, "aliyun") || strings.HasPrefix(tag.Key, "acs:") ||
|
||||
strings.HasPrefix(tag.Key, "ack.") { // k8s
|
||||
if len(tag.TagKey) > 0 {
|
||||
ret[tag.TagKey] = tag.TagValue
|
||||
} else if len(tag.Key) > 0 {
|
||||
@@ -204,13 +223,22 @@ type GoogleTags struct {
|
||||
func (self *GoogleTags) GetTags() (map[string]string, error) {
|
||||
ret := map[string]string{}
|
||||
for k, v := range self.Labels {
|
||||
if strings.HasPrefix(k, "goog-") {
|
||||
continue
|
||||
}
|
||||
ret[encode.DecodeGoogleLable(k)] = encode.DecodeGoogleLable(v)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *GoogleTags) GetSysTags() map[string]string {
|
||||
return nil
|
||||
ret := map[string]string{}
|
||||
for k, v := range self.Labels {
|
||||
if strings.HasPrefix(k, "goog-") {
|
||||
ret[k] = v
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *GoogleTags) SetTags(tags map[string]string, replace bool) error {
|
||||
|
||||
Reference in New Issue
Block a user