From 286fd9a2f2ac63045bbaae768a45ebd6818eab59 Mon Sep 17 00:00:00 2001 From: Cecile Robert-Michon Date: Fri, 9 Oct 2020 17:07:01 -0700 Subject: [PATCH] fix lb tests --- cloud/scope/cluster.go | 1 - cloud/services/loadbalancers/loadbalancers.go | 2 +- .../loadbalancers/loadbalancers_test.go | 370 ++++++------------ cloud/types.go | 1 - 4 files changed, 128 insertions(+), 246 deletions(-) diff --git a/cloud/scope/cluster.go b/cloud/scope/cluster.go index 6f8180c0f37..2eb9ae73eca 100644 --- a/cloud/scope/cluster.go +++ b/cloud/scope/cluster.go @@ -126,7 +126,6 @@ func (s *ClusterScope) LBSpecs() []azure.LBSpec { // Control Plane LB Name: s.APIServerLB().Name, SubnetName: s.ControlPlaneSubnet().Name, - SubnetCidrs: s.ControlPlaneSubnet().CIDRBlocks, FrontendIPConfigs: s.APIServerLB().FrontendIPs, APIServerPort: s.APIServerPort(), Type: s.APIServerLB().Type, diff --git a/cloud/services/loadbalancers/loadbalancers.go b/cloud/services/loadbalancers/loadbalancers.go index c012a6b450a..8ae39ee9320 100644 --- a/cloud/services/loadbalancers/loadbalancers.go +++ b/cloud/services/loadbalancers/loadbalancers.go @@ -37,7 +37,6 @@ func (s *Service) Reconcile(ctx context.Context) error { } lb := network.LoadBalancer{ - Name: to.StringPtr(lbSpec.Name), Sku: &network.LoadBalancerSku{Name: network.LoadBalancerSkuNameStandard}, Location: to.StringPtr(s.Scope.Location()), Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{ @@ -110,6 +109,7 @@ func (s *Service) Reconcile(ctx context.Context) error { }, }, } + // TODO: check if this is needed for outbound access if lbSpec.Type == infrav1.Internal { lb.LoadBalancerPropertiesFormat.OutboundRules = nil } diff --git a/cloud/services/loadbalancers/loadbalancers_test.go b/cloud/services/loadbalancers/loadbalancers_test.go index b67c5d0a765..6cf47bf26eb 100644 --- a/cloud/services/loadbalancers/loadbalancers_test.go +++ b/cloud/services/loadbalancers/loadbalancers_test.go @@ -45,14 +45,13 @@ func TestReconcileLoadBalancer(t *testing.T) { }{ { name: "fail to create a public LB", - expectedError: "failed to create load balancer my-publiclb: #: Internal Server Error: StatusCode=500", + expectedError: "failed to create load balancer \"my-publiclb\": #: Internal Server Error: StatusCode=500", expect: func(s *mock_loadbalancers.MockLBScopeMockRecorder, m *mock_loadbalancers.MockClientMockRecorder, mVnet *mock_virtualnetworks.MockClientMockRecorder) { s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) s.LBSpecs().Return([]azure.LBSpec{ { - Name: "my-publiclb", - PublicIPName: "my-publicip", - Role: infrav1.APIServerRole, + Name: "my-publiclb", + Role: infrav1.APIServerRole, }, }) s.SubscriptionID().AnyTimes().Return("123") @@ -64,15 +63,26 @@ func TestReconcileLoadBalancer(t *testing.T) { }, }, { - name: "create apiserver LB", + name: "create public apiserver LB", expectedError: "", expect: func(s *mock_loadbalancers.MockLBScopeMockRecorder, m *mock_loadbalancers.MockClientMockRecorder, mVnet *mock_virtualnetworks.MockClientMockRecorder) { s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) s.LBSpecs().Return([]azure.LBSpec{ { - Name: "my-publiclb", - PublicIPName: "my-publicip", - Role: infrav1.APIServerRole, + Name: "my-publiclb", + Role: infrav1.APIServerRole, + Type: infrav1.Public, + SubnetName: "my-cp-subnet", + BackendPoolName: "my-publiclb-backendPool", + FrontendIPConfigs: []infrav1.FrontendIP{ + { + Name: "my-publiclb-frontEnd", + PublicIP: &infrav1.PublicIPSpec{ + Name: "my-publicip", + DNSName: "my-cluster.12345.mydomain.com", + }, + }, + }, APIServerPort: 6443, }, }) @@ -94,7 +104,6 @@ func TestReconcileLoadBalancer(t *testing.T) { { Name: to.StringPtr("my-publiclb-frontEnd"), FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{ - PrivateIPAllocationMethod: network.Dynamic, PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/publicIPAddresses/my-publicip")}, }, }, @@ -159,57 +168,93 @@ func TestReconcileLoadBalancer(t *testing.T) { }, }, { - name: "create node outbound LB", + name: "create internal apiserver LB", expectedError: "", expect: func(s *mock_loadbalancers.MockLBScopeMockRecorder, m *mock_loadbalancers.MockClientMockRecorder, mVnet *mock_virtualnetworks.MockClientMockRecorder) { s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) s.LBSpecs().Return([]azure.LBSpec{ { - Name: "cluster-name", - PublicIPName: "outbound-publicip", - Role: infrav1.NodeOutboundRole, + Name: "my-private-lb", + Role: infrav1.APIServerRole, + Type: infrav1.Internal, + SubnetName: "my-cp-subnet", + BackendPoolName: "my-private-lb-backendPool", + FrontendIPConfigs: []infrav1.FrontendIP{ + { + Name: "my-private-lb-frontEnd", + PrivateIPAddress: "10.0.0.10", + }, + }, + APIServerPort: 6443, }, }) s.SubscriptionID().AnyTimes().Return("123") s.ResourceGroup().AnyTimes().Return("my-rg") + s.Vnet().AnyTimes().Return(&infrav1.VnetSpec{ + ResourceGroup: "my-rg", + Name: "my-vnet", + }) s.Location().AnyTimes().Return("testlocation") - s.ClusterName().AnyTimes().Return("cluster-name") + s.ClusterName().AnyTimes().Return("my-cluster") s.AdditionalTags().AnyTimes().Return(infrav1.Tags{}) gomock.InOrder( - m.CreateOrUpdate(context.TODO(), "my-rg", "cluster-name", gomockinternal.DiffEq(network.LoadBalancer{ + m.CreateOrUpdate(context.TODO(), "my-rg", "my-private-lb", gomockinternal.DiffEq(network.LoadBalancer{ Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_cluster-name": to.StringPtr("owned"), - "sigs.k8s.io_cluster-api-provider-azure_role": to.StringPtr(infrav1.NodeOutboundRole), + "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), + "sigs.k8s.io_cluster-api-provider-azure_role": to.StringPtr(infrav1.APIServerRole), }, Sku: &network.LoadBalancerSku{Name: network.LoadBalancerSkuNameStandard}, Location: to.StringPtr("testlocation"), LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{ FrontendIPConfigurations: &[]network.FrontendIPConfiguration{ { - Name: to.StringPtr("cluster-name-frontEnd"), + Name: to.StringPtr("my-private-lb-frontEnd"), FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{ - PrivateIPAllocationMethod: network.Dynamic, - PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/publicIPAddresses/outbound-publicip")}, + PrivateIPAllocationMethod: network.Static, + Subnet: &network.Subnet{ + ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-cp-subnet"), + }, + PrivateIPAddress: to.StringPtr("10.0.0.10"), }, }, }, BackendAddressPools: &[]network.BackendAddressPool{ { - Name: to.StringPtr("cluster-name-outboundBackendPool"), + Name: to.StringPtr("my-private-lb-backendPool"), }, }, - OutboundRules: &[]network.OutboundRule{ + LoadBalancingRules: &[]network.LoadBalancingRule{ { - Name: to.StringPtr("OutboundNATAllProtocols"), - OutboundRulePropertiesFormat: &network.OutboundRulePropertiesFormat{ - FrontendIPConfigurations: &[]network.SubResource{ - {ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/cluster-name/frontendIPConfigurations/cluster-name-frontEnd")}, + Name: to.StringPtr("LBRuleHTTPS"), + LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{ + DisableOutboundSnat: to.BoolPtr(true), + Protocol: network.TransportProtocolTCP, + FrontendPort: to.Int32Ptr(6443), + BackendPort: to.Int32Ptr(6443), + IdleTimeoutInMinutes: to.Int32Ptr(4), + EnableFloatingIP: to.BoolPtr(false), + LoadDistribution: network.LoadDistributionDefault, + FrontendIPConfiguration: &network.SubResource{ + ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-private-lb/frontendIPConfigurations/my-private-lb-frontEnd"), }, BackendAddressPool: &network.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/cluster-name/backendAddressPools/cluster-name-outboundBackendPool"), + ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-private-lb/backendAddressPools/my-private-lb-backendPool"), + }, + Probe: &network.SubResource{ + ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-private-lb/probes/HTTPSProbe"), }, - Protocol: network.LoadBalancerOutboundRuleProtocolAll, - IdleTimeoutInMinutes: to.Int32Ptr(4), + }, + }, + }, + Probes: &[]network.Probe{ + { + Name: to.StringPtr("HTTPSProbe"), + ProbePropertiesFormat: &network.ProbePropertiesFormat{ + Protocol: network.ProbeProtocolHTTPS, + Port: to.Int32Ptr(6443), + RequestPath: to.StringPtr("/healthz"), + IntervalInSeconds: to.Int32Ptr(15), + NumberOfProbes: to.Int32Ptr(4), }, }, }, @@ -218,182 +263,70 @@ func TestReconcileLoadBalancer(t *testing.T) { }, }, { - name: "internal load balancer does not exist", + name: "create node outbound LB", expectedError: "", expect: func(s *mock_loadbalancers.MockLBScopeMockRecorder, m *mock_loadbalancers.MockClientMockRecorder, mVnet *mock_virtualnetworks.MockClientMockRecorder) { s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) s.LBSpecs().Return([]azure.LBSpec{ { - Name: "my-lb", - SubnetCidrs: []string{"10.0.0.0/16"}, - SubnetName: "my-subnet", - PrivateIPAddress: "10.0.0.10", - Role: infrav1.InternalRole, - }, - }) - s.SubscriptionID().AnyTimes().Return("123") - s.ResourceGroup().AnyTimes().Return("my-rg") - s.Vnet().AnyTimes().Return(&infrav1.VnetSpec{ - ResourceGroup: "my-rg", - Name: "my-vnet", - }) - s.Location().AnyTimes().Return("testlocation") - s.ClusterName().AnyTimes().Return("cluster-name") - s.AdditionalTags().AnyTimes().Return(infrav1.Tags{}) - s.IsIPv6Enabled().AnyTimes().Return(false) - m.Get(context.TODO(), "my-rg", "my-lb").Return(network.LoadBalancer{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not found")) - mVnet.CheckIPAddressAvailability(context.TODO(), "my-rg", "my-vnet", "10.0.0.10").Return(network.IPAddressAvailabilityResult{Available: to.BoolPtr(true)}, nil) - m.CreateOrUpdate(context.TODO(), "my-rg", "my-lb", gomock.AssignableToTypeOf(network.LoadBalancer{})) - }, - }, - { - name: "internal load balancer retrieval fails", - expectedError: "failed to look for existing internal LB: #: Internal Server Error: StatusCode=500", - expect: func(s *mock_loadbalancers.MockLBScopeMockRecorder, m *mock_loadbalancers.MockClientMockRecorder, mVnet *mock_virtualnetworks.MockClientMockRecorder) { - s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) - s.LBSpecs().Return([]azure.LBSpec{ - { - Name: "my-lb", - SubnetCidrs: []string{"10.0.0.0/16"}, - SubnetName: "my-subnet", - PrivateIPAddress: "10.0.0.10", - Role: infrav1.InternalRole, + Name: "cluster-name", + Role: infrav1.NodeOutboundRole, + Type: infrav1.Public, + BackendPoolName: "cluster-name-outboundBackendPool", + FrontendIPConfigs: []infrav1.FrontendIP{ + { + Name: "cluster-name-frontEnd", + PublicIP: &infrav1.PublicIPSpec{ + Name: "outbound-publicip", + }, + }, + }, }, }) s.SubscriptionID().AnyTimes().Return("123") s.ResourceGroup().AnyTimes().Return("my-rg") - s.Vnet().AnyTimes().Return(&infrav1.VnetSpec{ - ResourceGroup: "my-rg", - Name: "my-vnet", - }) s.Location().AnyTimes().Return("testlocation") s.ClusterName().AnyTimes().Return("cluster-name") s.AdditionalTags().AnyTimes().Return(infrav1.Tags{}) - m.Get(context.TODO(), "my-rg", "my-lb").Return(network.LoadBalancer{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 500}, "Internal Server Error")) - }, - }, - { - name: "internal load balancer exists", - expectedError: "", - expect: func(s *mock_loadbalancers.MockLBScopeMockRecorder, m *mock_loadbalancers.MockClientMockRecorder, mVnet *mock_virtualnetworks.MockClientMockRecorder) { - s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) - s.LBSpecs().Return([]azure.LBSpec{ - { - Name: "my-lb", - SubnetCidrs: []string{"10.0.0.0/16"}, - SubnetName: "my-subnet", - PrivateIPAddress: "10.0.0.10", - Role: infrav1.InternalRole, - APIServerPort: 100, - }, - }) - s.SubscriptionID().AnyTimes().Return("123") - s.ResourceGroup().AnyTimes().Return("my-rg") - s.Vnet().AnyTimes().Return(&infrav1.VnetSpec{ - ResourceGroup: "my-rg", - Name: "my-vnet", - }) - s.Location().AnyTimes().Return("testlocation") - s.ClusterName().AnyTimes().Return("my-cluster") - s.IsIPv6Enabled().AnyTimes().Return(false) - s.AdditionalTags().AnyTimes().Return(infrav1.Tags{}) - m.Get(context.TODO(), "my-rg", "my-lb").Return(network.LoadBalancer{ - LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{ - FrontendIPConfigurations: &[]network.FrontendIPConfiguration{ - { - FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{ - PrivateIPAddress: to.StringPtr("10.0.0.10"), - PrivateIPAllocationMethod: network.Static, - }, - }, - }}}, nil) - m.CreateOrUpdate(context.TODO(), "my-rg", "my-lb", gomockinternal.DiffEq(network.LoadBalancer{ - Sku: &network.LoadBalancerSku{Name: network.LoadBalancerSkuNameStandard}, - Location: to.StringPtr("testlocation"), - Tags: map[string]*string{ - "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"), - "sigs.k8s.io_cluster-api-provider-azure_role": to.StringPtr(infrav1.InternalRole), - }, - LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{ - FrontendIPConfigurations: &[]network.FrontendIPConfiguration{ - { - Name: to.StringPtr("my-lb-frontEnd"), - FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{ - PrivateIPAllocationMethod: network.Static, - PrivateIPAddress: to.StringPtr("10.0.0.10"), - Subnet: &network.Subnet{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")}, - }, - }, + gomock.InOrder( + m.CreateOrUpdate(context.TODO(), "my-rg", "cluster-name", gomockinternal.DiffEq(network.LoadBalancer{ + Tags: map[string]*string{ + "sigs.k8s.io_cluster-api-provider-azure_cluster_cluster-name": to.StringPtr("owned"), + "sigs.k8s.io_cluster-api-provider-azure_role": to.StringPtr(infrav1.NodeOutboundRole), }, - Probes: &[]network.Probe{ - { - Name: to.StringPtr("HTTPSProbe"), - ProbePropertiesFormat: &network.ProbePropertiesFormat{ - Protocol: network.ProbeProtocolHTTPS, - RequestPath: to.StringPtr("/healthz"), - Port: to.Int32Ptr(100), - IntervalInSeconds: to.Int32Ptr(15), - NumberOfProbes: to.Int32Ptr(4), + Sku: &network.LoadBalancerSku{Name: network.LoadBalancerSkuNameStandard}, + Location: to.StringPtr("testlocation"), + LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{ + FrontendIPConfigurations: &[]network.FrontendIPConfiguration{ + { + Name: to.StringPtr("cluster-name-frontEnd"), + FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{ + PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/publicIPAddresses/outbound-publicip")}, + }, }, }, - }, - BackendAddressPools: &[]network.BackendAddressPool{ - { - Name: to.StringPtr("my-lb-backendPool"), + BackendAddressPools: &[]network.BackendAddressPool{ + { + Name: to.StringPtr("cluster-name-outboundBackendPool"), + }, }, - }, - LoadBalancingRules: &[]network.LoadBalancingRule{ - { - Name: to.StringPtr("LBRuleHTTPS"), - LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{ - Protocol: network.TransportProtocolTCP, - FrontendPort: to.Int32Ptr(100), - BackendPort: to.Int32Ptr(100), - IdleTimeoutInMinutes: to.Int32Ptr(4), - EnableFloatingIP: to.BoolPtr(false), - LoadDistribution: network.LoadDistributionDefault, - FrontendIPConfiguration: &network.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-lb/frontendIPConfigurations/my-lb-frontEnd"), - }, - BackendAddressPool: &network.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-lb/backendAddressPools/my-lb-backendPool"), - }, - Probe: &network.SubResource{ - ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-lb/probes/HTTPSProbe"), + OutboundRules: &[]network.OutboundRule{ + { + Name: to.StringPtr("OutboundNATAllProtocols"), + OutboundRulePropertiesFormat: &network.OutboundRulePropertiesFormat{ + FrontendIPConfigurations: &[]network.SubResource{ + {ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/cluster-name/frontendIPConfigurations/cluster-name-frontEnd")}, + }, + BackendAddressPool: &network.SubResource{ + ID: to.StringPtr("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/cluster-name/backendAddressPools/cluster-name-outboundBackendPool"), + }, + Protocol: network.LoadBalancerOutboundRuleProtocolAll, + IdleTimeoutInMinutes: to.Int32Ptr(4), }, }, }, }, - }, - })) - }, - }, - { - name: "internal load balancer does not exist and IP is not available", - expectedError: "IP 10.0.0.10 is not available in VNet my-vnet and there were no other available IPs found", - expect: func(s *mock_loadbalancers.MockLBScopeMockRecorder, m *mock_loadbalancers.MockClientMockRecorder, mVnet *mock_virtualnetworks.MockClientMockRecorder) { - s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) - s.LBSpecs().Return([]azure.LBSpec{ - { - Name: "my-lb", - SubnetCidrs: []string{"10.0.0.0/16"}, - SubnetName: "my-subnet", - PrivateIPAddress: "10.0.0.10", - Role: infrav1.InternalRole, - }, - }) - s.SubscriptionID().AnyTimes().Return("123") - s.ResourceGroup().AnyTimes().Return("my-rg") - s.Vnet().AnyTimes().Return(&infrav1.VnetSpec{ - ResourceGroup: "my-rg", - Name: "my-vnet", - }) - s.Location().AnyTimes().Return("testlocation") - s.ClusterName().AnyTimes().Return("cluster-name") - s.IsIPv6Enabled().AnyTimes().Return(false) - s.AdditionalTags().AnyTimes().Return(infrav1.Tags{}) - m.Get(context.TODO(), "my-rg", "my-lb").Return(network.LoadBalancer{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not found")) - mVnet.CheckIPAddressAvailability(context.TODO(), "my-rg", "my-vnet", "10.0.0.10").Return(network.IPAddressAvailabilityResult{Available: to.BoolPtr(false)}, nil) + })).Return(nil)) }, }, { @@ -403,23 +336,22 @@ func TestReconcileLoadBalancer(t *testing.T) { s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) s.LBSpecs().Return([]azure.LBSpec{ { - Name: "my-lb", - SubnetCidrs: []string{"10.0.0.0/16"}, - SubnetName: "my-subnet", - PrivateIPAddress: "10.0.0.10", - APIServerPort: 6443, - Role: infrav1.InternalRole, + Name: "my-lb", + SubnetName: "my-subnet", + APIServerPort: 6443, + Role: infrav1.APIServerRole, + Type: infrav1.Internal, }, { Name: "my-lb-2", APIServerPort: 6443, - PublicIPName: "my-apiserver-ip", Role: infrav1.APIServerRole, + Type: infrav1.Public, }, { - Name: "my-lb-3", - PublicIPName: "my-node-ip", - Role: infrav1.NodeOutboundRole, + Name: "my-lb-3", + Role: infrav1.NodeOutboundRole, + Type: infrav1.Public, }, }) s.SubscriptionID().AnyTimes().Return("123") @@ -432,8 +364,6 @@ func TestReconcileLoadBalancer(t *testing.T) { s.ClusterName().AnyTimes().Return("cluster-name") s.IsIPv6Enabled().AnyTimes().Return(false) s.AdditionalTags().AnyTimes().Return(infrav1.Tags{}) - m.Get(context.TODO(), "my-rg", "my-lb").Return(network.LoadBalancer{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not found")) - mVnet.CheckIPAddressAvailability(context.TODO(), "my-rg", "my-vnet", "10.0.0.10").Return(network.IPAddressAvailabilityResult{Available: to.BoolPtr(true)}, nil) m.CreateOrUpdate(context.TODO(), "my-rg", "my-lb", gomock.AssignableToTypeOf(network.LoadBalancer{})) m.CreateOrUpdate(context.TODO(), "my-rg", "my-lb-2", gomock.AssignableToTypeOf(network.LoadBalancer{})) m.CreateOrUpdate(context.TODO(), "my-rg", "my-lb-3", gomock.AssignableToTypeOf(network.LoadBalancer{})) @@ -558,49 +488,3 @@ func TestDeleteLoadBalancer(t *testing.T) { }) } } - -func TestGetAvailablePrivateIP(t *testing.T) { - g := NewWithT(t) - - testcases := []struct { - name string - subnetCidrs []string - expectedIP string - expect func(s *mock_loadbalancers.MockLBScopeMockRecorder, mVnet *mock_virtualnetworks.MockClientMockRecorder) - }{ - { - name: "internal load balancer with a valid subnet cidr", - subnetCidrs: []string{"10.0.8.0/16"}, - expectedIP: "10.0.8.0", - expect: func(s *mock_loadbalancers.MockLBScopeMockRecorder, mVnet *mock_virtualnetworks.MockClientMockRecorder) { - mVnet.CheckIPAddressAvailability(context.TODO(), "my-rg", "my-vnet", "10.0.8.0").Return(network.IPAddressAvailabilityResult{Available: to.BoolPtr(true)}, nil) - }, - }, - { - name: "internal load balancer subnet cidr not 8 characters in length", - subnetCidrs: []string{"10.64.8.0"}, - expectedIP: "10.64.8.0", - expect: func(s *mock_loadbalancers.MockLBScopeMockRecorder, mVnet *mock_virtualnetworks.MockClientMockRecorder) { - mVnet.CheckIPAddressAvailability(context.TODO(), "my-rg", "my-vnet", "10.64.8.0").Return(network.IPAddressAvailabilityResult{Available: to.BoolPtr(true)}, nil) - }, - }, - } - for _, tc := range testcases { - t.Run(tc.name, func(t *testing.T) { - mockCtrl := gomock.NewController(t) - scopeMock := mock_loadbalancers.NewMockLBScope(mockCtrl) - vnetMock := mock_virtualnetworks.NewMockClient(mockCtrl) - - tc.expect(scopeMock.EXPECT(), vnetMock.EXPECT()) - - s := &Service{ - Scope: scopeMock, - VirtualNetworksClient: vnetMock, - } - - resultIP, err := s.getAvailablePrivateIP(context.TODO(), "my-rg", "my-vnet", "", tc.subnetCidrs) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(resultIP).To(Equal(tc.expectedIP)) - }) - } -} diff --git a/cloud/types.go b/cloud/types.go index 8f21425faa9..8986cf05768 100644 --- a/cloud/types.go +++ b/cloud/types.go @@ -56,7 +56,6 @@ type LBSpec struct { Role string Type infrav1.LBType SubnetName string - SubnetCidrs []string BackendPoolName string FrontendIPConfigs []infrav1.FrontendIP APIServerPort int32