Skip to content

Commit ec3602c

Browse files
committed
azure: Add support for multi zonal NAT gateways
Adding support to install multiple NAT gateways per subnet. The zone in which they will be installed is not customizable due to needing an upstream PR to fix CAPZ.
1 parent ec5eb80 commit ec3602c

File tree

5 files changed

+84
-16
lines changed

5 files changed

+84
-16
lines changed

data/data/install.openshift.io_installconfigs.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5277,6 +5277,27 @@ spec:
52775277
type: string
52785278
type: array
52795279
type: object
5280+
natGatewaySpec:
5281+
description: |-
5282+
NatGatewaySpec allows the user to specify the subnets and the nat gateway configuration for each subnet.
5283+
Since only one nat gateway is allowed per subnet, users can create multiple subnets and create nat gateway
5284+
for each subnet for zone resilience.
5285+
items:
5286+
description: NatGatewaySpec allows the user to specify the subnets
5287+
and the nat gateway configuration for each subnet.
5288+
properties:
5289+
name:
5290+
description: Name of the nat gateway to be created.
5291+
type: string
5292+
subnet:
5293+
description: Subnet specifies the name of the subnet to
5294+
be created.
5295+
type: string
5296+
required:
5297+
- name
5298+
- subnet
5299+
type: object
5300+
type: array
52805301
networkResourceGroupName:
52815302
description: NetworkResourceGroupName specifies the network resource
52825303
group that contains an existing VNet
@@ -5326,6 +5347,7 @@ spec:
53265347
VNet for the installer to use
53275348
type: string
53285349
required:
5350+
- natGatewaySpec
53295351
- region
53305352
type: object
53315353
baremetal:

pkg/asset/manifests/azure/cluster.go

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,20 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
179179

180180
azEnv := string(installConfig.Azure.CloudName)
181181

182-
computeSubnetSpec := capz.SubnetSpec{
182+
subnetSpec := capz.Subnets{
183+
{
184+
SubnetClassSpec: capz.SubnetClassSpec{
185+
Name: controlPlaneSubnet,
186+
Role: capz.SubnetControlPlane,
187+
CIDRBlocks: []string{
188+
subnets[0].String(),
189+
},
190+
},
191+
SecurityGroup: securityGroup,
192+
},
193+
}
194+
195+
computeSubnetSpec := []capz.SubnetSpec{{
183196
ID: nodeSubnetID,
184197
SubnetClassSpec: capz.SubnetClassSpec{
185198
Name: computeSubnet,
@@ -189,14 +202,36 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
189202
},
190203
},
191204
SecurityGroup: securityGroup,
192-
}
205+
}}
193206

194207
if installConfig.Config.Azure.OutboundType == azure.NATGatewaySingleZoneOutboundType {
195-
computeSubnetSpec.NatGateway = capz.NatGateway{
208+
computeSubnetSpec[0].NatGateway = capz.NatGateway{
196209
NatGatewayClassSpec: capz.NatGatewayClassSpec{Name: fmt.Sprintf("%s-natgw", clusterID.InfraID)},
197210
}
211+
} else if installConfig.Config.Azure.OutboundType == azure.NATGatewayMultiZoneOutboundType {
212+
computeSubnetSpec = []capz.SubnetSpec{}
213+
for index, spec := range installConfig.Config.Azure.NatGatewaySpec {
214+
computeSubnetSpec = append(computeSubnetSpec, capz.SubnetSpec{
215+
ID: "UNKNOWN",
216+
SubnetClassSpec: capz.SubnetClassSpec{
217+
Name: computeSubnet,
218+
Role: capz.SubnetNode,
219+
CIDRBlocks: []string{
220+
spec.Subnet,
221+
},
222+
},
223+
NatGateway: capz.NatGateway{
224+
NatGatewayIP: capz.PublicIPSpec{
225+
Name: fmt.Sprintf("%s-natgw-public-ip-%d", clusterID.InfraID, index),
226+
},
227+
NatGatewayClassSpec: capz.NatGatewayClassSpec{Name: spec.Name},
228+
},
229+
SecurityGroup: securityGroup,
230+
})
231+
}
198232
}
199233

234+
subnetSpec = append(subnetSpec, computeSubnetSpec...)
200235
azureCluster := &capz.AzureCluster{
201236
ObjectMeta: metav1.ObjectMeta{
202237
Name: clusterID.InfraID,
@@ -236,19 +271,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
236271
},
237272
APIServerLB: &apiServerLB,
238273
ControlPlaneOutboundLB: controlPlaneOutboundLB,
239-
Subnets: capz.Subnets{
240-
{
241-
SubnetClassSpec: capz.SubnetClassSpec{
242-
Name: controlPlaneSubnet,
243-
Role: capz.SubnetControlPlane,
244-
CIDRBlocks: []string{
245-
subnets[0].String(),
246-
},
247-
},
248-
SecurityGroup: securityGroup,
249-
},
250-
computeSubnetSpec,
251-
},
274+
Subnets: subnetSpec,
252275
},
253276
},
254277
}

