Skip to content

Commit 9d9b9c9

Browse files
committed
Allow users to set the zones for NAT gateway
Allow users to set the zones they need the created NAT gateway to use. ASO allows the NAT gateway to be set to a list of zones so enabling that here.
1 parent 7194cbd commit 9d9b9c9

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

api/v1beta1/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ type NatGateway struct {
259259
// NatGatewayClassSpec defines a NAT gateway class specification.
260260
type NatGatewayClassSpec struct {
261261
Name string `json:"name"`
262+
263+
// Zones mentions the list of zones the NAT gateway should be a part of.
264+
// +optional
265+
Zones []string `json:"zones"`
262266
}
263267

264268
// SecurityGroupProtocol defines the protocol type for a security group rule.

azure/scope/cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ func (s *ClusterScope) NatGatewaySpecs() []azure.ASOResourceSpecGetter[*asonetwo
412412
NatGatewayIP: infrav1.PublicIPSpec{
413413
Name: subnet.NatGateway.NatGatewayIP.Name,
414414
},
415+
Zones: subnet.NatGateway.Zones,
415416
AdditionalTags: s.AdditionalTags(),
416417
// We need to know if the VNet is managed to decide if this NAT Gateway was-managed or not.
417418
IsVnetManaged: s.IsVnetManaged(),

azure/services/natgateways/spec.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type NatGatewaySpec struct {
3636
Location string
3737
NatGatewayIP infrav1.PublicIPSpec
3838
ClusterName string
39+
Zones []string
3940
AdditionalTags infrav1.Tags
4041
IsVnetManaged bool
4142
}
@@ -79,6 +80,9 @@ func (s *NatGatewaySpec) Parameters(_ context.Context, existingNatGateway *asone
7980
Name: ptr.To(s.Name),
8081
Additional: s.AdditionalTags,
8182
})
83+
if len(s.Zones) != 0 {
84+
natGateway.Spec.Zones = s.Zones
85+
}
8286

8387
return natGateway, nil
8488
}

azure/services/natgateways/spec_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var (
3636
ResourceGroup: "my-rg",
3737
SubscriptionID: "123",
3838
Location: "eastus",
39+
Zones: []string{"eastus-1"},
3940
NatGatewayIP: infrav1.PublicIPSpec{
4041
Name: "my-natgateway-ip",
4142
DNSName: "Standard",
@@ -59,6 +60,7 @@ var (
5960
AzureName: "my-natgateway",
6061
IdleTimeoutInMinutes: ptr.To(6),
6162
Location: locationPtr,
63+
Zones: []string{"eastus-1"},
6264
Owner: &genruntime.KnownResourceReference{
6365
Name: "my-rg",
6466
},
@@ -114,6 +116,8 @@ func TestParameters(t *testing.T) {
114116
g.Expect(parameters.Spec.Owner.Name).To(Equal("my-rg"))
115117
g.Expect(parameters.Spec.Location).NotTo(BeNil())
116118
g.Expect(parameters.Spec.Location).To(Equal(locationPtr))
119+
g.Expect(parameters.Spec.Zones).To(HaveLen(1))
120+
g.Expect(parameters.Spec.Zones[0]).To(Equal("eastus-1"))
117121
g.Expect(parameters.Spec.Sku.Name).NotTo(BeNil())
118122
g.Expect(parameters.Spec.Sku.Name).To(Equal(standardSKUPtr))
119123
g.Expect(parameters.Spec.PublicIpAddresses).To(HaveLen(1))

config/crd/bases/infrastructure.cluster.x-k8s.io_azureclusters.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ spec:
215215
type: object
216216
name:
217217
type: string
218+
zones:
219+
description: Zones mentions the list of zones the
220+
NAT gateway should be a part of.
221+
items:
222+
type: string
223+
type: array
218224
required:
219225
- name
220226
type: object
@@ -995,6 +1001,12 @@ spec:
9951001
type: object
9961002
name:
9971003
type: string
1004+
zones:
1005+
description: Zones mentions the list of zones the
1006+
NAT gateway should be a part of.
1007+
items:
1008+
type: string
1009+
type: array
9981010
required:
9991011
- name
10001012
type: object

config/crd/bases/infrastructure.cluster.x-k8s.io_azureclustertemplates.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ spec:
106106
properties:
107107
name:
108108
type: string
109+
zones:
110+
description: Zones mentions the list of zones the
111+
NAT gateway should be a part of.
112+
items:
113+
type: string
114+
type: array
109115
required:
110116
- name
111117
type: object
@@ -625,6 +631,12 @@ spec:
625631
properties:
626632
name:
627633
type: string
634+
zones:
635+
description: Zones mentions the list of zones the
636+
NAT gateway should be a part of.
637+
items:
638+
type: string
639+
type: array
628640
required:
629641
- name
630642
type: object

0 commit comments

Comments
 (0)