Skip to content

Commit

Permalink
fix: The case of load balancer name should be ignored when determing …
Browse files Browse the repository at this point in the history
…if it is an internal load balancer.
  • Loading branch information
nilo19 committed Jan 7, 2024
1 parent 7af6ae4 commit d84101a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
4 changes: 3 additions & 1 deletion kubetest2-aks/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module sigs.k8s.io/cloud-provider-azure/kubetest2-aks

go 1.18
go 1.21

toolchain go1.21.5

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1
Expand Down
4 changes: 0 additions & 4 deletions pkg/provider/azure_standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ func getIPConfigByIPFamily(nic network.Interface, IPv6 bool) (*network.Interface
return nil, fmt.Errorf("failed to determine the ipconfig(IPv6=%v). nicname=%q", IPv6, pointer.StringDeref(nic.Name, ""))
}

func isInternalLoadBalancer(lb *network.LoadBalancer) bool {
return strings.HasSuffix(*lb.Name, consts.InternalLoadBalancerNameSuffix)
}

// getBackendPoolName the LB BackendPool name for a service.
// to ensure backward and forward compat:
// SingleStack -v4 (pre v1.16) => BackendPool name == clusterName
Expand Down
4 changes: 4 additions & 0 deletions pkg/provider/azure_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,7 @@ func getResourceGroupAndNameFromNICID(ipConfigurationID string) (string, string,
}
return nicResourceGroup, nicName, nil
}

func isInternalLoadBalancer(lb *network.LoadBalancer) bool {
return strings.HasSuffix(strings.ToLower(*lb.Name), consts.InternalLoadBalancerNameSuffix)
}
38 changes: 38 additions & 0 deletions pkg/provider/azure_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,3 +895,41 @@ func TestGetResourceIDPrefix(t *testing.T) {
})
}
}

func TestIsInternalLoadBalancer(t *testing.T) {
tests := []struct {
name string
lb network.LoadBalancer
expected bool
}{
{
name: "internal load balancer",
lb: network.LoadBalancer{
Name: pointer.String("test-internal"),
},
expected: true,
},
{
name: "internal load balancer",
lb: network.LoadBalancer{
Name: pointer.String("TEST-INTERNAL"),
},
expected: true,
},
{
name: "not internal load balancer",
lb: network.LoadBalancer{
Name: pointer.String("test"),
},
expected: false,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
lb := test.lb
result := isInternalLoadBalancer(&lb)
assert.Equal(t, test.expected, result)
})
}
}

0 comments on commit d84101a

Please sign in to comment.