Skip to content

Commit

Permalink
use default backend pool name in capz controller if empty
Browse files Browse the repository at this point in the history
Ref issue kubernetes-sigs#3252

Signed-off-by: Ashutosh Kumar <[email protected]>
  • Loading branch information
sonasingh46 committed May 5, 2023
1 parent fecb3a5 commit 926a0db
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
42 changes: 32 additions & 10 deletions api/v1beta1/azurecluster_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,7 @@ func (c *AzureCluster) setAPIServerLBDefaults() {
}
}
}

if lb.BackendPool.Name == "" {
lb.BackendPool.Name = generateBackendAddressPoolName(lb.Name)
}
c.SetAPIServerLBBackendPoolNameDefault()
}

// SetNodeOutboundLBDefaults sets the default values for the NodeOutboundLB.
Expand Down Expand Up @@ -247,10 +244,7 @@ func (c *AzureCluster) SetNodeOutboundLBDefaults() {
}

c.setOutboundLBFrontendIPs(lb, generateNodeOutboundIPName)

if lb.BackendPool.Name == "" {
lb.BackendPool.Name = generateOutboundBackendAddressPoolName(lb.Name)
}
c.SetNodeOutboundLBBackendPoolNameDefault()
}

// SetControlPlaneOutboundLBDefaults sets the default values for the control plane's outbound LB.
Expand All @@ -269,9 +263,37 @@ func (c *AzureCluster) SetControlPlaneOutboundLBDefaults() {
lb.FrontendIPsCount = pointer.Int32(1)
}
c.setOutboundLBFrontendIPs(lb, generateControlPlaneOutboundIPName)
c.SetControlPlaneOutboundLBBackendPoolNameDefault()
}

// SetBackendPoolNameDefault defaults the backend pool name of the LBs.
func (c *AzureCluster) SetBackendPoolNameDefault() {
c.SetAPIServerLBBackendPoolNameDefault()
c.SetNodeOutboundLBBackendPoolNameDefault()
c.SetControlPlaneOutboundLBBackendPoolNameDefault()
}

// SetAPIServerLBBackendPoolNameDefault defaults the name of the backend pool for apiserver LB.
func (c *AzureCluster) SetAPIServerLBBackendPoolNameDefault() {
apiServerLB := &c.Spec.NetworkSpec.APIServerLB
if apiServerLB.BackendPool.Name == "" {
apiServerLB.BackendPool.Name = generateBackendAddressPoolName(apiServerLB.Name)
}
}

// SetNodeOutboundLBBackendPoolNameDefault defaults the name of the backend pool for node outbound LB.
func (c *AzureCluster) SetNodeOutboundLBBackendPoolNameDefault() {
nodeOutboundLB := c.Spec.NetworkSpec.NodeOutboundLB
if nodeOutboundLB != nil && nodeOutboundLB.BackendPool.Name == "" {
nodeOutboundLB.BackendPool.Name = generateOutboundBackendAddressPoolName(nodeOutboundLB.Name)
}
}

if lb.BackendPool.Name == "" {
lb.BackendPool.Name = generateOutboundBackendAddressPoolName(generateControlPlaneOutboundLBName(c.ObjectMeta.Name))
// SetControlPlaneOutboundLBBackendPoolNameDefault defaults the name of the backend pool for control plane outbound LB.
func (c *AzureCluster) SetControlPlaneOutboundLBBackendPoolNameDefault() {
controlPlaneOutboundLB := c.Spec.NetworkSpec.ControlPlaneOutboundLB
if controlPlaneOutboundLB != nil && controlPlaneOutboundLB.BackendPool.Name == "" {
controlPlaneOutboundLB.BackendPool.Name = generateOutboundBackendAddressPoolName(generateControlPlaneOutboundLBName(c.ObjectMeta.Name))
}
}

Expand Down
1 change: 1 addition & 0 deletions controllers/azurecluster_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (s *azureClusterService) Reconcile(ctx context.Context) error {
return errors.Wrap(err, "failed to get availability zones")
}

s.scope.AzureCluster.SetBackendPoolNameDefault()
s.scope.SetDNSName()
s.scope.SetControlPlaneSecurityRules()

Expand Down

0 comments on commit 926a0db

Please sign in to comment.