Skip to content

Commit 3f3e63d

Browse files
sonasingh46k8s-infra-cherrypick-robot
authored andcommitted
use default backend pool name in capz controller if empty
Ref issue #3252 Signed-off-by: Ashutosh Kumar <[email protected]>
1 parent 8959fc0 commit 3f3e63d

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

api/v1beta1/azurecluster_default.go

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,7 @@ func (c *AzureCluster) setAPIServerLBDefaults() {
204204
}
205205
}
206206
}
207-
208-
if lb.BackendPool.Name == "" {
209-
lb.BackendPool.Name = generateBackendAddressPoolName(lb.Name)
210-
}
207+
c.SetAPIServerLBBackendPoolNameDefault()
211208
}
212209

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

249246
c.setOutboundLBFrontendIPs(lb, generateNodeOutboundIPName)
250-
251-
if lb.BackendPool.Name == "" {
252-
lb.BackendPool.Name = generateOutboundBackendAddressPoolName(lb.Name)
253-
}
247+
c.SetNodeOutboundLBBackendPoolNameDefault()
254248
}
255249

256250
// SetControlPlaneOutboundLBDefaults sets the default values for the control plane's outbound LB.
@@ -269,9 +263,37 @@ func (c *AzureCluster) SetControlPlaneOutboundLBDefaults() {
269263
lb.FrontendIPsCount = pointer.Int32(1)
270264
}
271265
c.setOutboundLBFrontendIPs(lb, generateControlPlaneOutboundIPName)
266+
c.SetControlPlaneOutboundLBBackendPoolNameDefault()
267+
}
268+
269+
// SetBackendPoolNameDefault defaults the backend pool name of the LBs.
270+
func (c *AzureCluster) SetBackendPoolNameDefault() {
271+
c.SetAPIServerLBBackendPoolNameDefault()
272+
c.SetNodeOutboundLBBackendPoolNameDefault()
273+
c.SetControlPlaneOutboundLBBackendPoolNameDefault()
274+
}
275+
276+
// SetAPIServerLBBackendPoolNameDefault defaults the name of the backend pool for apiserver LB.
277+
func (c *AzureCluster) SetAPIServerLBBackendPoolNameDefault() {
278+
apiServerLB := &c.Spec.NetworkSpec.APIServerLB
279+
if apiServerLB.BackendPool.Name == "" {
280+
apiServerLB.BackendPool.Name = generateBackendAddressPoolName(apiServerLB.Name)
281+
}
282+
}
283+
284+
// SetNodeOutboundLBBackendPoolNameDefault defaults the name of the backend pool for node outbound LB.
285+
func (c *AzureCluster) SetNodeOutboundLBBackendPoolNameDefault() {
286+
nodeOutboundLB := c.Spec.NetworkSpec.NodeOutboundLB
287+
if nodeOutboundLB != nil && nodeOutboundLB.BackendPool.Name == "" {
288+
nodeOutboundLB.BackendPool.Name = generateOutboundBackendAddressPoolName(nodeOutboundLB.Name)
289+
}
290+
}
272291

273-
if lb.BackendPool.Name == "" {
274-
lb.BackendPool.Name = generateOutboundBackendAddressPoolName(generateControlPlaneOutboundLBName(c.ObjectMeta.Name))
292+
// SetControlPlaneOutboundLBBackendPoolNameDefault defaults the name of the backend pool for control plane outbound LB.
293+
func (c *AzureCluster) SetControlPlaneOutboundLBBackendPoolNameDefault() {
294+
controlPlaneOutboundLB := c.Spec.NetworkSpec.ControlPlaneOutboundLB
295+
if controlPlaneOutboundLB != nil && controlPlaneOutboundLB.BackendPool.Name == "" {
296+
controlPlaneOutboundLB.BackendPool.Name = generateOutboundBackendAddressPoolName(generateControlPlaneOutboundLBName(c.ObjectMeta.Name))
275297
}
276298
}
277299

controllers/azurecluster_reconciler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (s *azureClusterService) Reconcile(ctx context.Context) error {
8585
return errors.Wrap(err, "failed to get availability zones")
8686
}
8787

88+
s.scope.AzureCluster.SetBackendPoolNameDefault()
8889
s.scope.SetDNSName()
8990
s.scope.SetControlPlaneSecurityRules()
9091

0 commit comments

Comments
 (0)