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

Automated cherry pick of #79514: Default resourceGroup should be used when value of annotation #79519

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/cloudprovider/providers/azure/azure_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,10 @@ func findSecurityRule(rules []network.SecurityRule, rule network.SecurityRule) b

func (az *Cloud) getPublicIPAddressResourceGroup(service *v1.Service) string {
if resourceGroup, found := service.Annotations[ServiceAnnotationLoadBalancerResourceGroup]; found {
return resourceGroup
resourceGroupName := strings.TrimSpace(resourceGroup)
if len(resourceGroupName) > 0 {
return resourceGroupName
}
}

return az.ResourceGroup
Expand Down
32 changes: 32 additions & 0 deletions pkg/cloudprovider/providers/azure/azure_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,35 @@ func TestEnsureLoadBalancerDeleted(t *testing.T) {
assert.Equal(t, len(result), 0, "TestCase[%d]: %s", i, c.desc)
}
}

func TestGetPublicIPAddressResourceGroup(t *testing.T) {
az := getTestCloud()

for i, c := range []struct {
desc string
annotations map[string]string
expected string
}{
{
desc: "no annotation",
expected: "rg",
},
{
desc: "annoation with empty string resource group",
annotations: map[string]string{ServiceAnnotationLoadBalancerResourceGroup: ""},
expected: "rg",
},
{
desc: "annoation with non-empty resource group ",
annotations: map[string]string{ServiceAnnotationLoadBalancerResourceGroup: "rg2"},
expected: "rg2",
},
} {
t.Run(c.desc, func(t *testing.T) {
s := &v1.Service{}
s.Annotations = c.annotations
real := az.getPublicIPAddressResourceGroup(s)
assert.Equal(t, c.expected, real, "TestCase[%d]: %s", i, c.desc)
})
}
}