diff --git a/pkg/cloudprovider/providers/azure/azure_fakes.go b/pkg/cloudprovider/providers/azure/azure_fakes.go index 69be811de3a..35a443021f3 100644 --- a/pkg/cloudprovider/providers/azure/azure_fakes.go +++ b/pkg/cloudprovider/providers/azure/azure_fakes.go @@ -1158,7 +1158,7 @@ func (f *fakeVMSet) GetVMSetNames(service *v1.Service, nodes []*v1.Node) (availa return nil, fmt.Errorf("unimplemented") } -func (f *fakeVMSet) EnsureHostsInPool(serviceName string, nodes []*v1.Node, backendPoolID string, vmSetName string) error { +func (f *fakeVMSet) EnsureHostsInPool(serviceName string, nodes []*v1.Node, backendPoolID string, vmSetName string, isInternal bool) error { return fmt.Errorf("unimplemented") } diff --git a/pkg/cloudprovider/providers/azure/azure_standard_test.go b/pkg/cloudprovider/providers/azure/azure_standard_test.go index 5de3e3c4b1b..4d6e7c24572 100644 --- a/pkg/cloudprovider/providers/azure/azure_standard_test.go +++ b/pkg/cloudprovider/providers/azure/azure_standard_test.go @@ -130,6 +130,7 @@ func TestMapLoadBalancerNameToVMSet(t *testing.T) { cases := []struct { description string lbName string + useStandardLB bool clusterName string expectedVMSet string }{ @@ -157,10 +158,124 @@ func TestMapLoadBalancerNameToVMSet(t *testing.T) { clusterName: "azure", expectedVMSet: "azuretest", }, + { + description: "default standard external LB should map to empty string", + lbName: "azure", + useStandardLB: true, + clusterName: "azure", + expectedVMSet: "", + }, + { + description: "default standard internal LB should map to empty string", + lbName: "azure-internal", + useStandardLB: true, + clusterName: "azure", + expectedVMSet: "", + }, + { + description: "non-default standard external LB should map to empty string", + lbName: "azuretest", + useStandardLB: true, + clusterName: "azure", + expectedVMSet: "", + }, + { + description: "non-default standard internal LB should map to empty string", + lbName: "azuretest-internal", + useStandardLB: true, + clusterName: "azure", + expectedVMSet: "", + }, } for _, c := range cases { + if c.useStandardLB { + az.Config.LoadBalancerSku = loadBalancerSkuStandard + } else { + az.Config.LoadBalancerSku = loadBalancerSkuBasic + } vmset := az.mapLoadBalancerNameToVMSet(c.lbName, c.clusterName) assert.Equal(t, c.expectedVMSet, vmset, c.description) } } + +func TestGetLoadBalancerName(t *testing.T) { + az := getTestCloud() + az.PrimaryAvailabilitySetName = "primary" + + cases := []struct { + description string + vmSet string + isInternal bool + useStandardLB bool + clusterName string + expected string + }{ + { + description: "default external LB should get primary vmset", + vmSet: "primary", + clusterName: "azure", + expected: "azure", + }, + { + description: "default internal LB should get primary vmset", + vmSet: "primary", + clusterName: "azure", + isInternal: true, + expected: "azure-internal", + }, + { + description: "non-default external LB should get its own vmset", + vmSet: "as", + clusterName: "azure", + expected: "as", + }, + { + description: "non-default internal LB should get its own vmset", + vmSet: "as", + clusterName: "azure", + isInternal: true, + expected: "as-internal", + }, + { + description: "default standard external LB should get cluster name", + vmSet: "primary", + useStandardLB: true, + clusterName: "azure", + expected: "azure", + }, + { + description: "default standard internal LB should get cluster name", + vmSet: "primary", + useStandardLB: true, + isInternal: true, + clusterName: "azure", + expected: "azure-internal", + }, + { + description: "non-default standard external LB should get cluster-name", + vmSet: "as", + useStandardLB: true, + clusterName: "azure", + expected: "azure", + }, + { + description: "non-default standard internal LB should get cluster-name", + vmSet: "as", + useStandardLB: true, + isInternal: true, + clusterName: "azure", + expected: "azure-internal", + }, + } + + for _, c := range cases { + if c.useStandardLB { + az.Config.LoadBalancerSku = loadBalancerSkuStandard + } else { + az.Config.LoadBalancerSku = loadBalancerSkuBasic + } + loadbalancerName := az.getLoadBalancerName(c.clusterName, c.vmSet, c.isInternal) + assert.Equal(t, c.expected, loadbalancerName, c.description) + } +}