Skip to content

Commit 41a112d

Browse files
Merge pull request openshift#8652 from jhixson74/capz_external_lb
CORS-3485: Azure: modify control plane outbound LB into submission as an API LB
2 parents 88dec15 + a6a90db commit 41a112d

File tree

3 files changed

+55
-29
lines changed

3 files changed

+55
-29
lines changed

pkg/asset/manifests/azure/cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
103103
},
104104
},
105105
ControlPlaneOutboundLB: &capz.LoadBalancerSpec{
106+
Name: clusterID.InfraID,
106107
FrontendIPsCount: to.Ptr(int32(1)),
107108
},
108109
Subnets: capz.Subnets{

pkg/infrastructure/azure/azure.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,12 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
438438
}
439439

440440
lbClient := networkClientFactory.NewLoadBalancersClient()
441-
442441
lbInput := &lbInput{
443442
infraID: in.InfraID,
444-
region: in.InstallConfig.Config.Azure.Region,
443+
region: platform.Region,
445444
resourceGroup: resourceGroupName,
446445
subscriptionID: session.Credentials.SubscriptionID,
447446
lbClient: lbClient,
448-
pipClient: networkClientFactory.NewPublicIPAddressesClient(),
449447
tags: p.Tags,
450448
}
451449

@@ -458,17 +456,25 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
458456
var lbBap *armnetwork.BackendAddressPool
459457
var extLBFQDN string
460458
if in.InstallConfig.Config.Publish == types.ExternalPublishingStrategy {
461-
publicIP, err := createPublicIP(ctx, lbInput)
459+
publicIP, err := createPublicIP(ctx, &pipInput{
460+
name: fmt.Sprintf("%s-pip-v4", in.InfraID),
461+
infraID: in.InfraID,
462+
region: in.InstallConfig.Config.Azure.Region,
463+
resourceGroup: resourceGroupName,
464+
pipClient: networkClientFactory.NewPublicIPAddressesClient(),
465+
tags: p.Tags,
466+
})
462467
if err != nil {
463468
return fmt.Errorf("failed to create public ip: %w", err)
464469
}
465470
logrus.Debugf("created public ip: %s", *publicIP.ID)
466471

467-
loadBalancer, err := createExternalLoadBalancer(ctx, publicIP, lbInput)
472+
loadBalancer, err := updateExternalLoadBalancer(ctx, publicIP, lbInput)
468473
if err != nil {
469-
return fmt.Errorf("failed to create load balancer: %w", err)
474+
return fmt.Errorf("failed to update external load balancer: %w", err)
470475
}
471-
logrus.Debugf("created load balancer: %s", *loadBalancer.ID)
476+
477+
logrus.Debugf("updated external load balancer: %s", *loadBalancer.ID)
472478
lbBap = loadBalancer.Properties.BackendAddressPools[0]
473479
extLBFQDN = *publicIP.Properties.DNSSettings.Fqdn
474480
}
Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@ type lbInput struct {
1515
region string
1616
resourceGroup string
1717
subscriptionID string
18-
pipClient *armnetwork.PublicIPAddressesClient
1918
lbClient *armnetwork.LoadBalancersClient
2019
tags map[string]*string
2120
}
2221

