Skip to content

Commit 0ea69a2

Browse files
committed
use feature flag to set default ILB
1 parent 983bf8b commit 0ea69a2

File tree

4 files changed

+526
-21
lines changed

4 files changed

+526
-21
lines changed

azure/scope/cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import (
5151
"sigs.k8s.io/cluster-api-provider-azure/azure/services/subnets"
5252
"sigs.k8s.io/cluster-api-provider-azure/azure/services/virtualnetworks"
5353
"sigs.k8s.io/cluster-api-provider-azure/azure/services/vnetpeerings"
54+
"sigs.k8s.io/cluster-api-provider-azure/feature"
5455
"sigs.k8s.io/cluster-api-provider-azure/util/futures"
5556
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
5657
)
@@ -270,8 +271,7 @@ func (s *ClusterScope) LBSpecs() []azure.ResourceSpecGetter {
270271
},
271272
}
272273
}
273-
274-
if s.APIServerLB().Type != infrav1.Internal {
274+
if s.APIServerLB().Type != infrav1.Internal && feature.Gates.Enabled(feature.APIServerILB) {
275275
specs = append(specs, &loadbalancers.LBSpec{
276276
Name: s.APIServerLB().Name + "-internal",
277277
ResourceGroup: s.ResourceGroup(),

azure/scope/cluster_test.go

Lines changed: 293 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import (
3232
corev1 "k8s.io/api/core/v1"
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/runtime"
35+
"k8s.io/component-base/featuregate"
36+
featuregatetesting "k8s.io/component-base/featuregate/testing"
3537
"k8s.io/utils/ptr"
3638
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3739
"sigs.k8s.io/controller-runtime/pkg/client/fake"
@@ -48,6 +50,7 @@ import (
4850
"sigs.k8s.io/cluster-api-provider-azure/azure/services/securitygroups"
4951
"sigs.k8s.io/cluster-api-provider-azure/azure/services/subnets"
5052
"sigs.k8s.io/cluster-api-provider-azure/azure/services/vnetpeerings"
53+
"sigs.k8s.io/cluster-api-provider-azure/feature"
5154
)
5255

5356
const fakeClientID = "fake-client-id"
@@ -2174,6 +2177,7 @@ func TestBackendPoolName(t *testing.T) {
21742177
tests := []struct {
21752178
name string
21762179
clusterName string
2180+
featureGate featuregate.Feature
21772181

21782182
customAPIServerBackendPoolName string
21792183
customNodeBackendPoolName string
@@ -2190,6 +2194,14 @@ func TestBackendPoolName(t *testing.T) {
21902194
expectedNodeBackendPoolName: "NodeOutboundLBName-outboundBackendPool",
21912195
expectedControlPlaneBackendPoolName: "my-cluster-outbound-lb-outboundBackendPool",
21922196
},
2197+
{
2198+
name: "With default backend pool names feature gate enabled",
2199+
clusterName: "my-cluster",
2200+
featureGate: feature.APIServerILB,
2201+
expectedAPIServerBackendPoolName: "APIServerLBName-backendPool",
2202+
expectedNodeBackendPoolName: "NodeOutboundLBName-outboundBackendPool",
2203+
expectedControlPlaneBackendPoolName: "my-cluster-outbound-lb-outboundBackendPool",
2204+
},
21932205
{
21942206
name: "With custom node backend pool name",
21952207
clusterName: "my-cluster",
@@ -2218,6 +2230,9 @@ func TestBackendPoolName(t *testing.T) {
22182230
for _, tc := range tests {
22192231
t.Run(tc.name, func(t *testing.T) {
22202232
g := NewWithT(t)
2233+
if tc.featureGate == feature.APIServerILB {
2234+
defer featuregatetesting.SetFeatureGateDuringTest(t, feature.Gates, tc.featureGate, true)()
2235+
}
22212236

22222237
cluster := &clusterv1.Cluster{
22232238
ObjectMeta: metav1.ObjectMeta{
@@ -2280,27 +2295,43 @@ func TestBackendPoolName(t *testing.T) {
22802295
}
22812296
clusterScope.AzureCluster.SetBackendPoolNameDefault()
22822297
got := clusterScope.LBSpecs()
2283-
g.Expect(got).To(HaveLen(4))
2298+
if tc.featureGate == feature.APIServerILB {
2299+
g.Expect(got).To(HaveLen(4))
2300+
} else {
2301+
g.Expect(got).To(HaveLen(3))
2302+
}
22842303

22852304
// API server backend pool name
22862305
apiServerLBSpec := got[0].(*loadbalancers.LBSpec)
22872306
g.Expect(apiServerLBSpec.BackendPoolName).To(Equal(tc.expectedAPIServerBackendPoolName))
22882307
g.Expect(apiServerLBSpec.Role).To(Equal(infrav1.APIServerRole))
22892308

2290-
// API server backend pool name
2291-
apiServerILBSpec := got[1].(*loadbalancers.LBSpec)
2292-
g.Expect(apiServerILBSpec.BackendPoolName).To(Equal(tc.expectedAPIServerBackendPoolName + "-internal"))
2293-
g.Expect(apiServerILBSpec.Role).To(Equal(infrav1.APIServerRoleInternal))
2294-
2295-
// Node backend pool name
2296-
NodeLBSpec := got[2].(*loadbalancers.LBSpec)
2297-
g.Expect(NodeLBSpec.BackendPoolName).To(Equal(tc.expectedNodeBackendPoolName))
2298-
g.Expect(NodeLBSpec.Role).To(Equal(infrav1.NodeOutboundRole))
2299-
2300-
// Control Plane backend pool name
2301-
controlPlaneLBSpec := got[3].(*loadbalancers.LBSpec)
2302-
g.Expect(controlPlaneLBSpec.BackendPoolName).To(Equal(tc.expectedControlPlaneBackendPoolName))
2303-
g.Expect(controlPlaneLBSpec.Role).To(Equal(infrav1.ControlPlaneOutboundRole))
2309+
if tc.featureGate == feature.APIServerILB {
2310+
// API server backend pool name
2311+
apiServerILBSpec := got[1].(*loadbalancers.LBSpec)
2312+
g.Expect(apiServerILBSpec.BackendPoolName).To(Equal(tc.expectedAPIServerBackendPoolName + "-internal"))
2313+
g.Expect(apiServerILBSpec.Role).To(Equal(infrav1.APIServerRoleInternal))
2314+
2315+
// Node backend pool name
2316+
NodeLBSpec := got[2].(*loadbalancers.LBSpec)
2317+
g.Expect(NodeLBSpec.BackendPoolName).To(Equal(tc.expectedNodeBackendPoolName))
2318+
g.Expect(NodeLBSpec.Role).To(Equal(infrav1.NodeOutboundRole))
2319+
2320+
// Control Plane backend pool name
2321+
controlPlaneLBSpec := got[3].(*loadbalancers.LBSpec)
2322+
g.Expect(controlPlaneLBSpec.BackendPoolName).To(Equal(tc.expectedControlPlaneBackendPoolName))
2323+
g.Expect(controlPlaneLBSpec.Role).To(Equal(infrav1.ControlPlaneOutboundRole))
2324+
} else {
2325+
// Node backend pool name
2326+
NodeLBSpec := got[1].(*loadbalancers.LBSpec)
2327+
g.Expect(NodeLBSpec.BackendPoolName).To(Equal(tc.expectedNodeBackendPoolName))
2328+
g.Expect(NodeLBSpec.Role).To(Equal(infrav1.NodeOutboundRole))
2329+
2330+
// Control Plane backend pool name
2331+
controlPlaneLBSpec := got[2].(*loadbalancers.LBSpec)
2332+
g.Expect(controlPlaneLBSpec.BackendPoolName).To(Equal(tc.expectedControlPlaneBackendPoolName))
2333+
g.Expect(controlPlaneLBSpec.Role).To(Equal(infrav1.ControlPlaneOutboundRole))
2334+
}
23042335
})
23052336
}
23062337
}
@@ -2611,6 +2642,7 @@ func TestFailureDomains(t *testing.T) {
26112642
func TestClusterScope_LBSpecs(t *testing.T) {
26122643
tests := []struct {
26132644
name string
2645+
featureGate featuregate.Feature
26142646
azureCluster *infrav1.AzureCluster
26152647
want []azure.ResourceSpecGetter
26162648
}{
@@ -2709,6 +2741,182 @@ func TestClusterScope_LBSpecs(t *testing.T) {
27092741
},
27102742
},
27112743
},
2744+
want: []azure.ResourceSpecGetter{
2745+
&loadbalancers.LBSpec{
2746+
Name: "api-server-lb",
2747+
ResourceGroup: "my-rg",
2748+
SubscriptionID: "123",
2749+
ClusterName: "my-cluster",
2750+
Location: "westus2",
2751+
VNetName: "my-vnet",
2752+
VNetResourceGroup: "my-rg",
2753+
SubnetName: "cp-subnet",
2754+
FrontendIPConfigs: []infrav1.FrontendIP{
2755+
{
2756+
Name: "api-server-lb-frontend-ip",
2757+
PublicIP: &infrav1.PublicIPSpec{
2758+
Name: "api-server-lb-frontend-ip",
2759+
},
2760+
},
2761+
},
2762+
APIServerPort: 6443,
2763+
Type: infrav1.Public,
2764+
SKU: infrav1.SKUStandard,
2765+
Role: infrav1.APIServerRole,
2766+
BackendPoolName: "api-server-lb-backend-pool",
2767+
IdleTimeoutInMinutes: ptr.To[int32](30),
2768+
AdditionalTags: infrav1.Tags{
2769+
"foo": "bar",
2770+
},
2771+
},
2772+
&loadbalancers.LBSpec{
2773+
Name: "node-outbound-lb",
2774+
ResourceGroup: "my-rg",
2775+
SubscriptionID: "123",
2776+
ClusterName: "my-cluster",
2777+
Location: "westus2",
2778+
VNetName: "my-vnet",
2779+
VNetResourceGroup: "my-rg",
2780+
FrontendIPConfigs: []infrav1.FrontendIP{
2781+
{
2782+
Name: "node-outbound-lb-frontend-ip",
2783+
PublicIP: &infrav1.PublicIPSpec{
2784+
Name: "node-outbound-lb-frontend-ip",
2785+
},
2786+
},
2787+
},
2788+
Type: infrav1.Public,
2789+
SKU: infrav1.SKUStandard,
2790+
Role: infrav1.NodeOutboundRole,
2791+
BackendPoolName: "node-outbound-backend-pool",
2792+
IdleTimeoutInMinutes: ptr.To[int32](50),
2793+
AdditionalTags: infrav1.Tags{
2794+
"foo": "bar",
2795+
},
2796+
},
2797+
&loadbalancers.LBSpec{
2798+
Name: "cp-outbound-lb",
2799+
ResourceGroup: "my-rg",
2800+
SubscriptionID: "123",
2801+
ClusterName: "my-cluster",
2802+
Location: "westus2",
2803+
VNetName: "my-vnet",
2804+
VNetResourceGroup: "my-rg",
2805+
FrontendIPConfigs: []infrav1.FrontendIP{
2806+
{
2807+
Name: "cp-outbound-lb-frontend-ip",
2808+
PublicIP: &infrav1.PublicIPSpec{
2809+
Name: "cp-outbound-lb-frontend-ip",
2810+
},
2811+
},
2812+
},
2813+
Type: infrav1.Public,
2814+
SKU: infrav1.SKUStandard,
2815+
BackendPoolName: "cp-outbound-backend-pool",
2816+
IdleTimeoutInMinutes: ptr.To[int32](15),
2817+
Role: infrav1.ControlPlaneOutboundRole,
2818+
AdditionalTags: infrav1.Tags{
2819+
"foo": "bar",
2820+
},
2821+
},
2822+
},
2823+
},
2824+
{
2825+
name: "API Server LB, Control Plane Oubound LB, and Node Outbound LB with feature gate",
2826+
featureGate: feature.APIServerILB,
2827+
azureCluster: &infrav1.AzureCluster{
2828+
ObjectMeta: metav1.ObjectMeta{
2829+
Name: "my-cluster",
2830+
},
2831+
Spec: infrav1.AzureClusterSpec{
2832+
AzureClusterClassSpec: infrav1.AzureClusterClassSpec{
2833+
AdditionalTags: infrav1.Tags{
2834+
"foo": "bar",
2835+
},
2836+
SubscriptionID: "123",
2837+
Location: "westus2",
2838+
},
2839+
ControlPlaneEnabled: true,
2840+
ResourceGroup: "my-rg",
2841+
NetworkSpec: infrav1.NetworkSpec{
2842+
Vnet: infrav1.VnetSpec{
2843+
Name: "my-vnet",
2844+
ResourceGroup: "my-rg",
2845+
},
2846+
Subnets: []infrav1.SubnetSpec{
2847+
{
2848+
SubnetClassSpec: infrav1.SubnetClassSpec{
2849+
Name: "cp-subnet",
2850+
Role: infrav1.SubnetControlPlane,
2851+
},
2852+
},
2853+
{
2854+
SubnetClassSpec: infrav1.SubnetClassSpec{
2855+
Name: "node-subnet",
2856+
Role: infrav1.SubnetNode,
2857+
},
2858+
},
2859+
},
2860+
APIServerLB: &infrav1.LoadBalancerSpec{
2861+
Name: "api-server-lb",
2862+
BackendPool: infrav1.BackendPool{
2863+
Name: "api-server-lb-backend-pool",
2864+
},
2865+
LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{
2866+
Type: infrav1.Public,
2867+
IdleTimeoutInMinutes: ptr.To[int32](30),
2868+
SKU: infrav1.SKUStandard,
2869+
},
2870+
FrontendIPs: []infrav1.FrontendIP{
2871+
{
2872+
Name: "api-server-lb-frontend-ip",
2873+
PublicIP: &infrav1.PublicIPSpec{
2874+
Name: "api-server-lb-frontend-ip",
2875+
},
2876+
},
2877+
},
2878+
},
2879+
ControlPlaneOutboundLB: &infrav1.LoadBalancerSpec{
2880+
Name: "cp-outbound-lb",
2881+
BackendPool: infrav1.BackendPool{
2882+
Name: "cp-outbound-backend-pool",
2883+
},
2884+
LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{
2885+
Type: infrav1.Public,
2886+
IdleTimeoutInMinutes: ptr.To[int32](15),
2887+
SKU: infrav1.SKUStandard,
2888+
},
2889+
FrontendIPs: []infrav1.FrontendIP{
2890+
{
2891+
Name: "cp-outbound-lb-frontend-ip",
2892+
PublicIP: &infrav1.PublicIPSpec{
2893+
Name: "cp-outbound-lb-frontend-ip",
2894+
},
2895+
},
2896+
},
2897+
},
2898+
NodeOutboundLB: &infrav1.LoadBalancerSpec{
2899+
Name: "node-outbound-lb",
2900+
BackendPool: infrav1.BackendPool{
2901+
Name: "node-outbound-backend-pool",
2902+
},
2903+
LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{
2904+
Type: infrav1.Public,
2905+
IdleTimeoutInMinutes: ptr.To[int32](50),
2906+
SKU: infrav1.SKUStandard,
2907+
},
2908+
FrontendIPs: []infrav1.FrontendIP{
2909+
{
2910+
Name: "node-outbound-lb-frontend-ip",
2911+
PublicIP: &infrav1.PublicIPSpec{
2912+
Name: "node-outbound-lb-frontend-ip",
2913+
},
2914+
},
2915+
},
2916+
},
2917+
},
2918+
},
2919+
},
27122920
want: []azure.ResourceSpecGetter{
27132921
&loadbalancers.LBSpec{
27142922
Name: "api-server-lb",
@@ -2882,11 +3090,79 @@ func TestClusterScope_LBSpecs(t *testing.T) {
28823090
},
28833091
},
28843092
},
3093+
{
3094+
name: "Private API Server LB",
3095+
featureGate: feature.APIServerILB,
3096+
azureCluster: &infrav1.AzureCluster{
3097+
ObjectMeta: metav1.ObjectMeta{
3098+
Name: "my-cluster",
3099+
},
3100+
Spec: infrav1.AzureClusterSpec{
3101+
AzureClusterClassSpec: infrav1.AzureClusterClassSpec{
3102+
SubscriptionID: "123",
3103+
Location: "westus2",
3104+
},
3105+
ControlPlaneEnabled: true,
3106+
ResourceGroup: "my-rg",
3107+
NetworkSpec: infrav1.NetworkSpec{
3108+
Vnet: infrav1.VnetSpec{
3109+
Name: "my-vnet",
3110+
ResourceGroup: "my-rg",
3111+
},
3112+
Subnets: []infrav1.SubnetSpec{
3113+
{
3114+
SubnetClassSpec: infrav1.SubnetClassSpec{
3115+
Name: "cp-subnet",
3116+
Role: infrav1.SubnetControlPlane,
3117+
},
3118+
},
3119+
{
3120+
SubnetClassSpec: infrav1.SubnetClassSpec{
3121+
Name: "node-subnet",
3122+
Role: infrav1.SubnetNode,
3123+
},
3124+
},
3125+
},
3126+
APIServerLB: &infrav1.LoadBalancerSpec{
3127+
Name: "api-server-lb",
3128+
BackendPool: infrav1.BackendPool{
3129+
Name: "api-server-lb-backend-pool",
3130+
},
3131+
LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{
3132+
Type: infrav1.Internal,
3133+
IdleTimeoutInMinutes: ptr.To[int32](30),
3134+
SKU: infrav1.SKUStandard,
3135+
},
3136+
},
3137+
},
3138+
},
3139+
},
3140+
want: []azure.ResourceSpecGetter{
3141+
&loadbalancers.LBSpec{
3142+
Name: "api-server-lb",
3143+
ResourceGroup: "my-rg",
3144+
SubscriptionID: "123",
3145+
ClusterName: "my-cluster",
3146+
Location: "westus2",
3147+
VNetName: "my-vnet",
3148+
VNetResourceGroup: "my-rg",
3149+
SubnetName: "cp-subnet",
3150+
APIServerPort: 6443,
3151+
Type: infrav1.Internal,
3152+
SKU: infrav1.SKUStandard,
3153+
Role: infrav1.APIServerRole,
3154+
BackendPoolName: "api-server-lb-backend-pool",
3155+
IdleTimeoutInMinutes: ptr.To[int32](30),
3156+
AdditionalTags: infrav1.Tags{},
3157+
},
3158+
},
3159+
},
28853160
}
28863161
for _, tc := range tests {
28873162
t.Run(tc.name, func(t *testing.T) {
2888-
t.Parallel()
2889-
3163+
if tc.featureGate == feature.APIServerILB {
3164+
defer featuregatetesting.SetFeatureGateDuringTest(t, feature.Gates, tc.featureGate, true)()
3165+
}
28903166
cluster := &clusterv1.Cluster{
28913167
ObjectMeta: metav1.ObjectMeta{
28923168
Name: tc.azureCluster.Name,

0 commit comments

Comments
 (0)