Skip to content

Commit ba2665c

Browse files
aks-preview: Add managedNATGatewayV2 outbound type support
Add support for the managedNATGatewayV2 outbound type which uses Azure NAT Gateway Standard V2 SKU. New CLI parameters: - --nat-gateway-managed-outbound-ipv6-count: IPv6 managed IPs (1-16, dual-stack) - --nat-gateway-outbound-ip-ids: User-provided public IP resource IDs - --nat-gateway-outbound-ip-prefix-ids: User-provided IP prefix resource IDs These are valid only with --outbound-type managedNATGatewayV2.
1 parent 2286135 commit ba2665c

File tree

7 files changed

+317
-21
lines changed

7 files changed

+317
-21
lines changed

src/aks-preview/azext_aks_preview/_consts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@
377377

378378
CONST_OUTBOUND_TYPE_NONE = "none"
379379
CONST_OUTBOUND_TYPE_BLOCK = "block"
380+
CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY_V2 = "managedNATGatewayV2"
380381

381382
# IMDS restriction consts
382383
CONST_IMDS_RESTRICTION_ENABLED = "None"

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,27 @@
158158
- name: --nat-gateway-managed-outbound-ip-count
159159
type: int
160160
short-summary: NAT gateway managed outbound IP count.
161-
long-summary: Desired number of managed outbound IPs for NAT gateway outbound connection. Please specify a value in the range of [1, 16]. Valid for Standard SKU load balancer cluster with managedNATGateway outbound type only.
161+
long-summary: Desired number of managed outbound IPs for NAT gateway outbound connection. Please specify a value in the range of [1, 16]. Valid for Standard SKU load balancer cluster with managedNATGateway or managedNATGatewayV2 outbound type only.
162162
- name: --nat-gateway-idle-timeout
163163
type: int
164164
short-summary: NAT gateway idle timeout in minutes.
165-
long-summary: Desired idle timeout for NAT gateway outbound flows, default is 4 minutes. Please specify a value in the range of [4, 120]. Valid for Standard SKU load balancer cluster with managedNATGateway outbound type only.
165+
long-summary: Desired idle timeout for NAT gateway outbound flows, default is 4 minutes. Please specify a value in the range of [4, 120]. Valid for Standard SKU load balancer cluster with managedNATGateway or managedNATGatewayV2 outbound type only.
166+
- name: --nat-gateway-managed-outbound-ipv6-count
167+
type: int
168+
short-summary: NAT gateway managed outbound IPv6 IP count.
169+
long-summary: Desired number of managed outbound IPv6 IPs for NAT gateway on dual-stack clusters. Please specify a value in the range of [1, 16]. Valid only with --outbound-type managedNATGatewayV2.
170+
- name: --nat-gateway-outbound-ip-ids
171+
type: string
172+
short-summary: NAT gateway outbound IP resource IDs.
173+
long-summary: Space-separated list of public IP resource IDs for the cluster NAT gateway. Valid only with --outbound-type managedNATGatewayV2. Mutually exclusive with --nat-gateway-managed-outbound-ip-count.
174+
- name: --nat-gateway-outbound-ip-prefix-ids
175+
type: string
176+
short-summary: NAT gateway outbound IP prefix resource IDs.
177+
long-summary: Space-separated list of public IP prefix resource IDs for the cluster NAT gateway. Valid only with --outbound-type managedNATGatewayV2. Mutually exclusive with --nat-gateway-managed-outbound-ip-count.
166178
- name: --outbound-type
167179
type: string
168180
short-summary: How outbound traffic will be configured for a cluster.
169-
long-summary: Select between loadBalancer, userDefinedRouting, managedNATGateway, userAssignedNATGateway, none and block. If not set, defaults to type loadBalancer. Requires --vnet-subnet-id to be provided with a preconfigured route table and --load-balancer-sku to be Standard.
181+
long-summary: Select between loadBalancer, userDefinedRouting, managedNATGateway, managedNATGatewayV2, userAssignedNATGateway, none and block. If not set, defaults to type loadBalancer. managedNATGatewayV2 uses Azure NAT Gateway Standard V2 SKU and supports IPv6, user-provided public IPs, and user-provided IP prefixes.
170182
- name: --enable-addons -a
171183
type: string
172184
short-summary: Enable the Kubernetes addons in a comma-separated list.
@@ -928,15 +940,27 @@
928940
- name: --nat-gateway-managed-outbound-ip-count
929941
type: int
930942
short-summary: NAT gateway managed outbound IP count.
931-
long-summary: Desired number of managed outbound IPs for NAT gateway outbound connection. Please specify a value in the range of [1, 16]. Valid for Standard SKU load balancer cluster with managedNATGateway outbound type only.
943+
long-summary: Desired number of managed outbound IPs for NAT gateway outbound connection. Please specify a value in the range of [1, 16]. Valid for Standard SKU load balancer cluster with managedNATGateway or managedNATGatewayV2 outbound type only.
932944
- name: --nat-gateway-idle-timeout
933945
type: int
934946
short-summary: NAT gateway idle timeout in minutes.
935-
long-summary: Desired idle timeout for NAT gateway outbound flows, default is 4 minutes. Please specify a value in the range of [4, 120]. Valid for Standard SKU load balancer cluster with managedNATGateway outbound type only.
947+
long-summary: Desired idle timeout for NAT gateway outbound flows, default is 4 minutes. Please specify a value in the range of [4, 120]. Valid for Standard SKU load balancer cluster with managedNATGateway or managedNATGatewayV2 outbound type only.
948+
- name: --nat-gateway-managed-outbound-ipv6-count
949+
type: int
950+
short-summary: NAT gateway managed outbound IPv6 IP count.
951+
long-summary: Desired number of managed outbound IPv6 IPs for NAT gateway on dual-stack clusters. Please specify a value in the range of [1, 16]. Valid only with --outbound-type managedNATGatewayV2.
952+
- name: --nat-gateway-outbound-ip-ids
953+
type: string
954+
short-summary: NAT gateway outbound IP resource IDs.
955+
long-summary: Space-separated list of public IP resource IDs for the cluster NAT gateway. Valid only with --outbound-type managedNATGatewayV2. Mutually exclusive with --nat-gateway-managed-outbound-ip-count.
956+
- name: --nat-gateway-outbound-ip-prefix-ids
957+
type: string
958+
short-summary: NAT gateway outbound IP prefix resource IDs.
959+
long-summary: Space-separated list of public IP prefix resource IDs for the cluster NAT gateway. Valid only with --outbound-type managedNATGatewayV2. Mutually exclusive with --nat-gateway-managed-outbound-ip-count.
936960
- name: --outbound-type
937961
type: string
938962
short-summary: How outbound traffic will be configured for a cluster.
939-
long-summary: This option will change the way how the outbound connections are managed in the AKS cluster. Available options are loadbalancer, managedNATGateway, userAssignedNATGateway, userDefinedRouting, none and block. For custom vnet, loadbalancer, userAssignedNATGateway and userDefinedRouting are supported. For aks managed vnet, loadbalancer, managedNATGateway and userDefinedRouting are supported.
963+
long-summary: This option will change the way how the outbound connections are managed in the AKS cluster. Available options are loadbalancer, managedNATGateway, managedNATGatewayV2, userAssignedNATGateway, userDefinedRouting, none and block.
940964
- name: --nrg-lockdown-restriction-level
941965
type: string
942966
short-summary: Restriction level on the managed node resource.

