Skip to content

Commit

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

[release-1.27] fix: skip tagging route table that is not in the cluster resource group
  • Loading branch information
k8s-ci-robot committed Oct 13, 2023
2 parents 547bc11 + 9c548ef commit 03750a7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/provider/azure_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ func cidrtoRfc1035(cidr string) string {

// ensureRouteTableTagged ensures the route table is tagged as configured
func (az *Cloud) ensureRouteTableTagged(rt *network.RouteTable) (map[string]*string, bool) {
if !strings.EqualFold(az.RouteTableResourceGroup, az.ResourceGroup) {
return nil, false
}

if az.Tags == "" && (az.TagsMap == nil || len(az.TagsMap) == 0) {
return nil, false
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/provider/azure_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,26 @@ func TestCleanupOutdatedRoutes(t *testing.T) {
})
}
}

func TestEnsureRouteTableTagged(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

cloud := GetTestCloud(ctrl)
cloud.Tags = "a=b,c=d"

expectedTags := map[string]*string{
"a": pointer.String("b"),
"c": pointer.String("d"),
}
rt := &network.RouteTable{}
tags, changed := cloud.ensureRouteTableTagged(rt)
assert.Equal(t, expectedTags, tags)
assert.True(t, changed)

cloud.RouteTableResourceGroup = "rg1"
rt = &network.RouteTable{}
tags, changed = cloud.ensureRouteTableTagged(rt)
assert.Nil(t, tags)
assert.False(t, changed)
}

0 comments on commit 03750a7

Please sign in to comment.