Skip to content

Commit 1332e20

Browse files
authored
{AKS} fix InvalidParameter error when add Machines nodepool (#9689)
1 parent 0898ef9 commit 1332e20

9 files changed

Lines changed: 3088 additions & 5237 deletions

src/aks-preview/HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ To release a new version, please select a new version number (usually plus 1 to
1111

1212
Pending
1313
+++++++
14+
15+
19.0.0b27
16+
+++++++
17+
* `az aks nodepool add`: Fix `InvalidParameter` error when `mode` is `Machines`.
18+
1419
19.0.0b26
1520
+++++++
1621
* `az aks create/update`: Add `--enable-app-routing-istio` / `--disable-app-routing-istio` (short: `--enable-ari` / `--disable-ari`) flags to enable or disable Istio as a Gateway API implementation for App Routing.

src/aks-preview/azext_aks_preview/agentpool_decorator.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
CONST_SSH_ACCESS_LOCALUSER,
4747
CONST_GPU_DRIVER_NONE,
4848
CONST_NODEPOOL_MODE_MANAGEDSYSTEM,
49+
CONST_NODEPOOL_MODE_MACHINES,
4950
)
5051
from azext_aks_preview._helpers import (
5152
get_nodepool_snapshot_by_snapshot_id,
@@ -1452,6 +1453,25 @@ def set_up_managed_system_mode(self, agentpool: AgentPool) -> AgentPool:
14521453

14531454
return agentpool
14541455

1456+
def set_up_machines_mode(self, agentpool: AgentPool) -> AgentPool:
1457+
"""Handle the special Machines mode by resetting all properties except name and mode.
1458+
1459+
:param agentpool: the AgentPool object
1460+
:return: the AgentPool object
1461+
"""
1462+
self._ensure_agentpool(agentpool)
1463+
1464+
mode = self.context.get_mode()
1465+
if mode == CONST_NODEPOOL_MODE_MACHINES:
1466+
agentpool.mode = CONST_NODEPOOL_MODE_MACHINES
1467+
# Make sure all other attributes are None
1468+
for attr in vars(agentpool):
1469+
if attr != 'name' and attr != 'mode' and not attr.startswith('_'):
1470+
if hasattr(agentpool, attr):
1471+
setattr(agentpool, attr, None)
1472+
1473+
return agentpool
1474+
14551475
def set_up_localdns_profile(self, agentpool: AgentPool) -> AgentPool:
14561476
"""Set up local DNS profile for the AgentPool object if provided via --localdns-config."""
14571477
self._ensure_agentpool(agentpool)
@@ -1468,11 +1488,12 @@ def construct_agentpool_profile_preview(self) -> AgentPool:
14681488
# DO NOT MOVE: keep this on top, construct the default AgentPool profile
14691489
agentpool = self.construct_agentpool_profile_default(bypass_restore_defaults=True)
14701490

1471-
# Check if mode is ManagedSystem, if yes, reset all properties
1491+
# Check if mode is ManagedSystem or Machines, if yes, reset all other properties
14721492
agentpool = self.set_up_managed_system_mode(agentpool)
1493+
agentpool = self.set_up_machines_mode(agentpool)
14731494

1474-
# If mode is ManagedSystem, skip all other property setups
1475-
if agentpool.mode == CONST_NODEPOOL_MODE_MANAGEDSYSTEM:
1495+
# If mode is ManagedSystem or Machines, skip all other property setups
1496+
if agentpool.mode == CONST_NODEPOOL_MODE_MANAGEDSYSTEM or agentpool.mode == CONST_NODEPOOL_MODE_MACHINES:
14761497
return agentpool
14771498

14781499
# set up preview vm properties

src/aks-preview/azext_aks_preview/tests/latest/recordings/test_aks_machine_add_cmds.yaml

Lines changed: 0 additions & 1795 deletions
This file was deleted.

src/aks-preview/azext_aks_preview/tests/latest/recordings/test_aks_machine_update_cmds.yaml

Lines changed: 0 additions & 2483 deletions
This file was deleted.

src/aks-preview/azext_aks_preview/tests/latest/recordings/test_aks_machines_nodepool.yaml

Lines changed: 2907 additions & 0 deletions
Large diffs are not rendered by default.

src/aks-preview/azext_aks_preview/tests/latest/recordings/test_aks_nodepool_create_machines_pool.yaml

Lines changed: 0 additions & 807 deletions
This file was deleted.

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
CONST_MANAGED_CLUSTER_SKU_NAME_AUTOMATIC,
3838
CONST_GPU_DRIVER_NONE,
3939
CONST_NODEPOOL_MODE_MANAGEDSYSTEM,
40+
CONST_NODEPOOL_MODE_MACHINES,
4041
)
4142
from azure.cli.command_modules.acs.agentpool_decorator import AKSAgentPoolParamDict
4243
from azure.cli.command_modules.acs.tests.latest.mocks import (
@@ -1724,6 +1725,41 @@ def common_set_up_managed_system_mode(self):
17241725
# Verify that agentpool is returned unchanged
17251726
self.assertEqual(dec_agentpool_3, original_agentpool_3)
17261727

1728+
def common_set_up_machines_mode(self):
1729+
dec_1 = AKSPreviewAgentPoolAddDecorator(
1730+
self.cmd,
1731+
self.client,
1732+
{"mode": CONST_NODEPOOL_MODE_MACHINES},
1733+
self.resource_type,
1734+
self.agentpool_decorator_mode,
1735+
)
1736+
1737+
# fail on passing the wrong agentpool object
1738+
with self.assertRaises(CLIInternalError):
1739+
dec_1.set_up_machines_mode(None)
1740+
1741+
# Create an agentpool with various properties set
1742+
agentpool_1 = self.create_initialized_agentpool_instance(
1743+
restore_defaults=False,
1744+
count=3,
1745+
vm_size="Standard_D2s_v3",
1746+
os_type="Linux",
1747+
enable_auto_scaling=True,
1748+
min_count=1,
1749+
max_count=5,
1750+
)
1751+
dec_1.context.attach_agentpool(agentpool_1)
1752+
1753+
original_name = agentpool_1.name
1754+
dec_agentpool_1 = dec_1.set_up_machines_mode(agentpool_1)
1755+
self.assertEqual(dec_agentpool_1.name, original_name)
1756+
self.assertEqual(dec_agentpool_1.mode, CONST_NODEPOOL_MODE_MACHINES)
1757+
for attr_name in vars(dec_agentpool_1):
1758+
if attr_name not in ['name', 'mode'] and not attr_name.startswith('_'):
1759+
attr_value = getattr(dec_agentpool_1, attr_name)
1760+
self.assertIsNone(attr_value,
1761+
f"Attribute '{attr_name}' should be None but was '{attr_value}'")
1762+
17271763
def common_construct_agentpool_profile_preview_with_managed_system_mode(self):
17281764
"""Test that construct_agentpool_profile_preview properly handles ManagedSystem mode"""
17291765

@@ -1765,6 +1801,47 @@ def common_construct_agentpool_profile_preview_with_managed_system_mode(self):
17651801
self.assertIsNone(attr_value,
17661802
f"Attribute '{attr_name}' should be None but was '{attr_value}' when mode is ManagedSystem")
17671803

1804+
def common_construct_agentpool_profile_preview_with_machines_mode(self):
1805+
"""Test that construct_agentpool_profile_preview properly handles Machines mode"""
1806+
1807+
# Test that when mode is Machines, only name and mode are preserved,
1808+
# and all other property setup methods are bypassed
1809+
dec = AKSPreviewAgentPoolAddDecorator(
1810+
self.cmd,
1811+
self.client,
1812+
{
1813+
"nodepool_name": "testnp",
1814+
"mode": CONST_NODEPOOL_MODE_MACHINES,
1815+
# Add some parameters that would normally set properties
1816+
"node_count": 3,
1817+
"node_vm_size": "Standard_D2s_v3",
1818+
"crg_id": "test_crg_id",
1819+
"enable_artifact_streaming": True,
1820+
},
1821+
self.resource_type,
1822+
self.agentpool_decorator_mode,
1823+
)
1824+
1825+
# Construct the agentpool profile with mocked Azure API calls
1826+
with patch(
1827+
"azext_aks_preview.agentpool_decorator.cf_agent_pools",
1828+
return_value=Mock(list=Mock(return_value=[])),
1829+
):
1830+
agentpool = dec.construct_agentpool_profile_preview()
1831+
1832+
# Verify that name is preserved
1833+
self.assertEqual(agentpool.name, "testnp")
1834+
1835+
# Verify that mode is set to Machines
1836+
self.assertEqual(agentpool.mode, CONST_NODEPOOL_MODE_MACHINES)
1837+
1838+
# Verify that all other properties are None (bypassed)
1839+
for attr_name in vars(agentpool):
1840+
if attr_name not in ['name', 'mode'] and not attr_name.startswith('_'):
1841+
attr_value = getattr(agentpool, attr_name)
1842+
self.assertIsNone(attr_value,
1843+
f"Attribute '{attr_name}' should be None but was '{attr_value}' when mode is Machines")
1844+
17681845
def common_set_up_upgrade_strategy(self):
17691846
# Test case 1: No upgrade strategy provided
17701847
dec_1 = AKSPreviewAgentPoolAddDecorator(
@@ -1946,6 +2023,9 @@ def test_set_up_virtual_machines_profile(self):
19462023
def test_set_up_managed_system_mode(self):
19472024
self.common_set_up_managed_system_mode()
19482025

2026+
def test_set_up_machines_mode(self):
2027+
self.common_set_up_machines_mode()
2028+
19492029
def test_set_up_upgrade_strategy(self):
19502030
self.common_set_up_upgrade_strategy()
19512031

@@ -2034,6 +2114,9 @@ def test_set_up_blue_green_upgrade_settings(self):
20342114
def test_construct_agentpool_profile_preview_with_managed_system_mode(self):
20352115
self.common_construct_agentpool_profile_preview_with_managed_system_mode()
20362116

2117+
def test_construct_agentpool_profile_preview_with_machines_mode(self):
2118+
self.common_construct_agentpool_profile_preview_with_machines_mode()
2119+
20372120

20382121
class AKSPreviewAgentPoolAddDecoratorManagedClusterModeTestCase(
20392122
AKSPreviewAgentPoolAddDecoratorCommonTestCase
@@ -2083,6 +2166,9 @@ def test_set_up_virtual_machines_profile(self):
20832166
def test_set_up_managed_system_mode(self):
20842167
self.common_set_up_managed_system_mode()
20852168

2169+
def test_set_up_machines_mode(self):
2170+
self.common_set_up_machines_mode()
2171+
20862172
def test_set_up_upgrade_strategy(self):
20872173
self.common_set_up_upgrade_strategy()
20882174

0 commit comments

Comments
 (0)