src/aks-preview/azext_aks_preview/_natgateway.py

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,99 @@
66
from types import SimpleNamespace
77

88

9-
def create_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, models: SimpleNamespace):
9+
def create_nat_gateway_profile(
10+
managed_outbound_ip_count,
11+
idle_timeout,
12+
models: SimpleNamespace,
13+
managed_outbound_ipv6_count=None,
14+
outbound_ip_ids=None,
15+
outbound_ip_prefix_ids=None,
16+
):
1017
"""parse and build NAT gateway profile"""
11-
if not is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout):
18+
if not is_nat_gateway_profile_provided(
19+
managed_outbound_ip_count, idle_timeout,
20+
managed_outbound_ipv6_count, outbound_ip_ids, outbound_ip_prefix_ids,
21+
):
1222
return None
1323

1424
profile = models.ManagedClusterNATGatewayProfile()
15-
return configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models)
25+
return configure_nat_gateway_profile(
26+
managed_outbound_ip_count, idle_timeout, profile, models,
27+
managed_outbound_ipv6_count, outbound_ip_ids, outbound_ip_prefix_ids,
28+
)
1629

1730

18-
def update_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models: SimpleNamespace):
31+
def update_nat_gateway_profile(
32+
managed_outbound_ip_count,
33+
idle_timeout,
34+
profile,
35+
models: SimpleNamespace,
36+
managed_outbound_ipv6_count=None,
37+
outbound_ip_ids=None,
38+
outbound_ip_prefix_ids=None,
39+
):
1940
"""parse and update an existing NAT gateway profile"""
20-
if not is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout):
41+
if not is_nat_gateway_profile_provided(
42+
managed_outbound_ip_count, idle_timeout,
43+
managed_outbound_ipv6_count, outbound_ip_ids, outbound_ip_prefix_ids,
44+
):
2145
return profile
2246
if not profile:
2347
profile = models.ManagedClusterNATGatewayProfile()
24-
return configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models)
48+
return configure_nat_gateway_profile(
49+
managed_outbound_ip_count, idle_timeout, profile, models,
50+
managed_outbound_ipv6_count, outbound_ip_ids, outbound_ip_prefix_ids,
51+
)
2552

