Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.25] fix: make sure the pip dns tag will not be removed when systemTags is… #3959

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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