Skip to content

Commit

Permalink
update UT
Browse files Browse the repository at this point in the history
  • Loading branch information
nawazkh committed Dec 2, 2024
1 parent a9f2643 commit faee040
Show file tree
Hide file tree
Showing 3 changed files with 477 additions and 4 deletions.
6 changes: 4 additions & 2 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,10 @@ func (s *ClusterScope) LBSpecs() []azure.ResourceSpecGetter {
}
}

// set the frontend IPs for the frontend LB and save the LB spec
frontendLB.FrontendIPConfigs = apiServerFrontendLBIP
// set the frontend IPs for the frontend LB and save the LB spec only if there are frontend IPs
if len(apiServerFrontendLBIP) > 0 {
frontendLB.FrontendIPConfigs = apiServerFrontendLBIP
}
specs = append(specs, frontendLB)

if s.APIServerLB().Type != infrav1.Internal && feature.Gates.Enabled(feature.APIServerILB) {
Expand Down
249 changes: 247 additions & 2 deletions azure/scope/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2643,6 +2643,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
}{
Expand Down Expand Up @@ -2741,6 +2742,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",
Expand Down Expand Up @@ -2914,11 +3091,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,
Expand Down
Loading

0 comments on commit faee040

Please sign in to comment.