From 58b6bb9dcc367e1077bbc2793b7b5aa361e5dc4f Mon Sep 17 00:00:00 2001 From: Ashutosh Kumar Date: Thu, 4 May 2023 17:24:25 +0530 Subject: [PATCH] use default backend pool name in capz controller if empty Ref issue #3252 Signed-off-by: Ashutosh Kumar --- api/v1beta1/azurecluster_default.go | 42 ++++++++++++++++++++------ controllers/azurecluster_reconciler.go | 1 + 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/api/v1beta1/azurecluster_default.go b/api/v1beta1/azurecluster_default.go index 88e6365f9f0..a9a0526cf67 100644 --- a/api/v1beta1/azurecluster_default.go +++ b/api/v1beta1/azurecluster_default.go @@ -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. @@ -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. @@ -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)) } } diff --git a/controllers/azurecluster_reconciler.go b/controllers/azurecluster_reconciler.go index a4e3787978c..c78141730de 100644 --- a/controllers/azurecluster_reconciler.go +++ b/controllers/azurecluster_reconciler.go @@ -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()