Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update cluster.go
Browse files Browse the repository at this point in the history
nawazkh committed Dec 4, 2024
1 parent 8e2c02a commit 0f56695
Showing 2 changed files with 47 additions and 33 deletions.
78 changes: 46 additions & 32 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
@@ -268,49 +268,63 @@ func (s *ClusterScope) LBSpecs() []azure.ResourceSpecGetter {
AdditionalTags: s.AdditionalTags(),
}

// get the internal LB IP and the public LB IP
apiServerFrontendLBIP := make([]infrav1.FrontendIP, 0)
apiServerLBInternalIP := infrav1.FrontendIP{}
if s.APIServerLB().FrontendIPs != nil {
for _, frontendIP := range s.APIServerLB().FrontendIPs {
// save the public IPs for the frontend LB
// save the public IP 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 != "" {
apiServerLBInternalIP = frontendIP
frontendLB.FrontendIPConfigs = []infrav1.FrontendIP{frontendIP}
break
}
}
}
specs = append(specs, frontendLB)
}

// 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
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(),
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(),
}
specs = append(specs, frontendLB)

if s.APIServerLB().Type != infrav1.Internal && feature.Gates.Enabled(feature.APIServerILB) {
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{apiServerLBInternalIP},
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(),
})
privateIPFound := false
if s.APIServerLB().FrontendIPs != nil {
for _, frontendIP := range s.APIServerLB().FrontendIPs {
if frontendIP.PrivateIPAddress != "" {
internalLB.FrontendIPConfigs = []infrav1.FrontendIP{frontendIP}
privateIPFound = true
break
}
}
}

if !privateIPFound {
// If no private IP is found, use the default internal LB IP
// useful for scenarios where the user has not specified a private IP and is upgrading from a version that did not support it
internalLB.FrontendIPConfigs = []infrav1.FrontendIP{
{
Name: s.APIServerLB().Name + "-internal-ip",
FrontendIPClass: infrav1.FrontendIPClass{
PrivateIPAddress: infrav1.DefaultInternalLBIPAddress,
},
},
}
}
specs = append(specs, internalLB)
}

// Node outbound LB
2 changes: 1 addition & 1 deletion azure/scope/cluster_test.go
Original file line number Diff line number Diff line change
@@ -2956,7 +2956,7 @@ func TestClusterScope_LBSpecs(t *testing.T) {
SubnetName: "cp-subnet",
FrontendIPConfigs: []infrav1.FrontendIP{
{
Name: "api-server-lb-internal-frontEnd",
Name: "api-server-lb-internal-ip",
FrontendIPClass: infrav1.FrontendIPClass{
PrivateIPAddress: infrav1.DefaultInternalLBIPAddress,
},

0 comments on commit 0f56695

Please sign in to comment.