@@ -12,12 +12,16 @@ import (
1212)
1313
1414type lbInput struct {
15- infraID string
16- region string
17- resourceGroup string
18- subscriptionID string
19- lbClient * armnetwork.LoadBalancersClient
20- tags map [string ]* string
15+ loadBalancerName string
16+ infraID string
17+ region string
18+ resourceGroup string
19+ subscriptionID string
20+ frontendIPConfigName string
21+ backendAddressPoolName string
22+ idPrefix string
23+ lbClient * armnetwork.LoadBalancersClient
24+ tags map [string ]* string
2125}
2226
2327type pipInput struct {
@@ -93,15 +97,11 @@ func createPublicIP(ctx context.Context, in *pipInput) (*armnetwork.PublicIPAddr
9397}
9498
9599func createAPILoadBalancer (ctx context.Context , pip * armnetwork.PublicIPAddress , in * lbInput ) (* armnetwork.LoadBalancer , error ) {
96- loadBalancerName := in .infraID
97100 probeName := "api-probe"
98- frontEndIPConfigName := "public-lb-ip-v4"
99- backEndAddressPoolName := in .infraID
100- idPrefix := fmt .Sprintf ("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers" , in .subscriptionID , in .resourceGroup )
101101
102102 pollerResp , err := in .lbClient .BeginCreateOrUpdate (ctx ,
103103 in .resourceGroup ,
104- loadBalancerName ,
104+ in . loadBalancerName ,
105105 armnetwork.LoadBalancer {
106106 Location : to .Ptr (in .region ),
107107 SKU : & armnetwork.LoadBalancerSKU {
@@ -111,7 +111,7 @@ func createAPILoadBalancer(ctx context.Context, pip *armnetwork.PublicIPAddress,
111111 Properties : & armnetwork.LoadBalancerPropertiesFormat {
112112 FrontendIPConfigurations : []* armnetwork.FrontendIPConfiguration {
113113 {
114- Name : & frontEndIPConfigName ,
114+ Name : & in . frontendIPConfigName ,
115115 Properties : & armnetwork.FrontendIPConfigurationPropertiesFormat {
116116 PrivateIPAllocationMethod : to .Ptr (armnetwork .IPAllocationMethodDynamic ),
117117 PublicIPAddress : pip ,
@@ -120,7 +120,7 @@ func createAPILoadBalancer(ctx context.Context, pip *armnetwork.PublicIPAddress,
120120 },
121121 BackendAddressPools : []* armnetwork.BackendAddressPool {
122122 {
123- Name : & backEndAddressPoolName ,
123+ Name : & in . backendAddressPoolName ,
124124 },
125125 },
126126 Probes : []* armnetwork.Probe {
@@ -146,13 +146,13 @@ func createAPILoadBalancer(ctx context.Context, pip *armnetwork.PublicIPAddress,
146146 EnableFloatingIP : to .Ptr (false ),
147147 LoadDistribution : to .Ptr (armnetwork .LoadDistributionDefault ),
148148 FrontendIPConfiguration : & armnetwork.SubResource {
149- ID : to .Ptr (fmt .Sprintf ("/%s/%s/frontendIPConfigurations/%s" , idPrefix , loadBalancerName , frontEndIPConfigName )),
149+ ID : to .Ptr (fmt .Sprintf ("/%s/%s/frontendIPConfigurations/%s" , in . idPrefix , in . loadBalancerName , in . frontendIPConfigName )),
150150 },
151151 BackendAddressPool : & armnetwork.SubResource {
152- ID : to .Ptr (fmt .Sprintf ("/%s/%s/backendAddressPools/%s" , idPrefix , loadBalancerName , backEndAddressPoolName )),
152+ ID : to .Ptr (fmt .Sprintf ("/%s/%s/backendAddressPools/%s" , in . idPrefix , in . loadBalancerName , in . backendAddressPoolName )),
153153 },
154154 Probe : & armnetwork.SubResource {
155- ID : to .Ptr (fmt .Sprintf ("/%s/%s/probes/%s" , idPrefix , loadBalancerName , probeName )),
155+ ID : to .Ptr (fmt .Sprintf ("/%s/%s/probes/%s" , in . idPrefix , in . loadBalancerName , probeName )),
156156 },
157157 },
158158 },
@@ -173,14 +173,10 @@ func createAPILoadBalancer(ctx context.Context, pip *armnetwork.PublicIPAddress,
173173}
174174
175175func updateOutboundLoadBalancerToAPILoadBalancer (ctx context.Context , pip * armnetwork.PublicIPAddress , in * lbInput ) (* armnetwork.LoadBalancer , error ) {
176- loadBalancerName := in .infraID
177176 probeName := "api-probe"
178- frontEndIPConfigName := "public-lb-ip-v4"
179- backEndAddressPoolName := in .infraID
180- idPrefix := fmt .Sprintf ("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers" , in .subscriptionID , in .resourceGroup )
181177
182178 // Get the CAPI-created outbound load balancer so we can modify it.
183- extLB , err := in .lbClient .Get (ctx , in .resourceGroup , loadBalancerName , nil )
179+ extLB , err := in .lbClient .Get (ctx , in .resourceGroup , in . loadBalancerName , nil )
184180 if err != nil {
185181 return nil , fmt .Errorf ("failed to get external load balancer: %w" , err )
186182 }
@@ -192,20 +188,20 @@ func updateOutboundLoadBalancerToAPILoadBalancer(ctx context.Context, pip *armne
192188 // API server.
193189 extLB .Properties .FrontendIPConfigurations = append (extLB .Properties .FrontendIPConfigurations ,
194190 & armnetwork.FrontendIPConfiguration {
195- Name : & frontEndIPConfigName ,
191+ Name : & in . frontendIPConfigName ,
196192 Properties : & armnetwork.FrontendIPConfigurationPropertiesFormat {
197193 PrivateIPAllocationMethod : to .Ptr (armnetwork .IPAllocationMethodDynamic ),
198194 PublicIPAddress : pip ,
199195 },
200196 })
201197 extLB .Properties .BackendAddressPools = append (extLB .Properties .BackendAddressPools ,
202198 & armnetwork.BackendAddressPool {
203- Name : & backEndAddressPoolName ,
199+ Name : & in . backendAddressPoolName ,
204200 })
205201
206202 pollerResp , err := in .lbClient .BeginCreateOrUpdate (ctx ,
207203 in .resourceGroup ,
208- loadBalancerName ,
204+ in . loadBalancerName ,
209205 armnetwork.LoadBalancer {
210206 Location : to .Ptr (in .region ),
211207 SKU : & armnetwork.LoadBalancerSKU {
@@ -238,13 +234,13 @@ func updateOutboundLoadBalancerToAPILoadBalancer(ctx context.Context, pip *armne
238234 EnableFloatingIP : to .Ptr (false ),
239235 LoadDistribution : to .Ptr (armnetwork .LoadDistributionDefault ),
240236 FrontendIPConfiguration : & armnetwork.SubResource {
241- ID : to .Ptr (fmt .Sprintf ("/%s/%s/frontendIPConfigurations/%s" , idPrefix , loadBalancerName , frontEndIPConfigName )),
237+ ID : to .Ptr (fmt .Sprintf ("/%s/%s/frontendIPConfigurations/%s" , in . idPrefix , in . loadBalancerName , in . frontendIPConfigName )),
242238 },
243239 BackendAddressPool : & armnetwork.SubResource {
244- ID : to .Ptr (fmt .Sprintf ("/%s/%s/backendAddressPools/%s" , idPrefix , loadBalancerName , backEndAddressPoolName )),
240+ ID : to .Ptr (fmt .Sprintf ("/%s/%s/backendAddressPools/%s" , in . idPrefix , in . loadBalancerName , in . backendAddressPoolName )),
245241 },
246242 Probe : & armnetwork.SubResource {
247- ID : to .Ptr (fmt .Sprintf ("/%s/%s/probes/%s" , idPrefix , loadBalancerName , probeName )),
243+ ID : to .Ptr (fmt .Sprintf ("/%s/%s/probes/%s" , in . idPrefix , in . loadBalancerName , probeName )),
248244 },
249245 },
250246 },
@@ -266,13 +262,10 @@ func updateOutboundLoadBalancerToAPILoadBalancer(ctx context.Context, pip *armne
266262}
267263
268264func updateInternalLoadBalancer (ctx context.Context , in * lbInput ) (* armnetwork.LoadBalancer , error ) {
269- loadBalancerName := fmt .Sprintf ("%s-internal" , in .infraID )
270265 mcsProbeName := "sint-probe"
271- backEndAddressPoolName := fmt .Sprintf ("%s-internal" , in .infraID )
272- idPrefix := fmt .Sprintf ("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers" , in .subscriptionID , in .resourceGroup )
273266
274267 // Get the CAPI-created internal load balancer so we can modify it.
275- lbResp , err := in .lbClient .Get (ctx , in .resourceGroup , loadBalancerName , nil )
268+ lbResp , err := in .lbClient .Get (ctx , in .resourceGroup , in . loadBalancerName , nil )
276269 if err != nil {
277270 return nil , fmt .Errorf ("could not get internal load balancer: %w" , err )
278271 }
@@ -305,13 +298,13 @@ func updateInternalLoadBalancer(ctx context.Context, in *lbInput) (*armnetwork.L
305298 EnableFloatingIP : to .Ptr (false ),
306299 LoadDistribution : to .Ptr (armnetwork .LoadDistributionDefault ),
307300 FrontendIPConfiguration : & armnetwork.SubResource {
308- ID : to .Ptr (fmt .Sprintf ("/%s/%s/frontendIPConfigurations/%s" , idPrefix , loadBalancerName , existingFrontEndIPConfigName )),
301+ ID : to .Ptr (fmt .Sprintf ("/%s/%s/frontendIPConfigurations/%s" , in . idPrefix , in . loadBalancerName , existingFrontEndIPConfigName )),
309302 },
310303 BackendAddressPool : & armnetwork.SubResource {
311- ID : to .Ptr (fmt .Sprintf ("/%s/%s/backendAddressPools/%s" , idPrefix , loadBalancerName , backEndAddressPoolName )),
304+ ID : to .Ptr (fmt .Sprintf ("/%s/%s/backendAddressPools/%s" , in . idPrefix , in . loadBalancerName , in . backendAddressPoolName )),
312305 },
313306 Probe : & armnetwork.SubResource {
314- ID : to .Ptr (fmt .Sprintf ("/%s/%s/probes/%s" , idPrefix , loadBalancerName , mcsProbeName )),
307+ ID : to .Ptr (fmt .Sprintf ("/%s/%s/probes/%s" , in . idPrefix , in . loadBalancerName , mcsProbeName )),
315308 },
316309 },
317310 }
@@ -320,7 +313,7 @@ func updateInternalLoadBalancer(ctx context.Context, in *lbInput) (*armnetwork.L
320313 intLB .Properties .LoadBalancingRules = append (intLB .Properties .LoadBalancingRules , mcsRule )
321314 pollerResp , err := in .lbClient .BeginCreateOrUpdate (ctx ,
322315 in .resourceGroup ,
323- loadBalancerName ,
316+ in . loadBalancerName ,
324317 intLB ,
325318 nil )
326319 if err != nil {
0 commit comments