Skip to content

Commit 636d6b0

Browse files
{AKS} az aks: require StandardV2 for V2 params on update, fix ipv6 count range [1,16], and preserve IPv4 default of 1
1 parent 03fd7cc commit 636d6b0

4 files changed

Lines changed: 47 additions & 12 deletions

File tree

src/azure-cli/azure/cli/command_modules/acs/_natgateway.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ def configure_nat_gateway_profile(
9292
profile.managed_outbound_ip_profile = ManagedClusterManagedOutboundIPProfile()
9393
if managed_outbound_ip_count is not None:
9494
profile.managed_outbound_ip_profile.count = managed_outbound_ip_count
95+
elif profile.managed_outbound_ip_profile.count is None:
96+
# SDK 41.6 no longer materializes the IPv4 default; keep the documented default of 1.
97+
profile.managed_outbound_ip_profile.count = 1
9598
if managed_outbound_ipv6_count is not None:
9699
profile.managed_outbound_ip_profile.count_ipv6 = managed_outbound_ipv6_count
97100

src/azure-cli/azure/cli/command_modules/acs/_validators.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ def validate_nat_gateway_managed_outbound_ipv6_count(namespace):
360360
"""validate NAT gateway profile managed outbound IPv6 count (StandardV2, dual-stack only)"""
361361
ipv6_count = namespace.nat_gateway_managed_outbound_ipv6_count
362362
if ipv6_count is not None:
363-
if ipv6_count < 0 or ipv6_count > 16:
363+
if ipv6_count < 1 or ipv6_count > 16:
364364
raise InvalidArgumentValueError(
365-
"--nat-gateway-managed-outbound-ipv6-count must be in the range [0,16]"
365+
"--nat-gateway-managed-outbound-ipv6-count must be in the range [1,16]"
366366
)
367367

368368

@@ -425,10 +425,12 @@ def validate_nat_gateway_v2_params(namespace):
425425
def validate_nat_gateway_v2_params_for_update(namespace):
426426
"""Validate the V2-only NAT gateway params on update.
427427
428-
As on create these require the StandardV2 tier; omitting --outbound-type-sku is tolerated
429-
(defaults to StandardV2 where the region supports it) and only an explicit Standard SKU is
430-
rejected. Unlike create, --outbound-type may be omitted when the cluster is already managed NAT
431-
gateway; an explicit non-managed-NAT-gateway outbound type is also rejected.
428+
The V2-only params (managed IPv6 count, BYO outbound IPs / IP prefixes) require the StandardV2
429+
tier. Unlike create, an omitted --outbound-type-sku is not a "default to StandardV2": on update
430+
the RP preserves the cluster's existing SKU (which may be Standard), so the V2-only params
431+
require an explicit --outbound-type-sku StandardV2. --outbound-type may be omitted when the
432+
cluster is already managed NAT gateway; an explicit non-managed-NAT-gateway outbound type is
433+
also rejected.
432434
"""
433435
v2_params = [
434436
getattr(namespace, 'nat_gateway_managed_outbound_ipv6_count', None),
@@ -437,9 +439,9 @@ def validate_nat_gateway_v2_params_for_update(namespace):
437439
]
438440
if not any(p is not None for p in v2_params):
439441
return
440-
# Omitting the sku defaults to StandardV2 where supported, so only an explicit Standard is rejected.
442+
# On update the RP preserves the existing SKU (possibly Standard), so require an explicit StandardV2.
441443
if (namespace.outbound_type is not None and namespace.outbound_type != 'managedNATGateway') or \
442-
getattr(namespace, 'nat_gateway_sku', None) == 'Standard':
444+
getattr(namespace, 'nat_gateway_sku', None) != 'StandardV2':
443445
raise InvalidArgumentValueError(
444446
"--nat-gateway-managed-outbound-ipv6-count, --nat-gateway-outbound-ips and "
445447
"--nat-gateway-outbound-ip-prefixes are only valid with --outbound-type managedNATGateway "

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_natgateway.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,27 @@ def test_create_with_sku_and_v2_params(self):
121121
self.assertEqual(profile.outbound_ip_prefixes.public_ip_prefixes, ["/sub/pfx1"])
122122
self.assertEqual(profile.idle_timeout_in_minutes, 10)
123123

124+
def test_create_ipv6_only_defaults_ipv4_count(self):
125+
# Only an IPv6 count is provided; the IPv4 count must fall back to the documented default of 1.
126+
profile = natgateway.create_nat_gateway_profile(
127+
None, None, models=self.nat_gateway_models,
128+
managed_outbound_ipv6_count=3,
129+
nat_gateway_sku="StandardV2",
130+
)
131+
self.assertEqual(profile.managed_outbound_ip_profile.count, 1)
132+
self.assertEqual(profile.managed_outbound_ip_profile.count_ipv6, 3)
133+
134+
def test_update_ipv6_only_preserves_existing_ipv4_count(self):
135+
origin = self.nat_gateway_models.ManagedClusterNATGatewayProfile(
136+
managed_outbound_ip_profile=self.nat_gateway_models.ManagedClusterManagedOutboundIPProfile(count=5),
137+
)
138+
profile = natgateway.update_nat_gateway_profile(
139+
None, None, origin, models=self.nat_gateway_models,
140+
managed_outbound_ipv6_count=2,
141+
)
142+
self.assertEqual(profile.managed_outbound_ip_profile.count, 5)
143+
self.assertEqual(profile.managed_outbound_ip_profile.count_ipv6, 2)
144+
124145
def test_create_sku_only(self):
125146
profile = natgateway.create_nat_gateway_profile(
126147
None, None, models=self.nat_gateway_models, nat_gateway_sku="StandardV2"

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,14 +2082,23 @@ def test_v2_params_create_requires_managed_nat_gateway_and_v2_sku(self):
20822082
validators.validate_nat_gateway_v2_params(self._ns(nat_gateway_managed_outbound_ipv6_count=1, outbound_type="managedNATGateway", nat_gateway_sku="Standard"))
20832083
validators.validate_nat_gateway_v2_params(self._ns(outbound_type="loadBalancer"))
20842084

2085-
def test_v2_params_update_allows_omitted_outbound_type(self):
2086-
validators.validate_nat_gateway_v2_params_for_update(self._ns(nat_gateway_managed_outbound_ipv6_count=1, outbound_type=None))
2085+
def test_v2_params_update_requires_v2_sku(self):
2086+
# On update the RP preserves the existing SKU (possibly Standard), so V2 params require an
2087+
# explicit StandardV2; a sku-less update is rejected.
2088+
validators.validate_nat_gateway_v2_params_for_update(self._ns(nat_gateway_managed_outbound_ipv6_count=1, outbound_type=None, nat_gateway_sku="StandardV2"))
2089+
validators.validate_nat_gateway_v2_params_for_update(self._ns(nat_gateway_managed_outbound_ipv6_count=1, outbound_type="managedNATGateway", nat_gateway_sku="StandardV2"))
20872090
with self.assertRaises(InvalidArgumentValueError):
2088-
validators.validate_nat_gateway_v2_params_for_update(self._ns(nat_gateway_outbound_ip_ids="/sub/ip", outbound_type="loadBalancer"))
2091+
validators.validate_nat_gateway_v2_params_for_update(self._ns(nat_gateway_managed_outbound_ipv6_count=1, outbound_type=None))
2092+
with self.assertRaises(InvalidArgumentValueError):
2093+
validators.validate_nat_gateway_v2_params_for_update(self._ns(nat_gateway_managed_outbound_ipv6_count=1, outbound_type=None, nat_gateway_sku="Standard"))
2094+
with self.assertRaises(InvalidArgumentValueError):
2095+
validators.validate_nat_gateway_v2_params_for_update(self._ns(nat_gateway_outbound_ip_ids="/sub/ip", outbound_type="loadBalancer", nat_gateway_sku="StandardV2"))
20892096

20902097
def test_ipv6_count_range(self):
2091-
validators.validate_nat_gateway_managed_outbound_ipv6_count(self._ns(nat_gateway_managed_outbound_ipv6_count=0))
2098+
validators.validate_nat_gateway_managed_outbound_ipv6_count(self._ns(nat_gateway_managed_outbound_ipv6_count=1))
20922099
validators.validate_nat_gateway_managed_outbound_ipv6_count(self._ns(nat_gateway_managed_outbound_ipv6_count=16))
2100+
with self.assertRaises(InvalidArgumentValueError):
2101+
validators.validate_nat_gateway_managed_outbound_ipv6_count(self._ns(nat_gateway_managed_outbound_ipv6_count=0))
20932102
with self.assertRaises(InvalidArgumentValueError):
20942103
validators.validate_nat_gateway_managed_outbound_ipv6_count(self._ns(nat_gateway_managed_outbound_ipv6_count=17))
20952104

0 commit comments

Comments
 (0)