2653

27-
def is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout):
28-
return any([managed_outbound_ip_count is not None, idle_timeout])
54+
def is_nat_gateway_profile_provided(
55+
managed_outbound_ip_count,
56+
idle_timeout,
57+
managed_outbound_ipv6_count=None,
58+
outbound_ip_ids=None,
59+
outbound_ip_prefix_ids=None,
60+
):
61+
return any([
62+
managed_outbound_ip_count is not None,
63+
idle_timeout,
64+
managed_outbound_ipv6_count is not None,
65+
outbound_ip_ids,
66+
outbound_ip_prefix_ids,
67+
])
2968

3069

31-
def configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models: SimpleNamespace):
70+
def configure_nat_gateway_profile(
71+
managed_outbound_ip_count,
72+
idle_timeout,
73+
profile,
74+
models: SimpleNamespace,
75+
managed_outbound_ipv6_count=None,
76+
outbound_ip_ids=None,
77+
outbound_ip_prefix_ids=None,
78+
):
3279
"""configure a NAT Gateway with customer supplied values"""
33-
if managed_outbound_ip_count is not None:
80+
if managed_outbound_ip_count is not None or managed_outbound_ipv6_count is not None:
3481
ManagedClusterManagedOutboundIPProfile = models.ManagedClusterManagedOutboundIPProfile
35-
profile.managed_outbound_ip_profile = ManagedClusterManagedOutboundIPProfile(
36-
count=managed_outbound_ip_count
37-
)
82+
if not profile.managed_outbound_ip_profile:
83+
profile.managed_outbound_ip_profile = ManagedClusterManagedOutboundIPProfile()
84+
if managed_outbound_ip_count is not None:
85+
profile.managed_outbound_ip_profile.count = managed_outbound_ip_count
86+
if managed_outbound_ipv6_count is not None:
87+
profile.managed_outbound_ip_profile.count_i_pv6 = managed_outbound_ipv6_count
3888

3989
if idle_timeout:
4090
profile.idle_timeout_in_minutes = idle_timeout
4191

