@@ -19,6 +19,14 @@ import (
1919 "strings"
2020)
2121
22+ var (
23+ tagVariables = []string {
24+ "${iam.principal.name}" ,
25+ "${iam.principal.type}" ,
26+ "${oci.datetime}" ,
27+ }
28+ )
29+
2230func isDefinedTagsEqual (dt1 , dt2 util.DefinedTagsType ) bool {
2331 return reflect .DeepEqual (getLowerCaseDefinedTags (dt1 ), getLowerCaseDefinedTags (dt2 ))
2432}
@@ -59,7 +67,7 @@ func getUpdatedDefinedAndImplicitDefaultTags(actualTags util.DefinedTagsType,
5967 klog .Infof ("Calculating defined/default tags where actualTags: %+v, suppliedDefinedTags: %+v, implicitDefaultTags: %+v" ,
6068 actualTags , definedTags , defaultTags )
6169
62- // Preserve default tags
70+ // Preserve default tags if they are present on LB and not overriden in supplied tags
6371 lcDefinedTags := getLowerCaseDefinedTags (definedTags )
6472 lcDefaultTags := getLowerCaseDefinedTags (defaultTags )
6573 for namespace , _ := range actualTags {
@@ -74,10 +82,18 @@ func getUpdatedDefinedAndImplicitDefaultTags(actualTags util.DefinedTagsType,
7482
7583 // Add supplied defined tags
7684 // We use only lower-case (namespace, key) pairs to avoid case-related conflicts
85+ // If the supplied tag value has a Tag Variable, and the tag is already present on LB we will not try to update it
86+ lcActualTags := getLowerCaseDefinedTags (actualTags )
7787 lcUpdatedDefinedTags := getLowerCaseDefinedTags (updatedDefinedTags )
7888 for namespace , _ := range lcDefinedTags {
7989 for key , value := range lcDefinedTags [namespace ] {
80- insertDefinedTag (lcUpdatedDefinedTags , namespace , key , value )
90+ if definedTagValueHasTagVariable (value ) && containsDefinedTagIgnoreCase (lcActualTags , namespace , key ) {
91+ klog .Infof ("Supplied value of Tag %s.%s has tag-variable(s) and is already present on LB, will not be updated" ,
92+ namespace , key )
93+ insertDefinedTag (lcUpdatedDefinedTags , namespace , key , lcActualTags [namespace ][key ])
94+ } else {
95+ insertDefinedTag (lcUpdatedDefinedTags , namespace , key , value )
96+ }
8197 }
8298 }
8399
@@ -115,6 +131,7 @@ func getLowerCaseDefinedTags(tags util.DefinedTagsType) util.DefinedTagsType {
115131 return lowerCaseTags
116132}
117133
134+ // Checks if (namespace, key) pair exists in a lower-cased definedTags map, ignore case of (namespace, key)
118135func containsDefinedTagIgnoreCase (lowerCaseTags util.DefinedTagsType , namespace string , key string ) bool {
119136 if lowerCaseTags == nil {
120137 return false
@@ -143,3 +160,16 @@ func insertDefinedTag(definedTags util.DefinedTagsType, namespace string, key st
143160
144161 definedTags [namespace ][key ] = value
145162}
163+
164+ func definedTagValueHasTagVariable (value interface {}) bool {
165+ stringValue , ok := value .(string )
166+ if ok {
167+ for _ , tagVar := range tagVariables {
168+ if strings .Contains (stringValue , tagVar ) {
169+ return true
170+ }
171+ }
172+ }
173+
174+ return false
175+ }
0 commit comments