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 Nov 26, 2024
1 parent 983bf8b commit f13bec7
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 48 deletions.
146 changes: 100 additions & 46 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"hash/fnv"
"sigs.k8s.io/cluster-api-provider-azure/feature"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -247,59 +248,112 @@ 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,
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: s.APIServerLB().FrontendIPs,
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
// apiServerLBInternalIP := infrav1.FrontendIP{}
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)
}

//if frontendIP.PrivateIPAddress != "" {

Check failure on line 282 in azure/scope/cluster.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
// apiServerLBInternalIP = frontendIP
//}
}
}

// set the frontend IPs for the frontend LB and save the LB spec
frontendLB.FrontendIPConfigs = apiServerFrontendLBIP
specs := append(specs, frontendLB)

if feature.Gates.Enabled(feature.APIServerILB) {
if s.APIServerLB().Type != infrav1.Internal {
internalLB := &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,
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(),
}

// set the internal IP for the internal LB
// internalLB.FrontendIPConfigs = []infrav1.FrontendIP{apiServerInternalLBIP}
internalLB.FrontendIPConfigs = []infrav1.FrontendIP{
{
Name: s.APIServerLB().Name + "-internal-frontEnd",
FrontendIPClass: infrav1.FrontendIPClass{
PrivateIPAddress: infrav1.DefaultInternalLBIPAddress,
},
},
}
specs = append(specs, internalLB)
}
}

if s.APIServerLB().Type != infrav1.Internal {
specs = append(specs, &loadbalancers.LBSpec{

Check failure on line 328 in azure/scope/cluster.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to specs (ineffassign)
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{
{
Name: s.APIServerLB().Name + "-internal-frontEnd", // TODO: improve this name.
FrontendIPClass: infrav1.FrontendIPClass{
PrivateIPAddress: infrav1.DefaultInternalLBIPAddress,
},
},
},
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{
{
Name: s.APIServerLB().Name + "-internal-frontEnd", // TODO: improve this name.
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(),
})
}

// Node outbound LB
if s.NodeOutboundLB() != nil {
specs = append(specs, &loadbalancers.LBSpec{
Expand Down
7 changes: 5 additions & 2 deletions azure/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"sigs.k8s.io/cluster-api-provider-azure/feature"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2"
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit f13bec7

Please sign in to comment.