Skip to content

Commit

Permalink
use feature flag to set default ILB
Browse files Browse the repository at this point in the history
  • Loading branch information
nawazkh committed Dec 2, 2024
1 parent 983bf8b commit 1d605fe
Show file tree
Hide file tree
Showing 4 changed files with 576 additions and 52 deletions.
85 changes: 52 additions & 33 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -247,10 +248,47 @@ func (s *ClusterScope) PublicIPSpecs() []azure.ResourceSpecGetter {
func (s *ClusterScope) LBSpecs() []azure.ResourceSpecGetter {
var specs []azure.ResourceSpecGetter
if s.ControlPlaneEnabled() {
specs = []azure.ResourceSpecGetter{
&loadbalancers.LBSpec{
// API Server LB
Name: s.APIServerLB().Name,
frontendLB := &loadbalancers.LBSpec{
// API Server LB
Name: s.APIServerLB().Name,
ResourceGroup: s.ResourceGroup(),
SubscriptionID: s.SubscriptionID(),
ClusterName: s.ClusterName(),
Location: s.Location(),
ExtendedLocation: s.ExtendedLocation(),
VNetName: s.Vnet().Name,
VNetResourceGroup: s.Vnet().ResourceGroup,
SubnetName: s.ControlPlaneSubnet().Name,
APIServerPort: s.APIServerPort(),
Type: s.APIServerLB().Type,
SKU: s.APIServerLB().SKU,
Role: infrav1.APIServerRole,
BackendPoolName: s.APIServerLB().BackendPool.Name,
IdleTimeoutInMinutes: s.APIServerLB().IdleTimeoutInMinutes,
AdditionalTags: s.AdditionalTags(),
}

// get the internal LB IP and the public LB IP
apiServerFrontendLBIP := make([]infrav1.FrontendIP, 0)
if s.APIServerLB().FrontendIPs != nil {
for _, frontendIP := range s.APIServerLB().FrontendIPs {
// save the public IPs for the frontend LB
// or if the LB is of the type internal, save the only IP allowed for the frontend LB
if frontendIP.PublicIP != nil || frontendLB.Type == infrav1.Internal {
apiServerFrontendLBIP = append(apiServerFrontendLBIP, frontendIP)
}
}
}

// 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) {
internalLB := &loadbalancers.LBSpec{
Name: s.APIServerLB().Name + "-internal",
ResourceGroup: s.ResourceGroup(),
SubscriptionID: s.SubscriptionID(),
ClusterName: s.ClusterName(),
Expand All @@ -259,45 +297,26 @@ func (s *ClusterScope) LBSpecs() []azure.ResourceSpecGetter {
VNetName: s.Vnet().Name,
VNetResourceGroup: s.Vnet().ResourceGroup,
SubnetName: s.ControlPlaneSubnet().Name,
FrontendIPConfigs: s.APIServerLB().FrontendIPs,
APIServerPort: s.APIServerPort(),
Type: s.APIServerLB().Type,
Type: infrav1.Internal,
SKU: s.APIServerLB().SKU,
Role: infrav1.APIServerRole,
BackendPoolName: s.APIServerLB().BackendPool.Name,
Role: infrav1.APIServerRoleInternal,
BackendPoolName: s.APIServerLB().BackendPool.Name + "-internal",
IdleTimeoutInMinutes: s.APIServerLB().IdleTimeoutInMinutes,
AdditionalTags: s.AdditionalTags(),
},
}
}
}

if s.APIServerLB().Type != infrav1.Internal {
specs = append(specs, &loadbalancers.LBSpec{
Name: s.APIServerLB().Name + "-internal",
ResourceGroup: s.ResourceGroup(),
SubscriptionID: s.SubscriptionID(),
ClusterName: s.ClusterName(),
Location: s.Location(),
ExtendedLocation: s.ExtendedLocation(),
VNetName: s.Vnet().Name,
VNetResourceGroup: s.Vnet().ResourceGroup,
SubnetName: s.ControlPlaneSubnet().Name,
FrontendIPConfigs: []infrav1.FrontendIP{
// set the internal IP for the internal LB
internalLB.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,
},
},
},
APIServerPort: s.APIServerPort(),
Type: infrav1.Internal,
SKU: s.APIServerLB().SKU,
Role: infrav1.APIServerRoleInternal,
BackendPoolName: s.APIServerLB().BackendPool.Name + "-internal",
IdleTimeoutInMinutes: s.APIServerLB().IdleTimeoutInMinutes,
AdditionalTags: s.AdditionalTags(),
})
}
specs = append(specs, internalLB)
}
}

// Node outbound LB
Expand Down
Loading

0 comments on commit 1d605fe

Please sign in to comment.