pkg/explain/printer_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ If empty, the value is equal to "AzurePublicCloud".
322322
installing on Azure for machine pools which do not define their own
323323
platform configuration.
324324
325+
natGatewaySpec <[]object> -required-
326+
NatGatewaySpec allows the user to specify the subnets and the nat gateway configuration for each subnet.
327+
Since only one nat gateway is allowed per subnet, users can create multiple subnets and create nat gateway
328+
for each subnet for zone resilience.
329+
NatGatewaySpec allows the user to specify the subnets and the nat gateway configuration for each subnet.
330+
325331
networkResourceGroupName <string>
326332
NetworkResourceGroupName specifies the network resource group that contains an existing VNet
327333

pkg/types/azure/platform.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const (
2323
// see https://learn.microsoft.com/en-us/azure/virtual-network/nat-gateway/nat-gateway-resource
2424
NATGatewaySingleZoneOutboundType OutboundType = "NATGatewaySingleZone"
2525

26+
// NATGatewayMultiZoneOutboundType uses NAT gateways in multiple zones in the compute node subnets for outbound access.
27+
NATGatewayMultiZoneOutboundType OutboundType = "MultiZoneNatGateway"
28+
2629
// UserDefinedRoutingOutboundType uses user defined routing for egress from the cluster.
2730
// see https://docs.microsoft.com/en-us/azure/virtual-network/virtual-networks-udr-overview
2831
UserDefinedRoutingOutboundType OutboundType = "UserDefinedRouting"
@@ -83,6 +86,11 @@ type Platform struct {
8386
// +optional
8487
OutboundType OutboundType `json:"outboundType"`
8588

89+
// NatGatewaySpec allows the user to specify the subnets and the nat gateway configuration for each subnet.
90+
// Since only one nat gateway is allowed per subnet, users can create multiple subnets and create nat gateway
91+
// for each subnet for zone resilience.
92+
NatGatewaySpec []NatGatewaySpec `json:"natGatewaySpec"`
93+
8694
// ResourceGroupName is the name of an already existing resource group where the cluster should be installed.
8795
// This resource group should only be used for this specific cluster and the cluster components will assume
8896
// ownership of all resources in the resource group. Destroying the cluster using installer will delete this
@@ -110,6 +118,14 @@ type Platform struct {
110118
UserProvisionedDNS dns.UserProvisionedDNS `json:"userProvisionedDNS,omitempty"`
111119
}
112120

121+
// NatGatewaySpec allows the user to specify the subnets and the nat gateway configuration for each subnet.
122+
type NatGatewaySpec struct {
123+
// Name of the nat gateway to be created.
124+
Name string `json:"name"`
125+
// Subnet specifies the name of the subnet to be created.
126+
Subnet string `json:"subnet"`
127+
}
128+
113129
// KeyVault defines an Azure Key Vault.
114130
type KeyVault struct {
115131
// ResourceGroup defines the Azure resource group used by the key

pkg/types/azure/validation/platform.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ func findDuplicateTagKeys(tagSet map[string]string) error {
239239
var (
240240
validOutboundTypes = map[azure.OutboundType]struct{}{
241241
azure.LoadbalancerOutboundType: {},
242+
azure.NATGatewayMultiZoneOutboundType: {},
242243
azure.NATGatewaySingleZoneOutboundType: {},
243244
azure.UserDefinedRoutingOutboundType: {},
244245
}

0 commit comments

Comments
 (0)