Skip to content

Commit a875643

Browse files
committed
pkg/infrastructure/azaure: UDR for Azure
When user defined routing is configured, don't create an outbound load balancer with outbound rules. Since a public load balancer isn't being created, we create one for public API access. https://issues.redhat.com/browse/CORS-3569
1 parent 30e01b0 commit a875643

File tree

3 files changed

+101
-7
lines changed

3 files changed

+101
-7
lines changed

pkg/asset/manifests/azure/cluster.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/openshift/installer/pkg/asset/manifests/capiutils"
1616
"github.com/openshift/installer/pkg/asset/manifests/capiutils/cidr"
1717
"github.com/openshift/installer/pkg/types"
18+
"github.com/openshift/installer/pkg/types/azure"
1819
)
1920

2021
// GenerateClusterAssets generates the manifests for the cluster-api.
@@ -50,6 +51,14 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
5051
source = mainCIDR.String()
5152
}
5253

54+
controlPlaneOutboundLB := &capz.LoadBalancerSpec{
55+
Name: clusterID.InfraID,
56+
FrontendIPsCount: to.Ptr(int32(1)),
57+
}
58+
if installConfig.Config.Platform.Azure.OutboundType == azure.UserDefinedRoutingOutboundType {
59+
controlPlaneOutboundLB = nil
60+
}
61+
5362
securityGroup := capz.SecurityGroup{
5463
Name: networkSecurityGroup,
5564
SecurityGroupClass: capz.SecurityGroupClass{
@@ -114,10 +123,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
114123
Type: capz.Internal,
115124
},
116125
},
117-
ControlPlaneOutboundLB: &capz.LoadBalancerSpec{
118-
Name: clusterID.InfraID,
119-
FrontendIPsCount: to.Ptr(int32(1)),
120-
},
126+
ControlPlaneOutboundLB: controlPlaneOutboundLB,
121127
Subnets: capz.Subnets{
122128
{
123129
SubnetClassSpec: capz.SubnetClassSpec{

pkg/infrastructure/azure/azure.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,17 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
504504
}
505505
logrus.Debugf("created public ip: %s", *publicIP.ID)
506506

507-
loadBalancer, err := updateOutboundLoadBalancerToAPILoadBalancer(ctx, publicIP, lbInput)
508-
if err != nil {
509-
return fmt.Errorf("failed to update external load balancer: %w", err)
507+
var loadBalancer *armnetwork.LoadBalancer
508+
if platform.OutboundType == aztypes.UserDefinedRoutingOutboundType {
509+
loadBalancer, err = createAPILoadBalancer(ctx, publicIP, lbInput)
510+
if err != nil {
511+
return fmt.Errorf("failed to create API load balancer: %w", err)
512+
}
513+
} else {
514+
loadBalancer, err = updateOutboundLoadBalancerToAPILoadBalancer(ctx, publicIP, lbInput)
515+
if err != nil {
516+
return fmt.Errorf("failed to update external load balancer: %w", err)
517+
}
510518
}
511519

512520
logrus.Debugf("updated external load balancer: %s", *loadBalancer.ID)

pkg/infrastructure/azure/network.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,86 @@ func createPublicIP(ctx context.Context, in *pipInput) (*armnetwork.PublicIPAddr
9292
return &resp.PublicIPAddress, nil
9393
}
9494

95+
func createAPILoadBalancer(ctx context.Context, pip *armnetwork.PublicIPAddress, in *lbInput) (*armnetwork.LoadBalancer, error) {
96+
loadBalancerName := in.infraID
97+
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)
101+
102+
pollerResp, err := in.lbClient.BeginCreateOrUpdate(ctx,
103+
in.resourceGroup,
104+
loadBalancerName,
105+
armnetwork.LoadBalancer{
106+
Location: to.Ptr(in.region),
107+
SKU: &armnetwork.LoadBalancerSKU{
108+
Name: to.Ptr(armnetwork.LoadBalancerSKUNameStandard),
109+
Tier: to.Ptr(armnetwork.LoadBalancerSKUTierRegional),
110+
},
111+
Properties: &armnetwork.LoadBalancerPropertiesFormat{
112+
FrontendIPConfigurations: []*armnetwork.FrontendIPConfiguration{
113+
{
114+
Name: &frontEndIPConfigName,
115+
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
116+
PrivateIPAllocationMethod: to.Ptr(armnetwork.IPAllocationMethodDynamic),
117+
PublicIPAddress: pip,
118+
},
119+
},
120+
},
121+
BackendAddressPools: []*armnetwork.BackendAddressPool{
122+
{
123+
Name: &backEndAddressPoolName,
124+
},
125+
},
126+
Probes: []*armnetwork.Probe{
127+
{
128+
Name: &probeName,
129+
Properties: &armnetwork.ProbePropertiesFormat{
130+
Protocol: to.Ptr(armnetwork.ProbeProtocolHTTPS),
131+
Port: to.Ptr[int32](6443),
132+
IntervalInSeconds: to.Ptr[int32](5),
133+
NumberOfProbes: to.Ptr[int32](2),
134+
RequestPath: to.Ptr("/readyz"),
135+
},
136+
},
137+
},
138+
LoadBalancingRules: []*armnetwork.LoadBalancingRule{
139+
{
140+
Name: to.Ptr("api-v4"),
141+
Properties: &armnetwork.LoadBalancingRulePropertiesFormat{
142+
Protocol: to.Ptr(armnetwork.TransportProtocolTCP),
143+
FrontendPort: to.Ptr[int32](6443),
144+
BackendPort: to.Ptr[int32](6443),
145+
IdleTimeoutInMinutes: to.Ptr[int32](30),
146+
EnableFloatingIP: to.Ptr(false),
147+
LoadDistribution: to.Ptr(armnetwork.LoadDistributionDefault),
148+
FrontendIPConfiguration: &armnetwork.SubResource{
149+
ID: to.Ptr(fmt.Sprintf("/%s/%s/frontendIPConfigurations/%s", idPrefix, loadBalancerName, frontEndIPConfigName)),
150+
},
151+
BackendAddressPool: &armnetwork.SubResource{
152+
ID: to.Ptr(fmt.Sprintf("/%s/%s/backendAddressPools/%s", idPrefix, loadBalancerName, backEndAddressPoolName)),
153+
},
154+
Probe: &armnetwork.SubResource{
155+
ID: to.Ptr(fmt.Sprintf("/%s/%s/probes/%s", idPrefix, loadBalancerName, probeName)),
156+
},
157+
},
158+
},
159+
},
160+
},
161+
Tags: in.tags,
162+
}, nil)
163+
164+
if err != nil {
165+
return nil, fmt.Errorf("cannot create load balancer: %w", err)
166+
}
167+
168+
resp, err := pollerResp.PollUntilDone(ctx, nil)
169+
if err != nil {
170+
return nil, err
171+
}
172+
return &resp.LoadBalancer, nil
173+
}
174+
95175
func updateOutboundLoadBalancerToAPILoadBalancer(ctx context.Context, pip *armnetwork.PublicIPAddress, in *lbInput) (*armnetwork.LoadBalancer, error) {
96176
loadBalancerName := in.infraID
97177
probeName := "api-probe"

0 commit comments

Comments
 (0)