Skip to content

Commit

Permalink
Merge pull request #3956 from nilo19/fix/dns-tag
Browse files Browse the repository at this point in the history
fix: make sure the pip dns tag will not be removed when systemTags is…
  • Loading branch information
k8s-ci-robot committed May 24, 2023
2 parents a99261b + b33278e commit 568712f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
8 changes: 7 additions & 1 deletion pkg/provider/azure_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3109,19 +3109,25 @@ func (az *Cloud) ensurePIPTagged(service *v1.Service, pip *network.PublicIPAddre
}

// include the cluster name and service names tags when comparing
var clusterName, serviceNames *string
var clusterName, serviceNames, serviceNameUsingDNS *string
if v := getClusterFromPIPClusterTags(pip.Tags); v != "" {
clusterName = &v
}
if v := getServiceFromPIPServiceTags(pip.Tags); v != "" {
serviceNames = &v
}
if v := getServiceFromPIPDNSTags(pip.Tags); v != "" {
serviceNameUsingDNS = &v
}
if clusterName != nil {
configTags[consts.ClusterNameKey] = clusterName
}
if serviceNames != nil {
configTags[consts.ServiceTagKey] = serviceNames
}
if serviceNameUsingDNS != nil {
configTags[consts.ServiceUsingDNSKey] = serviceNameUsingDNS
}

tags, changed := az.reconcileTags(pip.Tags, configTags)
pip.Tags = tags
Expand Down
58 changes: 31 additions & 27 deletions pkg/provider/azure_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6259,25 +6259,27 @@ func TestEnsurePIPTagged(t *testing.T) {
}
pip := network.PublicIPAddress{
Tags: map[string]*string{
consts.ClusterNameKey: pointer.String("testCluster"),
consts.ServiceTagKey: pointer.String("default/svc1,default/svc2"),
"foo": pointer.String("bar"),
"a": pointer.String("j"),
"m": pointer.String("n"),
consts.ClusterNameKey: pointer.String("testCluster"),
consts.ServiceTagKey: pointer.String("default/svc1,default/svc2"),
consts.ServiceUsingDNSKey: pointer.String("default/svc1"),
"foo": pointer.String("bar"),
"a": pointer.String("j"),
"m": pointer.String("n"),
},
}

t.Run("ensurePIPTagged should ensure the pip is tagged as configured", func(t *testing.T) {
expectedPIP := network.PublicIPAddress{
Tags: map[string]*string{
consts.ClusterNameKey: pointer.String("testCluster"),
consts.ServiceTagKey: pointer.String("default/svc1,default/svc2"),
"foo": pointer.String("bar"),
"a": pointer.String("b"),
"c": pointer.String("d"),
"y": pointer.String("z"),
"m": pointer.String("n"),
"e": pointer.String(""),
consts.ClusterNameKey: pointer.String("testCluster"),
consts.ServiceTagKey: pointer.String("default/svc1,default/svc2"),
consts.ServiceUsingDNSKey: pointer.String("default/svc1"),
"foo": pointer.String("bar"),
"a": pointer.String("b"),
"c": pointer.String("d"),
"y": pointer.String("z"),
"m": pointer.String("n"),
"e": pointer.String(""),
},
}
changed := cloud.ensurePIPTagged(&service, &pip)
Expand All @@ -6289,13 +6291,14 @@ func TestEnsurePIPTagged(t *testing.T) {
cloud.SystemTags = "a,foo"
expectedPIP := network.PublicIPAddress{
Tags: map[string]*string{
consts.ClusterNameKey: pointer.String("testCluster"),
consts.ServiceTagKey: pointer.String("default/svc1,default/svc2"),
"foo": pointer.String("bar"),
"a": pointer.String("b"),
"c": pointer.String("d"),
"y": pointer.String("z"),
"e": pointer.String(""),
consts.ClusterNameKey: pointer.String("testCluster"),
consts.ServiceTagKey: pointer.String("default/svc1,default/svc2"),
consts.ServiceUsingDNSKey: pointer.String("default/svc1"),
"foo": pointer.String("bar"),
"a": pointer.String("b"),
"c": pointer.String("d"),
"y": pointer.String("z"),
"e": pointer.String(""),
},
}
changed := cloud.ensurePIPTagged(&service, &pip)
Expand All @@ -6308,13 +6311,14 @@ func TestEnsurePIPTagged(t *testing.T) {
cloud.TagsMap = map[string]string{"a": "c", "a=b": "c=d", "Y": "zz"}
expectedPIP := network.PublicIPAddress{
Tags: map[string]*string{
consts.ClusterNameKey: pointer.String("testCluster"),
consts.ServiceTagKey: pointer.String("default/svc1,default/svc2"),
"foo": pointer.String("bar"),
"a": pointer.String("b"),
"c": pointer.String("d"),
"a=b": pointer.String("c=d"),
"e": pointer.String(""),
consts.ClusterNameKey: pointer.String("testCluster"),
consts.ServiceTagKey: pointer.String("default/svc1,default/svc2"),
consts.ServiceUsingDNSKey: pointer.String("default/svc1"),
"foo": pointer.String("bar"),
"a": pointer.String("b"),
"c": pointer.String("d"),
"a=b": pointer.String("c=d"),
"e": pointer.String(""),
},
}
changed := cloud.ensurePIPTagged(&service, &pip)
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/azure_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func (az *Cloud) reconcileTags(currentTagsOnResource, newTags map[string]*string
for k := range currentTagsOnResource {
if _, ok := newTags[k]; !ok {
if found, _ := findKeyInMapCaseInsensitive(systemTagsMap, k); !found {
klog.V(2).Infof("reconcileTags: delete tag %s: %s", k, pointer.StringDeref(currentTagsOnResource[k], ""))
delete(currentTagsOnResource, k)
changed = true
}
Expand Down

0 comments on commit 568712f

Please sign in to comment.