Skip to content

Commit c464eba

Browse files
authored
Support ManagedSystem mode NodePool (#8891)
1 parent d50a5de commit c464eba

16 files changed

+6319
-41
lines changed

src/aks-preview/HISTORY.rst

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

1212
Pending
1313
+++++++
14+
* Add support for `ManagedSystem` Agent Pool Mode.
15+
1416
18.0.0b18
1517
+++++++
1618
* Add validation error when neither --location or --cluster and --resource-group-name are specified for az extension type list or az extension type version list
1719

1820

21+
1922
18.0.0b17
2023
+++++++
2124
* Remove `__import__('pkg_resources').declare_namespace(__name__)` from `vendored_sdks/__init__.py`` to fix the namespace package issue.

src/aks-preview/azext_aks_preview/_consts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
CONST_NODEPOOL_MODE_SYSTEM = "System"
2525
CONST_NODEPOOL_MODE_USER = "User"
2626
CONST_NODEPOOL_MODE_GATEWAY = "Gateway"
27+
CONST_NODEPOOL_MODE_MANAGEDSYSTEM = "ManagedSystem"
2728

2829
# os type
2930
CONST_DEFAULT_NODE_OS_TYPE = "Linux"

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,10 @@
650650
- name: --vm-sizes
651651
type: string
652652
short-summary: Comma-separated list of sizes. Must use VirtualMachines agent pool type.
653+
- name: --enable-managed-system-pool
654+
type: bool
655+
short-summary: Create a default ManagedSystem mode that is fully managed by AKS.
656+
long-summary: When set, the default system node pool is created with ManagedSystem mode, where all properties except name and mode are managed by AKS. Learn more at https://aka.ms/aks/nodepool/mode.
653657
examples:
654658
- name: Create a Kubernetes cluster with an existing SSH public key.
655659
text: az aks create -g MyResourceGroup -n MyManagedCluster --ssh-key-value /path/to/publickey
@@ -729,6 +733,8 @@
729733
text: az aks create -g MyResourceGroup -n MyManagedCluster --os-sku Ubuntu --max-pods MaxPodsPerNode --network-plugin azure --vnet-subnet-id /subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/NodeSubnet --pod-subnet-id /subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/PodSubnet --pod-ip-allocation-mode StaticBlock
730734
- name: Create a kubernetes cluster with a VirtualMachines nodepool
731735
text: az aks create -g MyResourceGroup -n MyManagedCluster --vm-set-type VirtualMachines --vm-sizes "VMSize1,VMSize2" --node-count 3
736+
- name: Create a kubernetes cluster with a fully managed system node pool
737+
text: az aks create -g MyResourceGroup -n MyManagedCluster --enable-managed-system-pool
732738
733739
"""
734740

@@ -1933,7 +1939,7 @@
19331939
short-summary: The node labels for the node pool. See https://aka.ms/node-labels for syntax of labels.
19341940
- name: --mode
19351941
type: string
1936-
short-summary: The mode for a node pool which defines a node pool's primary function. If set as "System", AKS prefers system pods scheduling to node pools with mode `System`. Learn more at https://aka.ms/aks/nodepool/mode.
1942+
short-summary: The mode for a node pool which defines a node pool's primary function. If set as "System", AKS prefers system pods scheduling to node pools with mode `System`. If set as "ManagedSystem", all other properties except name and mode will be reset and managed by AKS. Learn more at https://aka.ms/aks/nodepool/mode.
19371943
- name: --vm-set-type
19381944
type: string
19391945
short-summary: Agent pool vm set type. VirtualMachineScaleSets, AvailabilitySet or VirtualMachines(Preview).
@@ -2061,6 +2067,8 @@
20612067
text: az aks nodepool add -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster --os-sku Ubuntu --pod-subnet-id /subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/MySubnet --pod-ip-allocation-mode StaticBlock
20622068
- name: Create a nodepool of type VirtualMachines
20632069
text: az aks nodepool add -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster --vm-set-type VirtualMachines --vm-sizes "Standard_D4s_v3,Standard_D8s_v3" --node-count 3
2070+
- name: Create a nodepool with ManagedSystem mode
2071+
text: az aks nodepool add -g MyResourceGroup -n managedsystem1 --cluster-name MyManagedCluster --mode ManagedSystem
20642072
"""
20652073

20662074
helps['aks nodepool scale'] = """
@@ -2157,7 +2165,7 @@
21572165
short-summary: The maximum number or percentage of extra nodes that are allowed to be blocked in the agent pool during an upgrade when undrainable node behavior is Cordon. When specified, it represents the number or percent used, eg. 1 or 5%.
21582166
- name: --mode
21592167
type: string
2160-
short-summary: The mode for a node pool which defines a node pool's primary function. If set as "System", AKS prefers system pods scheduling to node pools with mode `System`. Learn more at https://aka.ms/aks/nodepool/mode.
2168+
short-summary: The mode for a node pool which defines a node pool's primary function. If set as "System", AKS prefers system pods scheduling to node pools with mode `System`. If set as "ManagedSystem", all other properties except name and mode will be rejected and managed by AKS. Learn more at https://aka.ms/aks/nodepool/mode.
21612169
- name: --labels
21622170
type: string
21632171
short-summary: The node labels for the node pool. See https://aka.ms/node-labels for syntax of labels.

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
CONST_NODEPOOL_MODE_SYSTEM,
8585
CONST_NODEPOOL_MODE_USER,
8686
CONST_NODEPOOL_MODE_GATEWAY,
87+
CONST_NODEPOOL_MODE_MANAGEDSYSTEM,
8788
CONST_NONE_UPGRADE_CHANNEL,
8889
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_READONLY,
8990
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_UNRESTRICTED,
@@ -259,7 +260,12 @@
259260
CONST_SPOT_EVICTION_POLICY_DEALLOCATE,
260261
]
261262
node_os_disk_types = [CONST_OS_DISK_TYPE_MANAGED, CONST_OS_DISK_TYPE_EPHEMERAL]
262-
node_mode_types = [CONST_NODEPOOL_MODE_SYSTEM, CONST_NODEPOOL_MODE_USER, CONST_NODEPOOL_MODE_GATEWAY]
263+
node_mode_types = [
264+
CONST_NODEPOOL_MODE_SYSTEM,
265+
CONST_NODEPOOL_MODE_USER,
266+
CONST_NODEPOOL_MODE_GATEWAY,
267+
CONST_NODEPOOL_MODE_MANAGEDSYSTEM,
268+
]
263269
node_os_skus_create = [
264270
CONST_OS_SKU_AZURELINUX,
265271
CONST_OS_SKU_UBUNTU,
@@ -1066,6 +1072,7 @@ def load_arguments(self, _):
10661072
# virtual machines
10671073
c.argument("vm_sizes", is_preview=True)
10681074
c.argument("enable_imds_restriction", action="store_true", is_preview=True)
1075+
c.argument("enable_managed_system_pool", action="store_true", is_preview=True)
10691076

10701077
with self.argument_context("aks update") as c:
10711078
# managed cluster paramerters

src/aks-preview/azext_aks_preview/agentpool_decorator.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
AKSAgentPoolUpdateDecorator,
1818
)
1919
from azure.cli.core.azclierror import (
20+
CLIInternalError,
2021
InvalidArgumentValueError,
2122
MutuallyExclusiveArgumentError,
2223
)
@@ -41,6 +42,7 @@
4142
CONST_DEFAULT_WINDOWS_VMS_VM_SIZE,
4243
CONST_SSH_ACCESS_LOCALUSER,
4344
CONST_GPU_DRIVER_NONE,
45+
CONST_NODEPOOL_MODE_MANAGEDSYSTEM,
4446
)
4547
from azext_aks_preview._helpers import (
4648
get_nodepool_snapshot_by_snapshot_id,
@@ -1070,6 +1072,33 @@ def set_up_virtual_machines_profile(self, agentpool: AgentPool) -> AgentPool:
10701072

10711073
return agentpool
10721074

1075+
def set_up_managed_system_mode(self, agentpool: AgentPool) -> AgentPool:
1076+
"""Handle the special ManagedSystem mode by resetting all properties except name and mode.
1077+
1078+
:param agentpool: the AgentPool object
1079+
:return: the AgentPool object
1080+
"""
1081+
if self.context.raw_param.get("enable_managed_system_pool") is True:
1082+
mode = CONST_NODEPOOL_MODE_MANAGEDSYSTEM
1083+
else:
1084+
mode = self.context.raw_param.get("mode")
1085+
1086+
if mode == CONST_NODEPOOL_MODE_MANAGEDSYSTEM:
1087+
# Raise error if agentpool is None
1088+
if agentpool is None:
1089+
raise CLIInternalError("agentpool cannot be None for ManagedSystem mode")
1090+
1091+
# Instead of creating a new instance, modify the existing one
1092+
# Keep name and set mode to ManagedSystem
1093+
agentpool.mode = CONST_NODEPOOL_MODE_MANAGEDSYSTEM
1094+
# Make sure all other attributes are None
1095+
for attr in vars(agentpool):
1096+
if attr != 'name' and attr != 'mode' and not attr.startswith('_'):
1097+
if hasattr(agentpool, attr):
1098+
setattr(agentpool, attr, None)
1099+
1100+
return agentpool
1101+
10731102
def construct_agentpool_profile_preview(self) -> AgentPool:
10741103
"""The overall controller used to construct the preview AgentPool profile.
10751104
@@ -1081,6 +1110,13 @@ def construct_agentpool_profile_preview(self) -> AgentPool:
10811110
# DO NOT MOVE: keep this on top, construct the default AgentPool profile
10821111
agentpool = self.construct_agentpool_profile_default(bypass_restore_defaults=True)
10831112

1113+
# Check if mode is ManagedSystem, if yes, reset all properties
1114+
agentpool = self.set_up_managed_system_mode(agentpool)
1115+
1116+
# If mode is ManagedSystem, skip all other property setups
1117+
if agentpool.mode == CONST_NODEPOOL_MODE_MANAGEDSYSTEM:
1118+
return agentpool
1119+
10841120
# set up preview vm properties
10851121
agentpool = self.set_up_preview_vm_properties(agentpool)
10861122
# set up message of the day
@@ -1318,6 +1354,15 @@ def update_agentpool_profile_preview(self, agentpools: List[AgentPool] = None) -
13181354
# DO NOT MOVE: keep this on top, fetch and update the default AgentPool profile
13191355
agentpool = self.update_agentpool_profile_default(agentpools)
13201356

1357+
# Check if agentpool is in ManagedSystem mode and handle special case
1358+
if agentpool.mode == CONST_NODEPOOL_MODE_MANAGEDSYSTEM:
1359+
# Make sure all other attributes are None
1360+
for attr in vars(agentpool):
1361+
if attr != 'name' and attr != 'mode' and not attr.startswith('_'):
1362+
if hasattr(agentpool, attr):
1363+
setattr(agentpool, attr, None)
1364+
return agentpool
1365+
13211366
# update custom ca trust
13221367
agentpool = self.update_custom_ca_trust(agentpool)
13231368

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,8 @@ def aks_create(
732732
vm_sizes=None,
733733
# IMDS restriction
734734
enable_imds_restriction=False,
735+
# managed system pool
736+
enable_managed_system_pool=False,
735737
):
736738
# DO NOT MOVE: get all the original parameters and save them as a dictionary
737739
raw_parameters = locals()

src/aks-preview/azext_aks_preview/managed_cluster_decorator.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
CONST_NETWORK_PLUGIN_AZURE,
3030
CONST_NETWORK_PLUGIN_MODE_OVERLAY,
3131
CONST_NETWORK_POLICY_CILIUM,
32+
CONST_NODEPOOL_MODE_MANAGEDSYSTEM,
3233
CONST_PRIVATE_DNS_ZONE_NONE,
3334
CONST_PRIVATE_DNS_ZONE_SYSTEM,
3435
CONST_ROTATION_POLL_INTERVAL,
@@ -3972,6 +3973,25 @@ def __init__(
39723973
self.__raw_parameters = raw_parameters
39733974
super().__init__(cmd, client, raw_parameters, resource_type)
39743975

3976+
def update_managed_system_pools(self, mc: ManagedCluster) -> ManagedCluster:
3977+
"""Update ManagedSystem agent pools to only include name, mode, and type fields.
3978+
3979+
:return: the ManagedCluster object
3980+
"""
3981+
self._ensure_mc(mc)
3982+
3983+
if mc.agent_pool_profiles is None:
3984+
return mc
3985+
for agentpool in mc.agent_pool_profiles:
3986+
# Check if agentpool is in ManagedSystem mode and handle special case
3987+
if agentpool.mode == CONST_NODEPOOL_MODE_MANAGEDSYSTEM:
3988+
# Make sure all other attributes are None
3989+
for attr in vars(agentpool):
3990+
if attr != 'name' and attr != 'mode' and not attr.startswith('_'):
3991+
if hasattr(agentpool, attr):
3992+
setattr(agentpool, attr, None)
3993+
return mc
3994+
39753995
def init_models(self) -> None:
39763996
"""Initialize an AKSManagedClusterModels object to store the models.
39773997
@@ -5475,6 +5495,8 @@ def update_mc_profile_preview(self) -> ManagedCluster:
54755495
mc = self.update_vmas_to_vms(mc)
54765496
# update http proxy config
54775497
mc = self.update_http_proxy_enabled(mc)
5498+
# update ManagedSystem pools, must at end
5499+
mc = self.update_managed_system_pools(mc)
54785500

54795501
return mc
54805502

0 commit comments

Comments
 (0)