92+
if outbound_ip_ids is not None:
93+
ManagedClusterNATGatewayProfileOutboundIPs = models.ManagedClusterNATGatewayProfileOutboundIPs
94+
profile.outbound_i_ps = ManagedClusterNATGatewayProfileOutboundIPs(
95+
public_i_ps=outbound_ip_ids
96+
)
97+
98+
if outbound_ip_prefix_ids is not None:
99+
ManagedClusterNATGatewayProfileOutboundIPPrefixes = models.ManagedClusterNATGatewayProfileOutboundIPPrefixes
100+
profile.outbound_ip_prefixes = ManagedClusterNATGatewayProfileOutboundIPPrefixes(
101+
public_ip_prefixes=outbound_ip_prefix_ids
102+
)
103+
42104
return profile

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
validate_nat_gateway_idle_timeout,
2424
validate_nat_gateway_managed_outbound_ip_count,
2525
)
26+
from azext_aks_preview._validators import ( # pylint: disable=ungrouped-imports
27+
validate_nat_gateway_managed_outbound_ipv6_count,
28+
)
2629
from azure.cli.core.commands.parameters import (
2730
edge_zone_type,
2831
file_type,
@@ -147,6 +150,7 @@
147150
CONST_ARTIFACT_SOURCE_CACHE,
148151
CONST_OUTBOUND_TYPE_NONE,
149152
CONST_OUTBOUND_TYPE_BLOCK,
153+
CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY_V2,
150154
CONST_APP_ROUTING_ANNOTATION_CONTROLLED_NGINX,
151155
CONST_APP_ROUTING_EXTERNAL_NGINX,
152156
CONST_APP_ROUTING_INTERNAL_NGINX,
@@ -371,6 +375,7 @@
371375
CONST_OUTBOUND_TYPE_LOAD_BALANCER,
372376
CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING,
373377
CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY,
378+
CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY_V2,
374379
CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY,
375380
CONST_OUTBOUND_TYPE_NONE,
376381
CONST_OUTBOUND_TYPE_BLOCK,
@@ -659,6 +664,13 @@ def load_arguments(self, _):
659664
type=int,
660665
validator=validate_nat_gateway_idle_timeout,
661666
)
667+
c.argument(
668+
"nat_gateway_managed_outbound_ipv6_count",
669+
type=int,
670+
validator=validate_nat_gateway_managed_outbound_ipv6_count,
671+
)
672+
c.argument("nat_gateway_outbound_ip_ids", nargs="+")
673+
c.argument("nat_gateway_outbound_ip_prefix_ids", nargs="+")
662674
c.argument("outbound_type", arg_type=get_enum_type(outbound_types))
663675
c.argument("network_plugin", arg_type=get_enum_type(network_plugins))
664676
c.argument("network_plugin_mode", arg_type=get_enum_type(network_plugin_modes))
@@ -1247,6 +1259,13 @@ def load_arguments(self, _):
12471259
type=int,
12481260
validator=validate_nat_gateway_idle_timeout,
12491261
)
1262+
c.argument(
1263+
"nat_gateway_managed_outbound_ipv6_count",
1264+
type=int,
1265+
validator=validate_nat_gateway_managed_outbound_ipv6_count,
1266+
)
1267+
c.argument("nat_gateway_outbound_ip_ids", nargs="+")
1268+
c.argument("nat_gateway_outbound_ip_prefix_ids", nargs="+")
12501269
c.argument("network_dataplane", arg_type=get_enum_type(network_dataplanes))
12511270
c.argument("network_policy")
12521271
c.argument("network_plugin", arg_type=get_enum_type(network_plugins))

src/aks-preview/azext_aks_preview/_validators.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,3 +1144,13 @@ def validate_azure_monitor_logs_enable_disable(namespace):
11441144
"Cannot specify both '--enable-azure-monitor-logs' and '--disable-azure-monitor-logs'. "
11451145
"Use either '--enable-azure-monitor-logs' or '--disable-azure-monitor-logs'."
11461146
)
1147+
1148+
1149+
def validate_nat_gateway_managed_outbound_ipv6_count(namespace):
1150+
"""validate NAT gateway profile managed outbound IPv6 count"""
1151+
if namespace.nat_gateway_managed_outbound_ipv6_count is not None:
1152+
if (namespace.nat_gateway_managed_outbound_ipv6_count < 1 or
1153+
namespace.nat_gateway_managed_outbound_ipv6_count > 16):
1154+
raise InvalidArgumentValueError(
1155+
"--nat-gateway-managed-outbound-ipv6-count must be in the range [1,16]"
1156+
)

0 commit comments

Comments
 (0)