Skip to content

Commit e73e303

Browse files
authored
[AKS] az command aks: Add KataVmIsolation option for --workload-runtime parameter (#32020)
1 parent e831f2d commit e73e303

File tree

9 files changed

+2892
-1
lines changed

9 files changed

+2892
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@
261261
CONST_NODE_PROVISIONING_DEFAULT_POOLS_NONE = "None"
262262
CONST_NODE_PROVISIONING_DEFAULT_POOLS_AUTO = "Auto"
263263

264+
# consts for workloadruntime
265+
CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION = "KataVmIsolation"
266+
264267

265268
# consts for decorator pattern
266269
class DecoratorMode(Enum):

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,13 @@
623623
Auto: A standard set of Karpenter NodePools are provisioned.
624624
None: No Karpenter NodePools are provisioned.
625625
WARNING: Changing this from Auto to None on an existing cluster will cause the default Karpenter NodePools to be deleted, which will in turn drain and delete the nodes associated with those pools. It is strongly recommended to not do this unless there are idle nodes ready to take the pods evicted by that action.
626+
- name: --workload-runtime
627+
type: string
628+
short-summary: Set the workload runtime.
629+
long-summary: |
630+
Azure provides a different workload-runtime to enable Kata supported workloads in your nodepools. The following values can be specified:
631+
- "KataVmIsolation" for Kata.
632+
626633
examples:
627634
- name: Create a Kubernetes cluster with an existing SSH public key.
628635
text: az aks create -g MyResourceGroup -n MyManagedCluster --ssh-key-value /path/to/publickey
@@ -706,6 +713,8 @@
706713
text: az aks create -g MyResourceGroup -n MyManagedCluster --node-provisioning-mode Auto
707714
- name: Create a kubernetes cluster with auto node provisioning and no default pools.
708715
text: az aks create -g MyResourceGroup -n MyManagedCluster --node-provisioning-mode Auto --node-provisioning-default-pools None
716+
- name: Create a Kubernetes cluster with KataVmIsolation enabled.
717+
text: az aks create -g MyResourceGroup -n MyManagedCluster --os-sku AzureLinux --vm-size Standard_D4s_v3 --workload-runtime KataVmIsolation --node-count 1
709718
"""
710719

711720
helps["aks update"] = """
@@ -1953,6 +1962,13 @@
19531962
- name: --gateway-prefix-size
19541963
type: int
19551964
short-summary: The size of Public IPPrefix attached to the Gateway-mode node pool. The node pool must be in Gateway mode.
1965+
- name: --workload-runtime
1966+
type: string
1967+
short-summary: Set the workload runtime.
1968+
long-summary: |
1969+
Azure provides a different workload-runtime to enable Kata supported workloads in your nodepools. The following values can be specified:
1970+
- "KataVmIsolation" for Kata.
1971+
19561972
examples:
19571973
- name: Create a nodepool in an existing AKS cluster with ephemeral os enabled.
19581974
text: az aks nodepool add -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster --node-osdisk-type Ephemeral --node-osdisk-size 48
@@ -1974,6 +1990,8 @@
19741990
text: az aks nodepool add -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster --os-sku Ubuntu --pod-subnet-id /subscriptions/SubID/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/MySubnet --pod-ip-allocation-mode StaticBlock
19751991
- name: create a nodepool of type VirtualMachines
19761992
text: az aks nodepool add -g MyResourceGroup -n MyNodePool --cluster-name MyMC --vm-set-type VirtualMachines --vm-sizes "VMSize1,VMSize2" --node-count 3
1993+
- name: Create a nodepool with KataVmIsolation enabled.
1994+
text: az aks nodepool add -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster --os-sku AzureLinux --vm-size Standard_D4s_v3 --workload-runtime KataVmIsolation --node-count 1
19771995
"""
19781996

19791997
helps["aks nodepool delete"] = """

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
CONST_NODE_PROVISIONING_MODE_MANUAL,
7474
CONST_NODE_PROVISIONING_MODE_AUTO,
7575
CONST_NODE_PROVISIONING_DEFAULT_POOLS_NONE,
76-
CONST_NODE_PROVISIONING_DEFAULT_POOLS_AUTO)
76+
CONST_NODE_PROVISIONING_DEFAULT_POOLS_AUTO,
77+
CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION)
7778
from azure.cli.command_modules.acs.azurecontainerstorage._consts import (
7879
CONST_ACSTOR_ALL,
7980
CONST_DISK_TYPE_EPHEMERAL_VOLUME_ONLY,
@@ -356,6 +357,10 @@
356357
CONST_APP_ROUTING_NONE_NGINX
357358
]
358359

