Skip to content

Commit

Permalink
AKS: Add vms agentpool type (#6592)
Browse files Browse the repository at this point in the history
  • Loading branch information
zqingqing1 authored Aug 4, 2023
1 parent 2f17d29 commit 736b699
Show file tree
Hide file tree
Showing 10 changed files with 1,389 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ To release a new version, please select a new version number (usually plus 1 to

Pending
++++++
* Vendor new SDK and bump API version to 2023-06-02-preview.

0.5.150
+++++++
* Vendor new SDK and bump API version to 2023-06-02-preview.
* Add `--network-dataplane` to the `az aks update` command.
* Support "VirtualMachines" agent pool type to `az aks create --vm-set-type` and `az aks nodepool add --vm-set-type`. This is internal use only, not for public preview.

0.5.149
+++++++
Expand Down
1 change: 1 addition & 0 deletions src/aks-preview/azext_aks_preview/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
# vm set type
CONST_VIRTUAL_MACHINE_SCALE_SETS = "VirtualMachineScaleSets"
CONST_AVAILABILITY_SET = "AvailabilitySet"
CONST_VIRTUAL_MACHINES = "VirtualMachines"

# vm size
CONST_DEFAULT_NODE_VM_SIZE = "Standard_DS2_v2"
Expand Down
5 changes: 4 additions & 1 deletion src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
short-summary: Maximum nodes count used for autoscaler, when "--enable-cluster-autoscaler" specified. Please specify the value in the range of [1, 1000].
- name: --vm-set-type
type: string
short-summary: Agent pool vm set type. VirtualMachineScaleSets or AvailabilitySet.
short-summary: Agent pool vm set type. VirtualMachineScaleSets, AvailabilitySet or VirtualMachines(internal use only).
- name: --enable-pod-security-policy
type: bool
short-summary: Enable pod security policy.
Expand Down Expand Up @@ -1566,6 +1566,9 @@
- name: --mode
type: string
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.
- name: --vm-set-type
type: string
short-summary: Agent pool vm set type. VirtualMachineScaleSets, AvailabilitySet or VirtualMachines(internal use only).
- name: --aks-custom-headers
type: string
short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2
Expand Down
1 change: 1 addition & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ def load_arguments(self, _):
c.argument('max_pods', type=int, options_list=['--max-pods', '-m'])
c.argument('zones', zones_type, options_list=['--zones', '-z'], help='Space-separated list of availability zones where agent nodes will be placed.')
c.argument('ppg')
c.argument('vm_set_type', validator=validate_vm_set_type)
c.argument('enable_encryption_at_host', action='store_true')
c.argument('enable_ultra_ssd', action='store_true')
c.argument('enable_fips_image', action='store_true')
Expand Down
3 changes: 2 additions & 1 deletion src/aks-preview/azext_aks_preview/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ def validate_vm_set_type(namespace):
if namespace.vm_set_type == '':
return
if namespace.vm_set_type.lower() != "availabilityset" and \
namespace.vm_set_type.lower() != "virtualmachines" and \
namespace.vm_set_type.lower() != "virtualmachinescalesets":
raise CLIError(
"--vm-set-type can only be VirtualMachineScaleSets or AvailabilitySet")
"--vm-set-type can only be VirtualMachineScaleSets, AvailabilitySet or VirtualMachines(internal use only)")


def validate_load_balancer_sku(namespace):
Expand Down
34 changes: 33 additions & 1 deletion src/aks-preview/azext_aks_preview/agentpool_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Dict, TypeVar, Union, List

from azure.cli.command_modules.acs._consts import AgentPoolDecoratorMode, DecoratorMode

from azure.cli.command_modules.acs.agentpool_decorator import (
AKSAgentPoolAddDecorator,
AKSAgentPoolContext,
Expand All @@ -26,7 +27,12 @@
from knack.log import get_logger

from azext_aks_preview._client_factory import cf_agent_pools
from azext_aks_preview._consts import CONST_WORKLOAD_RUNTIME_OCI_CONTAINER
from azext_aks_preview._consts import (
CONST_WORKLOAD_RUNTIME_OCI_CONTAINER,
CONST_VIRTUAL_MACHINE_SCALE_SETS,
CONST_AVAILABILITY_SET,
CONST_VIRTUAL_MACHINES
)
from azext_aks_preview._helpers import get_nodepool_snapshot_by_snapshot_id

logger = get_logger(__name__)
Expand Down Expand Up @@ -68,6 +74,32 @@ def external_functions(self) -> SimpleNamespace:
self.__external_functions = SimpleNamespace(**external_functions)
return self.__external_functions

def get_vm_set_type(self) -> str:
"""Obtain the value of vm_set_type, default value is CONST_VIRTUAL_MACHINE_SCALE_SETS.
:return: string
"""
# read the original value passed by the command
vm_set_type = self.raw_param.get("vm_set_type", CONST_VIRTUAL_MACHINE_SCALE_SETS)
# try to read the property value corresponding to the parameter from the `agentpool` object
if self.agentpool_decorator_mode == AgentPoolDecoratorMode.MANAGED_CLUSTER:
if self.agentpool and self.agentpool.type is not None:
vm_set_type = self.agentpool.type
else:
if self.agentpool and self.agentpool.type_properties_type is not None:
vm_set_type = self.agentpool.type_properties_type

# normalize
if vm_set_type.lower() == CONST_VIRTUAL_MACHINE_SCALE_SETS.lower():
vm_set_type = CONST_VIRTUAL_MACHINE_SCALE_SETS
elif vm_set_type.lower() == CONST_AVAILABILITY_SET.lower():
vm_set_type = CONST_AVAILABILITY_SET
elif vm_set_type.lower() == CONST_VIRTUAL_MACHINES.lower():
vm_set_type = CONST_VIRTUAL_MACHINES
else:
raise InvalidArgumentValueError("--vm-set-type can only be VirtualMachineScaleSets, AvailabilitySet or VirtualMachines(internal use only)")
# this parameter does not need validation
return vm_set_type

def get_crg_id(self) -> Union[str, None]:
"""Obtain the value of crg_id.
Expand Down
1 change: 1 addition & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,7 @@ def aks_agentpool_add(
max_pods=0,
zones=None,
ppg=None,
vm_set_type=None,
enable_encryption_at_host=False,
enable_ultra_ssd=False,
enable_fips_image=False,
Expand Down
Loading

0 comments on commit 736b699

Please sign in to comment.