From 9e35b02afa12c409304bb6606a75097d09cd4ee8 Mon Sep 17 00:00:00 2001 From: Nawaz Hussain Khazielakha Date: Tue, 26 Nov 2024 10:51:28 -0800 Subject: [PATCH] use feature flag to set default ILB --- azure/scope/cluster.go | 6 +- azure/scope/cluster_test.go | 310 ++++++++++++++++++++++++++++++++++-- azure/scope/machine.go | 7 +- azure/scope/machine_test.go | 226 ++++++++++++++++++++++++++ 4 files changed, 527 insertions(+), 22 deletions(-) diff --git a/azure/scope/cluster.go b/azure/scope/cluster.go index dcbe671d650..d276fdc90d1 100644 --- a/azure/scope/cluster.go +++ b/azure/scope/cluster.go @@ -51,6 +51,7 @@ import ( "sigs.k8s.io/cluster-api-provider-azure/azure/services/subnets" "sigs.k8s.io/cluster-api-provider-azure/azure/services/virtualnetworks" "sigs.k8s.io/cluster-api-provider-azure/azure/services/vnetpeerings" + "sigs.k8s.io/cluster-api-provider-azure/feature" "sigs.k8s.io/cluster-api-provider-azure/util/futures" "sigs.k8s.io/cluster-api-provider-azure/util/tele" ) @@ -270,8 +271,7 @@ func (s *ClusterScope) LBSpecs() []azure.ResourceSpecGetter { }, } } - - if s.APIServerLB().Type != infrav1.Internal { + if s.APIServerLB().Type != infrav1.Internal && feature.Gates.Enabled(feature.APIServerILB) { specs = append(specs, &loadbalancers.LBSpec{ Name: s.APIServerLB().Name + "-internal", ResourceGroup: s.ResourceGroup(), @@ -284,7 +284,7 @@ func (s *ClusterScope) LBSpecs() []azure.ResourceSpecGetter { SubnetName: s.ControlPlaneSubnet().Name, FrontendIPConfigs: []infrav1.FrontendIP{ { - Name: s.APIServerLB().Name + "-internal-frontEnd", // TODO: improve this name. + Name: s.APIServerLB().Name + "-internal-frontEnd", FrontendIPClass: infrav1.FrontendIPClass{ PrivateIPAddress: infrav1.DefaultInternalLBIPAddress, }, diff --git a/azure/scope/cluster_test.go b/azure/scope/cluster_test.go index 9ad59fd6b52..c2636b654e3 100644 --- a/azure/scope/cluster_test.go +++ b/azure/scope/cluster_test.go @@ -32,6 +32,8 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/component-base/featuregate" + featuregatetesting "k8s.io/component-base/featuregate/testing" "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client/fake" @@ -48,6 +50,7 @@ import ( "sigs.k8s.io/cluster-api-provider-azure/azure/services/securitygroups" "sigs.k8s.io/cluster-api-provider-azure/azure/services/subnets" "sigs.k8s.io/cluster-api-provider-azure/azure/services/vnetpeerings" + "sigs.k8s.io/cluster-api-provider-azure/feature" ) const fakeClientID = "fake-client-id" @@ -2174,6 +2177,7 @@ func TestBackendPoolName(t *testing.T) { tests := []struct { name string clusterName string + featureGate featuregate.Feature customAPIServerBackendPoolName string customNodeBackendPoolName string @@ -2190,6 +2194,14 @@ func TestBackendPoolName(t *testing.T) { expectedNodeBackendPoolName: "NodeOutboundLBName-outboundBackendPool", expectedControlPlaneBackendPoolName: "my-cluster-outbound-lb-outboundBackendPool", }, + { + name: "With default backend pool names feature gate enabled", + clusterName: "my-cluster", + featureGate: feature.APIServerILB, + expectedAPIServerBackendPoolName: "APIServerLBName-backendPool", + expectedNodeBackendPoolName: "NodeOutboundLBName-outboundBackendPool", + expectedControlPlaneBackendPoolName: "my-cluster-outbound-lb-outboundBackendPool", + }, { name: "With custom node backend pool name", clusterName: "my-cluster", @@ -2218,6 +2230,9 @@ func TestBackendPoolName(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) + if tc.featureGate == feature.APIServerILB { + defer featuregatetesting.SetFeatureGateDuringTest(t, feature.Gates, tc.featureGate, true)() + } cluster := &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ @@ -2280,27 +2295,43 @@ func TestBackendPoolName(t *testing.T) { } clusterScope.AzureCluster.SetBackendPoolNameDefault() got := clusterScope.LBSpecs() - g.Expect(got).To(HaveLen(4)) + if tc.featureGate == feature.APIServerILB { + g.Expect(got).To(HaveLen(4)) + } else { + g.Expect(got).To(HaveLen(3)) + } // API server backend pool name apiServerLBSpec := got[0].(*loadbalancers.LBSpec) g.Expect(apiServerLBSpec.BackendPoolName).To(Equal(tc.expectedAPIServerBackendPoolName)) g.Expect(apiServerLBSpec.Role).To(Equal(infrav1.APIServerRole)) - // API server backend pool name - apiServerILBSpec := got[1].(*loadbalancers.LBSpec) - g.Expect(apiServerILBSpec.BackendPoolName).To(Equal(tc.expectedAPIServerBackendPoolName + "-internal")) - g.Expect(apiServerILBSpec.Role).To(Equal(infrav1.APIServerRoleInternal)) - - // Node backend pool name - NodeLBSpec := got[2].(*loadbalancers.LBSpec) - g.Expect(NodeLBSpec.BackendPoolName).To(Equal(tc.expectedNodeBackendPoolName)) - g.Expect(NodeLBSpec.Role).To(Equal(infrav1.NodeOutboundRole)) - - // Control Plane backend pool name - controlPlaneLBSpec := got[3].(*loadbalancers.LBSpec) - g.Expect(controlPlaneLBSpec.BackendPoolName).To(Equal(tc.expectedControlPlaneBackendPoolName)) - g.Expect(controlPlaneLBSpec.Role).To(Equal(infrav1.ControlPlaneOutboundRole)) + if tc.featureGate == feature.APIServerILB { + // API server backend pool name + apiServerILBSpec := got[1].(*loadbalancers.LBSpec) + g.Expect(apiServerILBSpec.BackendPoolName).To(Equal(tc.expectedAPIServerBackendPoolName + "-internal")) + g.Expect(apiServerILBSpec.Role).To(Equal(infrav1.APIServerRoleInternal)) + + // Node backend pool name + NodeLBSpec := got[2].(*loadbalancers.LBSpec) + g.Expect(NodeLBSpec.BackendPoolName).To(Equal(tc.expectedNodeBackendPoolName)) + g.Expect(NodeLBSpec.Role).To(Equal(infrav1.NodeOutboundRole)) + + // Control Plane backend pool name + controlPlaneLBSpec := got[3].(*loadbalancers.LBSpec) + g.Expect(controlPlaneLBSpec.BackendPoolName).To(Equal(tc.expectedControlPlaneBackendPoolName)) + g.Expect(controlPlaneLBSpec.Role).To(Equal(infrav1.ControlPlaneOutboundRole)) + } else { + // Node backend pool name + NodeLBSpec := got[1].(*loadbalancers.LBSpec) + g.Expect(NodeLBSpec.BackendPoolName).To(Equal(tc.expectedNodeBackendPoolName)) + g.Expect(NodeLBSpec.Role).To(Equal(infrav1.NodeOutboundRole)) + + // Control Plane backend pool name + controlPlaneLBSpec := got[2].(*loadbalancers.LBSpec) + g.Expect(controlPlaneLBSpec.BackendPoolName).To(Equal(tc.expectedControlPlaneBackendPoolName)) + g.Expect(controlPlaneLBSpec.Role).To(Equal(infrav1.ControlPlaneOutboundRole)) + } }) } } @@ -2611,6 +2642,7 @@ func TestFailureDomains(t *testing.T) { func TestClusterScope_LBSpecs(t *testing.T) { tests := []struct { name string + featureGate featuregate.Feature azureCluster *infrav1.AzureCluster want []azure.ResourceSpecGetter }{ @@ -2709,6 +2741,182 @@ func TestClusterScope_LBSpecs(t *testing.T) { }, }, }, + want: []azure.ResourceSpecGetter{ + &loadbalancers.LBSpec{ + Name: "api-server-lb", + ResourceGroup: "my-rg", + SubscriptionID: "123", + ClusterName: "my-cluster", + Location: "westus2", + VNetName: "my-vnet", + VNetResourceGroup: "my-rg", + SubnetName: "cp-subnet", + FrontendIPConfigs: []infrav1.FrontendIP{ + { + Name: "api-server-lb-frontend-ip", + PublicIP: &infrav1.PublicIPSpec{ + Name: "api-server-lb-frontend-ip", + }, + }, + }, + APIServerPort: 6443, + Type: infrav1.Public, + SKU: infrav1.SKUStandard, + Role: infrav1.APIServerRole, + BackendPoolName: "api-server-lb-backend-pool", + IdleTimeoutInMinutes: ptr.To[int32](30), + AdditionalTags: infrav1.Tags{ + "foo": "bar", + }, + }, + &loadbalancers.LBSpec{ + Name: "node-outbound-lb", + ResourceGroup: "my-rg", + SubscriptionID: "123", + ClusterName: "my-cluster", + Location: "westus2", + VNetName: "my-vnet", + VNetResourceGroup: "my-rg", + FrontendIPConfigs: []infrav1.FrontendIP{ + { + Name: "node-outbound-lb-frontend-ip", + PublicIP: &infrav1.PublicIPSpec{ + Name: "node-outbound-lb-frontend-ip", + }, + }, + }, + Type: infrav1.Public, + SKU: infrav1.SKUStandard, + Role: infrav1.NodeOutboundRole, + BackendPoolName: "node-outbound-backend-pool", + IdleTimeoutInMinutes: ptr.To[int32](50), + AdditionalTags: infrav1.Tags{ + "foo": "bar", + }, + }, + &loadbalancers.LBSpec{ + Name: "cp-outbound-lb", + ResourceGroup: "my-rg", + SubscriptionID: "123", + ClusterName: "my-cluster", + Location: "westus2", + VNetName: "my-vnet", + VNetResourceGroup: "my-rg", + FrontendIPConfigs: []infrav1.FrontendIP{ + { + Name: "cp-outbound-lb-frontend-ip", + PublicIP: &infrav1.PublicIPSpec{ + Name: "cp-outbound-lb-frontend-ip", + }, + }, + }, + Type: infrav1.Public, + SKU: infrav1.SKUStandard, + BackendPoolName: "cp-outbound-backend-pool", + IdleTimeoutInMinutes: ptr.To[int32](15), + Role: infrav1.ControlPlaneOutboundRole, + AdditionalTags: infrav1.Tags{ + "foo": "bar", + }, + }, + }, + }, + { + name: "API Server LB, Control Plane Oubound LB, and Node Outbound LB with feature gate", + featureGate: feature.APIServerILB, + azureCluster: &infrav1.AzureCluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-cluster", + }, + Spec: infrav1.AzureClusterSpec{ + AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ + AdditionalTags: infrav1.Tags{ + "foo": "bar", + }, + SubscriptionID: "123", + Location: "westus2", + }, + ControlPlaneEnabled: true, + ResourceGroup: "my-rg", + NetworkSpec: infrav1.NetworkSpec{ + Vnet: infrav1.VnetSpec{ + Name: "my-vnet", + ResourceGroup: "my-rg", + }, + Subnets: []infrav1.SubnetSpec{ + { + SubnetClassSpec: infrav1.SubnetClassSpec{ + Name: "cp-subnet", + Role: infrav1.SubnetControlPlane, + }, + }, + { + SubnetClassSpec: infrav1.SubnetClassSpec{ + Name: "node-subnet", + Role: infrav1.SubnetNode, + }, + }, + }, + APIServerLB: &infrav1.LoadBalancerSpec{ + Name: "api-server-lb", + BackendPool: infrav1.BackendPool{ + Name: "api-server-lb-backend-pool", + }, + LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{ + Type: infrav1.Public, + IdleTimeoutInMinutes: ptr.To[int32](30), + SKU: infrav1.SKUStandard, + }, + FrontendIPs: []infrav1.FrontendIP{ + { + Name: "api-server-lb-frontend-ip", + PublicIP: &infrav1.PublicIPSpec{ + Name: "api-server-lb-frontend-ip", + }, + }, + }, + }, + ControlPlaneOutboundLB: &infrav1.LoadBalancerSpec{ + Name: "cp-outbound-lb", + BackendPool: infrav1.BackendPool{ + Name: "cp-outbound-backend-pool", + }, + LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{ + Type: infrav1.Public, + IdleTimeoutInMinutes: ptr.To[int32](15), + SKU: infrav1.SKUStandard, + }, + FrontendIPs: []infrav1.FrontendIP{ + { + Name: "cp-outbound-lb-frontend-ip", + PublicIP: &infrav1.PublicIPSpec{ + Name: "cp-outbound-lb-frontend-ip", + }, + }, + }, + }, + NodeOutboundLB: &infrav1.LoadBalancerSpec{ + Name: "node-outbound-lb", + BackendPool: infrav1.BackendPool{ + Name: "node-outbound-backend-pool", + }, + LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{ + Type: infrav1.Public, + IdleTimeoutInMinutes: ptr.To[int32](50), + SKU: infrav1.SKUStandard, + }, + FrontendIPs: []infrav1.FrontendIP{ + { + Name: "node-outbound-lb-frontend-ip", + PublicIP: &infrav1.PublicIPSpec{ + Name: "node-outbound-lb-frontend-ip", + }, + }, + }, + }, + }, + }, + }, want: []azure.ResourceSpecGetter{ &loadbalancers.LBSpec{ Name: "api-server-lb", @@ -2882,11 +3090,79 @@ func TestClusterScope_LBSpecs(t *testing.T) { }, }, }, + { + name: "Private API Server LB", + featureGate: feature.APIServerILB, + azureCluster: &infrav1.AzureCluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-cluster", + }, + Spec: infrav1.AzureClusterSpec{ + AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ + SubscriptionID: "123", + Location: "westus2", + }, + ControlPlaneEnabled: true, + ResourceGroup: "my-rg", + NetworkSpec: infrav1.NetworkSpec{ + Vnet: infrav1.VnetSpec{ + Name: "my-vnet", + ResourceGroup: "my-rg", + }, + Subnets: []infrav1.SubnetSpec{ + { + SubnetClassSpec: infrav1.SubnetClassSpec{ + Name: "cp-subnet", + Role: infrav1.SubnetControlPlane, + }, + }, + { + SubnetClassSpec: infrav1.SubnetClassSpec{ + Name: "node-subnet", + Role: infrav1.SubnetNode, + }, + }, + }, + APIServerLB: &infrav1.LoadBalancerSpec{ + Name: "api-server-lb", + BackendPool: infrav1.BackendPool{ + Name: "api-server-lb-backend-pool", + }, + LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{ + Type: infrav1.Internal, + IdleTimeoutInMinutes: ptr.To[int32](30), + SKU: infrav1.SKUStandard, + }, + }, + }, + }, + }, + want: []azure.ResourceSpecGetter{ + &loadbalancers.LBSpec{ + Name: "api-server-lb", + ResourceGroup: "my-rg", + SubscriptionID: "123", + ClusterName: "my-cluster", + Location: "westus2", + VNetName: "my-vnet", + VNetResourceGroup: "my-rg", + SubnetName: "cp-subnet", + APIServerPort: 6443, + Type: infrav1.Internal, + SKU: infrav1.SKUStandard, + Role: infrav1.APIServerRole, + BackendPoolName: "api-server-lb-backend-pool", + IdleTimeoutInMinutes: ptr.To[int32](30), + AdditionalTags: infrav1.Tags{}, + }, + }, + }, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - t.Parallel() - + if tc.featureGate == feature.APIServerILB { + defer featuregatetesting.SetFeatureGateDuringTest(t, feature.Gates, tc.featureGate, true)() + } cluster := &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: tc.azureCluster.Name, diff --git a/azure/scope/machine.go b/azure/scope/machine.go index 971f5cf8696..8e96dae2179 100644 --- a/azure/scope/machine.go +++ b/azure/scope/machine.go @@ -47,6 +47,7 @@ import ( "sigs.k8s.io/cluster-api-provider-azure/azure/services/virtualmachineimages" "sigs.k8s.io/cluster-api-provider-azure/azure/services/virtualmachines" "sigs.k8s.io/cluster-api-provider-azure/azure/services/vmextensions" + "sigs.k8s.io/cluster-api-provider-azure/feature" azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure" "sigs.k8s.io/cluster-api-provider-azure/util/futures" "sigs.k8s.io/cluster-api-provider-azure/util/tele" @@ -298,8 +299,10 @@ func (m *MachineScope) BuildNICSpec(nicName string, infrav1NetworkInterface infr spec.InternalLBName = m.APIServerLBName() spec.InternalLBAddressPoolName = m.APIServerLBPoolName() } else { - spec.InternalLBName = m.APIServerLBName() + "-internal" - spec.InternalLBAddressPoolName = m.APIServerLBPoolName() + "-internal" + if feature.Gates.Enabled(feature.APIServerILB) { + spec.InternalLBName = m.APIServerLBName() + "-internal" + spec.InternalLBAddressPoolName = m.APIServerLBPoolName() + "-internal" + } spec.PublicLBNATRuleName = m.Name() spec.PublicLBAddressPoolName = m.APIServerLBPoolName() } diff --git a/azure/scope/machine_test.go b/azure/scope/machine_test.go index b399c6aaf61..7c6a30011a7 100644 --- a/azure/scope/machine_test.go +++ b/azure/scope/machine_test.go @@ -30,6 +30,8 @@ import ( "go.uber.org/mock/gomock" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/component-base/featuregate" + featuregatetesting "k8s.io/component-base/featuregate/testing" "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" @@ -44,6 +46,7 @@ import ( "sigs.k8s.io/cluster-api-provider-azure/azure/services/roleassignments" "sigs.k8s.io/cluster-api-provider-azure/azure/services/virtualmachineimages" "sigs.k8s.io/cluster-api-provider-azure/azure/services/vmextensions" + "sigs.k8s.io/cluster-api-provider-azure/feature" ) func TestMachineScope_Name(t *testing.T) { @@ -1730,6 +1733,7 @@ func TestMachineScope_GetVMImage(t *testing.T) { func TestMachineScope_NICSpecs(t *testing.T) { tests := []struct { name string + featureGate featuregate.Feature machineScope MachineScope want []azure.ResourceSpecGetter }{ @@ -2362,6 +2366,115 @@ func TestMachineScope_NICSpecs(t *testing.T) { }, }, }, + want: []azure.ResourceSpecGetter{ + &networkinterfaces.NICSpec{ + Name: "machine-name-nic", + ResourceGroup: "my-rg", + Location: "westus", + SubscriptionID: "123", + MachineName: "machine-name", + SubnetName: "subnet1", + IPConfigs: []networkinterfaces.IPConfig{{}}, + VNetName: "vnet1", + VNetResourceGroup: "rg1", + PublicLBName: "api-lb", + PublicLBAddressPoolName: "api-lb-backendPool", + PublicLBNATRuleName: "machine-name", + PublicIPName: "", + AcceleratedNetworking: nil, + DNSServers: nil, + IPv6Enabled: false, + EnableIPForwarding: false, + SKU: nil, + ClusterName: "cluster", + AdditionalTags: infrav1.Tags{ + "kubernetes.io_cluster_cluster": "owned", + }, + }, + }, + }, + { + name: "Control Plane Machine with public LB with feature gate API Server ILB enabled", + featureGate: feature.APIServerILB, + machineScope: MachineScope{ + ClusterScoper: &ClusterScope{ + AzureClients: AzureClients{ + EnvironmentSettings: auth.EnvironmentSettings{ + Values: map[string]string{ + auth.SubscriptionID: "123", + }, + }, + }, + Cluster: &clusterv1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster", + Namespace: "default", + }, + }, + AzureCluster: &infrav1.AzureCluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster", + Namespace: "default", + OwnerReferences: []metav1.OwnerReference{ + { + APIVersion: "cluster.x-k8s.io/v1beta1", + Kind: "Cluster", + Name: "cluster", + }, + }, + }, + Spec: infrav1.AzureClusterSpec{ + ResourceGroup: "my-rg", + AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ + Location: "westus", + }, + NetworkSpec: infrav1.NetworkSpec{ + Vnet: infrav1.VnetSpec{ + Name: "vnet1", + ResourceGroup: "rg1", + }, + Subnets: []infrav1.SubnetSpec{ + { + SubnetClassSpec: infrav1.SubnetClassSpec{ + Role: infrav1.SubnetNode, + Name: "subnet1", + }, + }, + }, + APIServerLB: &infrav1.LoadBalancerSpec{ + Name: "api-lb", + BackendPool: infrav1.BackendPool{ + Name: "api-lb-backendPool", + }, + }, + NodeOutboundLB: &infrav1.LoadBalancerSpec{ + Name: "outbound-lb", + }, + }, + }, + }, + }, + AzureMachine: &infrav1.AzureMachine{ + ObjectMeta: metav1.ObjectMeta{ + Name: "machine", + }, + Spec: infrav1.AzureMachineSpec{ + ProviderID: ptr.To("azure:///subscriptions/1234-5678/resourceGroups/my-cluster/providers/Microsoft.Compute/virtualMachines/machine-name"), + NetworkInterfaces: []infrav1.NetworkInterface{{ + SubnetName: "subnet1", + PrivateIPConfigs: 1, + }}, + }, + }, + Machine: &clusterv1.Machine{ + ObjectMeta: metav1.ObjectMeta{ + Name: "machine", + Labels: map[string]string{ + clusterv1.MachineControlPlaneLabel: "true", + }, + }, + }, + }, want: []azure.ResourceSpecGetter{ &networkinterfaces.NICSpec{ Name: "machine-name-nic", @@ -2473,6 +2586,116 @@ func TestMachineScope_NICSpecs(t *testing.T) { }, }, }, + want: []azure.ResourceSpecGetter{ + &networkinterfaces.NICSpec{ + Name: "machine-name-nic", + ResourceGroup: "my-rg", + Location: "westus", + SubscriptionID: "123", + MachineName: "machine-name", + SubnetName: "subnet1", + IPConfigs: []networkinterfaces.IPConfig{{}}, + VNetName: "vnet1", + VNetResourceGroup: "rg1", + PublicLBName: "api-lb", + PublicLBAddressPoolName: "api-lb-backendPool", + PublicLBNATRuleName: "machine-name", + PublicIPName: "", + AcceleratedNetworking: nil, + DNSServers: []string{"123.123.123.123", "124.124.124.124"}, + IPv6Enabled: false, + EnableIPForwarding: false, + SKU: nil, + ClusterName: "cluster", + AdditionalTags: infrav1.Tags{ + "kubernetes.io_cluster_cluster": "owned", + }, + }, + }, + }, + { + name: "Control Plane Machine with public LB and Custom DNS Servers with feature gate API Server ILB enabled", + featureGate: feature.APIServerILB, + machineScope: MachineScope{ + ClusterScoper: &ClusterScope{ + AzureClients: AzureClients{ + EnvironmentSettings: auth.EnvironmentSettings{ + Values: map[string]string{ + auth.SubscriptionID: "123", + }, + }, + }, + Cluster: &clusterv1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster", + Namespace: "default", + }, + }, + AzureCluster: &infrav1.AzureCluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster", + Namespace: "default", + OwnerReferences: []metav1.OwnerReference{ + { + APIVersion: "cluster.x-k8s.io/v1beta1", + Kind: "Cluster", + Name: "cluster", + }, + }, + }, + Spec: infrav1.AzureClusterSpec{ + ResourceGroup: "my-rg", + AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ + Location: "westus", + }, + NetworkSpec: infrav1.NetworkSpec{ + Vnet: infrav1.VnetSpec{ + Name: "vnet1", + ResourceGroup: "rg1", + }, + Subnets: []infrav1.SubnetSpec{ + { + SubnetClassSpec: infrav1.SubnetClassSpec{ + Role: infrav1.SubnetNode, + Name: "subnet1", + }, + }, + }, + APIServerLB: &infrav1.LoadBalancerSpec{ + Name: "api-lb", + BackendPool: infrav1.BackendPool{ + Name: "api-lb-backendPool", + }, + }, + NodeOutboundLB: &infrav1.LoadBalancerSpec{ + Name: "outbound-lb", + }, + }, + }, + }, + }, + AzureMachine: &infrav1.AzureMachine{ + ObjectMeta: metav1.ObjectMeta{ + Name: "machine", + }, + Spec: infrav1.AzureMachineSpec{ + ProviderID: ptr.To("azure:///subscriptions/1234-5678/resourceGroups/my-cluster/providers/Microsoft.Compute/virtualMachines/machine-name"), + NetworkInterfaces: []infrav1.NetworkInterface{{ + SubnetName: "subnet1", + PrivateIPConfigs: 1, + }}, + DNSServers: []string{"123.123.123.123", "124.124.124.124"}, + }, + }, + Machine: &clusterv1.Machine{ + ObjectMeta: metav1.ObjectMeta{ + Name: "machine", + Labels: map[string]string{ + clusterv1.MachineControlPlaneLabel: "true", + }, + }, + }, + }, want: []azure.ResourceSpecGetter{ &networkinterfaces.NICSpec{ Name: "machine-name-nic", @@ -2894,6 +3117,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) + if tt.featureGate == feature.APIServerILB { + defer featuregatetesting.SetFeatureGateDuringTest(t, feature.Gates, tt.featureGate, true)() + } gotNicSpecs := tt.machineScope.NICSpecs() if !reflect.DeepEqual(gotNicSpecs, tt.want) { g.Expect(gotNicSpecs).To(BeEquivalentTo(tt.want))