@@ -160,15 +160,8 @@ func (c *AzureCluster) setVnetPeeringDefaults() {
160160
161161func (c * AzureCluster ) setAPIServerLBDefaults () {
162162 lb := & c .Spec .NetworkSpec .APIServerLB
163- if lb .Type == "" {
164- lb .Type = Public
165- }
166- if lb .SKU == "" {
167- lb .SKU = SKUStandard
168- }
169- if lb .IdleTimeoutInMinutes == nil {
170- lb .IdleTimeoutInMinutes = pointer .Int32Ptr (DefaultOutboundRuleIdleTimeoutInMinutes )
171- }
163+
164+ lb .LoadBalancerClassSpec .setAPIServerLBDefaults ()
172165
173166 if lb .Type == Public {
174167 if lb .Name == "" {
@@ -226,13 +219,9 @@ func (c *AzureCluster) setNodeOutboundLBDefaults() {
226219 }
227220
228221 lb := c .Spec .NetworkSpec .NodeOutboundLB
229- lb .Type = Public
230- lb .SKU = SKUStandard
231- lb .Name = c .ObjectMeta .Name
222+ lb .LoadBalancerClassSpec .setNodeOutboundLBDefaults ()
232223
233- if lb .IdleTimeoutInMinutes == nil {
234- lb .IdleTimeoutInMinutes = pointer .Int32Ptr (DefaultOutboundRuleIdleTimeoutInMinutes )
235- }
224+ lb .Name = c .ObjectMeta .Name
236225
237226 if lb .FrontendIPsCount == nil {
238227 lb .FrontendIPsCount = pointer .Int32Ptr (1 )
@@ -242,32 +231,19 @@ func (c *AzureCluster) setNodeOutboundLBDefaults() {
242231}
243232
244233func (c * AzureCluster ) setControlPlaneOutboundLBDefaults () {
245- // public clusters don't need control plane outbound lb
246- if c .Spec .NetworkSpec .APIServerLB .Type == Public {
247- return
248- }
234+ lb := c .Spec .NetworkSpec .ControlPlaneOutboundLB
249235
250- // private clusters can disable control plane outbound lb by setting it to nil.
251- if c .Spec .NetworkSpec .ControlPlaneOutboundLB == nil {
236+ if lb == nil {
252237 return
253238 }
254239
255- lb := c .Spec .NetworkSpec .ControlPlaneOutboundLB
256- lb .Type = Public
257- lb .SKU = SKUStandard
258-
240+ lb .LoadBalancerClassSpec .setControlPlaneOutboundLBDefaults ()
259241 if lb .Name == "" {
260242 lb .Name = generateControlPlaneOutboundLBName (c .ObjectMeta .Name )
261243 }
262-
263- if lb .IdleTimeoutInMinutes == nil {
264- lb .IdleTimeoutInMinutes = pointer .Int32Ptr (DefaultOutboundRuleIdleTimeoutInMinutes )
265- }
266-
267244 if lb .FrontendIPsCount == nil {
268245 lb .FrontendIPsCount = pointer .Int32Ptr (1 )
269246 }
270-
271247 c .setOutboundLBFrontendIPs (lb , generateControlPlaneOutboundIPName )
272248}
273249
@@ -321,6 +297,53 @@ func (c *AzureCluster) setBastionDefaults() {
321297 }
322298}
323299
300+ func (lb * LoadBalancerClassSpec ) setAPIServerLBDefaults () {
301+ if lb .Type == "" {
302+ lb .Type = Public
303+ }
304+ if lb .SKU == "" {
305+ lb .SKU = SKUStandard
306+ }
307+ if lb .IdleTimeoutInMinutes == nil {
308+ lb .IdleTimeoutInMinutes = pointer .Int32Ptr (DefaultOutboundRuleIdleTimeoutInMinutes )
309+ }
310+ }
311+
312+ func (lb * LoadBalancerClassSpec ) setNodeOutboundLBDefaults () {
313+ lb .setOutboundLBDefaults ()
314+ }
315+
316+ func (lb * LoadBalancerClassSpec ) setControlPlaneOutboundLBDefaults () {
317+ lb .setOutboundLBDefaults ()
318+ }
319+
320+ func (lb * LoadBalancerClassSpec ) setOutboundLBDefaults () {
321+ lb .Type = Public
322+ lb .SKU = SKUStandard
323+ if lb .IdleTimeoutInMinutes == nil {
324+ lb .IdleTimeoutInMinutes = pointer .Int32Ptr (DefaultOutboundRuleIdleTimeoutInMinutes )
325+ }
326+ }
327+
328+ func setControlPlaneOutboundLBDefaults (lb * LoadBalancerClassSpec , apiserverLBType LBType ) {
329+ // public clusters don't need control plane outbound lb
330+ if apiserverLBType == Public {
331+ return
332+ }
333+
334+ // private clusters can disable control plane outbound lb by setting it to nil.
335+ if lb == nil {
336+ return
337+ }
338+
339+ lb .Type = Public
340+ lb .SKU = SKUStandard
341+
342+ if lb .IdleTimeoutInMinutes == nil {
343+ lb .IdleTimeoutInMinutes = pointer .Int32Ptr (DefaultOutboundRuleIdleTimeoutInMinutes )
344+ }
345+ }
346+
324347// generateVnetName generates a virtual network name, based on the cluster name.
325348func generateVnetName (clusterName string ) string {
326349 return fmt .Sprintf ("%s-%s" , clusterName , "vnet" )
0 commit comments