360+
workload_runtime_types = [
361+
CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION,
362+
]
363+
359364

360365
def load_arguments(self, _):
361366
acr_arg_type = CLIArgumentType(metavar='ACR_NAME_OR_RESOURCE_ID')
@@ -536,6 +541,7 @@ def load_arguments(self, _):
536541
c.argument('gpu_instance_profile', arg_type=get_enum_type(gpu_instance_profiles))
537542
c.argument('nodepool_allowed_host_ports', nargs='+', validator=validate_allowed_host_ports, help="allowed host ports for agentpool")
538543
c.argument('nodepool_asg_ids', nargs='+', validator=validate_application_security_groups, help="application security groups for agentpool")
544+
c.argument('workload_runtime', arg_type=get_enum_type(workload_runtime_types), help="The workload runtime to use on the node pool.")
539545
c.argument("message_of_the_day")
540546

541547
# azure monitor profile
@@ -1046,6 +1052,7 @@ def load_arguments(self, _):
10461052
c.argument("if_none_match")
10471053
c.argument('gpu_driver', arg_type=get_enum_type(gpu_driver_install_modes))
10481054
c.argument("gateway_prefix_size", type=int, validator=validate_gateway_prefix_size)
1055+
c.argument('workload_runtime', arg_type=get_enum_type(workload_runtime_types), help="The workload runtime to use on the nodepool.")
10491056

10501057
with self.argument_context('aks nodepool update', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='agent_pools') as c:
10511058
c.argument('enable_cluster_autoscaler', options_list=[

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,21 @@ def get_gateway_prefix_size(self) -> Union[int, None]:
16851685
"""
16861686
return self.raw_param.get('gateway_prefix_size')
16871687

1688+
def get_workload_runtime(self) -> Union[str, None]:
1689+
"""Obtain the value of workload_runtime, default value is None.
1690+
1691+
:return: string or None
1692+
"""
1693+
# read the original value passed by the command
1694+
workload_runtime = self.raw_param.get("workload_runtime", None)
1695+
# try to read the property value corresponding to the parameter from the `mc` object
1696+
if self.agentpool and self.agentpool.workload_runtime is not None:
1697+
workload_runtime = self.agentpool.workload_runtime
1698+
1699+
# this parameter does not need dynamic completion
1700+
# this parameter does not need validation
1701+
return workload_runtime
1702+
16881703

16891704
class AKSAgentPoolAddDecorator:
16901705
def __init__(
@@ -2134,6 +2149,19 @@ def set_up_virtual_machines_profile(self, agentpool: AgentPool) -> AgentPool:
21342149

21352150
return agentpool
21362151

2152+
def set_up_workload_runtime(self, agentpool: AgentPool) -> AgentPool:
2153+
"""Set up workload runtime for the AgentPool object.
2154+
2155+
:return: the AgentPool object
2156+
"""
2157+
self._ensure_agentpool(agentpool)
2158+
2159+
workload_runtime = self.context.get_workload_runtime()
2160+
if workload_runtime is not None:
2161+
agentpool.workload_runtime = workload_runtime
2162+
2163+
return agentpool
2164+
21372165
def construct_agentpool_profile_default(self, bypass_restore_defaults: bool = False) -> AgentPool:
21382166
"""The overall controller used to construct the AgentPool profile by default.
21392167
@@ -2186,6 +2214,8 @@ def construct_agentpool_profile_default(self, bypass_restore_defaults: bool = Fa
21862214
agentpool = self.set_up_agentpool_gateway_profile(agentpool)
21872215
# set up virtual machines profile
21882216
agentpool = self.set_up_virtual_machines_profile(agentpool)
2217+
# set up workload_runtime
2218+
agentpool = self.set_up_workload_runtime(agentpool)
21892219
# restore defaults
21902220
if not bypass_restore_defaults:
21912221
agentpool = self._restore_defaults_in_agentpool(agentpool)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,7 @@ def aks_create(
945945
crg_id=None,
946946
gpu_instance_profile=None,
947947
message_of_the_day=None,
948+
workload_runtime=None,
948949
# azure service mesh
949950
enable_azure_service_mesh=None,
950951
revision=None,
@@ -2855,6 +2856,7 @@ def aks_agentpool_add(
28552856
asg_ids=None,
28562857
node_public_ip_tags=None,
28572858
disable_windows_outbound_nat=False,
2859+
workload_runtime=None,
28582860
# trusted launch
28592861
enable_vtpm=False,
28602862
enable_secure_boot=False,

0 commit comments

Comments
 (0)