Skip to content

Commit

Permalink
Merge pull request #3959 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…3956-to-release-1.25

[release-1.25] fix: make sure the pip dns tag will not be removed when systemTags is…
  • Loading branch information
k8s-ci-robot authored May 24, 2023
2 parents 63ff751 + 31e638e commit 8ec9963
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 @@ -3016,19 +3016,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 @@ -5478,25 +5478,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 @@ -5508,13 +5510,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 @@ -5527,13 +5530,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 @@ -181,6 +181,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 8ec9963

Please sign in to comment.