22+
type pipInput struct {
23+
infraID string
24+
name string
25+
region string
26+
resourceGroup string
27+
pipClient *armnetwork.PublicIPAddressesClient
28+
tags map[string]*string
29+
}
30+
2331
type vmInput struct {
2432
infraID string
2533
resourceGroup string
@@ -29,15 +37,13 @@ type vmInput struct {
2937
nicClient *armnetwork.InterfacesClient
3038
}
3139

32-
func createPublicIP(ctx context.Context, in *lbInput) (*armnetwork.PublicIPAddress, error) {
33-
publicIPAddressName := fmt.Sprintf("%s-pip-v4", in.infraID)
34-
40+
func createPublicIP(ctx context.Context, in *pipInput) (*armnetwork.PublicIPAddress, error) {
3541
pollerResp, err := in.pipClient.BeginCreateOrUpdate(
3642
ctx,
3743
in.resourceGroup,
38-
publicIPAddressName,
44+
in.name,
3945
armnetwork.PublicIPAddress{
40-
Name: to.Ptr(publicIPAddressName),
46+
Name: to.Ptr(in.name),
4147
Location: to.Ptr(in.region),
4248
SKU: &armnetwork.PublicIPAddressSKU{
4349
Name: to.Ptr(armnetwork.PublicIPAddressSKUNameStandard),
@@ -65,13 +71,37 @@ func createPublicIP(ctx context.Context, in *lbInput) (*armnetwork.PublicIPAddre
6571
return &resp.PublicIPAddress, nil
6672
}
6773

68-
func createExternalLoadBalancer(ctx context.Context, pip *armnetwork.PublicIPAddress, in *lbInput) (*armnetwork.LoadBalancer, error) {
74+
func updateExternalLoadBalancer(ctx context.Context, pip *armnetwork.PublicIPAddress, in *lbInput) (*armnetwork.LoadBalancer, error) {
6975
loadBalancerName := in.infraID
7076
probeName := "api-probe"
7177
frontEndIPConfigName := "public-lb-ip-v4"
7278
backEndAddressPoolName := in.infraID
7379
idPrefix := fmt.Sprintf("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers", in.subscriptionID, in.resourceGroup)
7480

81+
// Get the CAPI-created outbound load balancer so we can modify it.
82+
extLB, err := in.lbClient.Get(ctx, in.resourceGroup, loadBalancerName, nil)
83+
if err != nil {
84+
return nil, fmt.Errorf("failed to get external load balancer: %w", err)
85+
}
86+
87+
// Get the existing frontend configuration and backend address pool and
88+
// create an additional frontend configuration mand backend address
89+
// pool. Use the newly created public IP address with the additional
90+
// configuration so we can setup load balancing rules for the external
91+
// API server.
92+
extLB.Properties.FrontendIPConfigurations = append(extLB.Properties.FrontendIPConfigurations,
93+
&armnetwork.FrontendIPConfiguration{
94+
Name: &frontEndIPConfigName,
95+
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
96+
PrivateIPAllocationMethod: to.Ptr(armnetwork.IPAllocationMethodDynamic),
97+
PublicIPAddress: pip,
98+
},
99+
})
100+
extLB.Properties.BackendAddressPools = append(extLB.Properties.BackendAddressPools,
101+
&armnetwork.BackendAddressPool{
102+
Name: &backEndAddressPoolName,
103+
})
104+
75105
pollerResp, err := in.lbClient.BeginCreateOrUpdate(ctx,
76106
in.resourceGroup,
77107
loadBalancerName,
@@ -82,20 +112,8 @@ func createExternalLoadBalancer(ctx context.Context, pip *armnetwork.PublicIPAdd
82112
Tier: to.Ptr(armnetwork.LoadBalancerSKUTierRegional),
83113
},
84114
Properties: &armnetwork.LoadBalancerPropertiesFormat{
85-
FrontendIPConfigurations: []*armnetwork.FrontendIPConfiguration{
86-
{
87-
Name: &frontEndIPConfigName,
88-
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
89-
PrivateIPAllocationMethod: to.Ptr(armnetwork.IPAllocationMethodDynamic),
90-
PublicIPAddress: pip,
91-
},
92-
},
93-
},
94-
BackendAddressPools: []*armnetwork.BackendAddressPool{
95-
{
96-
Name: &backEndAddressPoolName,
97-
},
98-
},
115+
FrontendIPConfigurations: extLB.Properties.FrontendIPConfigurations,
116+
BackendAddressPools: extLB.Properties.BackendAddressPools,
99117
Probes: []*armnetwork.Probe{
100118
{
101119
Name: &probeName,
@@ -130,12 +148,13 @@ func createExternalLoadBalancer(ctx context.Context, pip *armnetwork.PublicIPAdd
130148
},
131149
},
132150
},
151+
OutboundRules: extLB.Properties.OutboundRules,
133152
},
134153
Tags: in.tags,
135154
}, nil)
136155

137156
if err != nil {
138-
return nil, fmt.Errorf("cannot create load balancer: %w", err)
157+
return nil, fmt.Errorf("cannot update load balancer: %w", err)
139158
}
140159

141160
resp, err := pollerResp.PollUntilDone(ctx, nil)

0 commit comments

Comments
 (0)