Skip to content

Commit

Permalink
feat: add a configuration SkipTaggingRouteTable to skip tagging the…
Browse files Browse the repository at this point in the history
… route table resource if set to true.
  • Loading branch information
nilo19 committed Oct 5, 2023
1 parent 91f6184 commit 0a10673
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/provider/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ type Config struct {
RouteUpdateIntervalInSeconds int `json:"routeUpdateIntervalInSeconds,omitempty" yaml:"routeUpdateIntervalInSeconds,omitempty"`
// LoadBalancerBackendPoolUpdateIntervalInSeconds is the interval for updating load balancer backend pool of local services. Default is 30 seconds.
LoadBalancerBackendPoolUpdateIntervalInSeconds int `json:"loadBalancerBackendPoolUpdateIntervalInSeconds,omitempty" yaml:"loadBalancerBackendPoolUpdateIntervalInSeconds,omitempty"`

SkipTaggingRouteTable bool `json:"skipTaggingRouteTable,omitempty" yaml:"skipTaggingRouteTable,omitempty"`
}

// MultipleStandardLoadBalancerConfiguration stores the properties regarding multiple standard load balancers.
Expand Down
4 changes: 4 additions & 0 deletions pkg/provider/azure_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,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 az.SkipTaggingRouteTable {
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.SkipTaggingRouteTable = true
rt = &network.RouteTable{}
tags, changed = cloud.ensureRouteTableTagged(rt)
assert.Nil(t, tags)
assert.False(t, changed)
}

0 comments on commit 0a10673

Please sign in to comment.