Skip to content

Commit 321f09a

Browse files
aks-preview: Fix V2 NAT gateway params rejected on update without --outbound-type
The validate_nat_gateway_v2_params validator required --outbound-type managedNATGatewayV2 to be explicitly passed even on updates where the cluster is already V2. Users had to re-specify --outbound-type on every update that used V2-only params like --nat-gateway-managed-outbound-ipv6-count. Fix: Only reject V2 params when --outbound-type is explicitly set to a non-V2 value. When --outbound-type is not specified (None), allow the request through and let the RP validate.
1 parent 784a113 commit 321f09a

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

src/aks-preview/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ To release a new version, please select a new version number (usually plus 1 to
1212
Pending
1313
+++++++
1414

15+
20.0.0b2
16+
+++++++
17+
* `az aks update`: Fix V2-only NAT gateway params (e.g. `--nat-gateway-managed-outbound-ipv6-count`) being rejected on update when `--outbound-type` is not re-specified for an already-V2 cluster.
18+
1519
20.0.0b1
1620
+++++++
1721
* [Breaking Change] `az aks create/update`: Change `--nat-gateway-outbound-ips` and `--nat-gateway-outbound-ip-prefixes` to use comma-separated values, consistent with load balancer outbound IP parameters.

src/aks-preview/azext_aks_preview/_validators.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,15 +1168,19 @@ def validate_nat_gateway_managed_outbound_ipv6_count(namespace):
11681168

11691169

11701170
def validate_nat_gateway_v2_params(namespace):
1171-
"""Validate that V2-only NAT gateway params require managedNATGatewayV2."""
1171+
"""Validate that V2-only NAT gateway params require managedNATGatewayV2.
1172+
1173+
On update, --outbound-type may not be specified if the cluster is already V2.
1174+
Only reject when --outbound-type is explicitly set to a non-V2 value.
1175+
"""
11721176
v2_params = [
11731177
getattr(namespace, 'nat_gateway_managed_outbound_ipv6_count', None),
11741178
getattr(namespace, 'nat_gateway_outbound_ip_ids', None),
11751179
getattr(namespace, 'nat_gateway_outbound_ip_prefix_ids', None),
11761180
]
11771181
if any(p is not None for p in v2_params):
11781182
outbound_type = getattr(namespace, 'outbound_type', None)
1179-
if outbound_type != 'managedNATGatewayV2':
1183+
if outbound_type is not None and outbound_type != 'managedNATGatewayV2':
11801184
raise InvalidArgumentValueError(
11811185
"--nat-gateway-managed-outbound-ipv6-count, "
11821186
"--nat-gateway-outbound-ips, and "

src/aks-preview/azext_aks_preview/tests/latest/test_natgateway.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,55 @@ def test_all_none(self):
235235
self.assertFalse(result)
236236

237237

238+
class TestValidateNatGatewayV2Params(unittest.TestCase):
239+
"""Test the cross-parameter validator for V2-only params."""
240+
241+
def _make_namespace(self, **kwargs):
242+
from types import SimpleNamespace
243+
defaults = {
244+
'nat_gateway_managed_outbound_ipv6_count': None,
245+
'nat_gateway_outbound_ip_ids': None,
246+
'nat_gateway_outbound_ip_prefix_ids': None,
247+
'outbound_type': None,
248+
}
249+
defaults.update(kwargs)
250+
return SimpleNamespace(**defaults)
251+
252+
def test_v2_params_allowed_when_outbound_type_is_v2(self):
253+
from azext_aks_preview._validators import validate_nat_gateway_v2_params
254+
ns = self._make_namespace(
255+
nat_gateway_managed_outbound_ipv6_count=4,
256+
outbound_type='managedNATGatewayV2',
257+
)
258+
# Should not raise
259+
validate_nat_gateway_v2_params(ns)
260+
261+
def test_v2_params_allowed_when_outbound_type_not_specified(self):
262+
"""On update, outbound_type may be None if cluster is already V2."""
263+
from azext_aks_preview._validators import validate_nat_gateway_v2_params
264+
ns = self._make_namespace(
265+
nat_gateway_managed_outbound_ipv6_count=3,
266+
outbound_type=None,
267+
)
268+
# Should not raise — let RP validate
269+
validate_nat_gateway_v2_params(ns)
270+
271+
def test_v2_params_rejected_when_outbound_type_is_non_v2(self):
272+
from azure.cli.core.azclierror import InvalidArgumentValueError
273+
from azext_aks_preview._validators import validate_nat_gateway_v2_params
274+
ns = self._make_namespace(
275+
nat_gateway_managed_outbound_ipv6_count=4,
276+
outbound_type='loadBalancer',
277+
)
278+
with self.assertRaises(InvalidArgumentValueError):
279+
validate_nat_gateway_v2_params(ns)
280+
281+
def test_no_v2_params_passes_always(self):
282+
from azext_aks_preview._validators import validate_nat_gateway_v2_params
283+
ns = self._make_namespace(outbound_type='loadBalancer')
284+
# No V2 params set, should not raise
285+
validate_nat_gateway_v2_params(ns)
286+
287+
238288
if __name__ == '__main__':
239289
unittest.main()

src/aks-preview/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from setuptools import find_packages, setup
1111

12-
VERSION = "20.0.0b1"
12+
VERSION = "20.0.0b2"
1313

1414
CLASSIFIERS = [
1515
"Development Status :: 4 - Beta",

0 commit comments

Comments
 (0)