mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Merge pull request #79514 from feiskyer/fix-lb-rg
Default resourceGroup should be used when value of annotation azure-load-balancer-resource-group is empty string
This commit is contained in:
commit
5019bb57a3
@ -1543,7 +1543,10 @@ func findSecurityRule(rules []network.SecurityRule, rule network.SecurityRule) b
|
|||||||
|
|
||||||
func (az *Cloud) getPublicIPAddressResourceGroup(service *v1.Service) string {
|
func (az *Cloud) getPublicIPAddressResourceGroup(service *v1.Service) string {
|
||||||
if resourceGroup, found := service.Annotations[ServiceAnnotationLoadBalancerResourceGroup]; found {
|
if resourceGroup, found := service.Annotations[ServiceAnnotationLoadBalancerResourceGroup]; found {
|
||||||
return resourceGroup
|
resourceGroupName := strings.TrimSpace(resourceGroup)
|
||||||
|
if len(resourceGroupName) > 0 {
|
||||||
|
return resourceGroupName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return az.ResourceGroup
|
return az.ResourceGroup
|
||||||
|
@ -450,6 +450,38 @@ func TestServiceOwnsPublicIP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetServiceTags(t *testing.T) {
|
func TestGetServiceTags(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
desc string
|
desc string
|
||||||
|
Loading…
Reference in New Issue
Block a user