Skip to content

Restrict VirtualMachines node pool manual profile vm_sizes field to support single sku size #8702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Pending
14.0.0b5
++++++++
* Re-generate the SDK for API version 2025-02-02-preview with @autorest/[email protected] to fix `\#31345 <https://github.com/Azure/azure-cli/issues/31345>`_.
* [BREAKING CHANGE] Change `--vm-sizes` for VirtualMachines manual profile to awalys support single SKU size.

14.0.0b4
++++++++
Expand Down
4 changes: 3 additions & 1 deletion src/aks-preview/azext_aks_preview/agentpool_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,12 +982,14 @@ def set_up_virtual_machines_profile(self, agentpool: AgentPool) -> AgentPool:
return agentpool

sizes = self.context.get_vm_sizes()
if len(sizes) != 1:
raise InvalidArgumentValueError(f"We only accept single sku size for manual profile. {sizes} is invalid.")
count, _, _, _ = self.context.get_node_count_and_enable_cluster_autoscaler_min_max_count()
agentpool.virtual_machines_profile = self.models.VirtualMachinesProfile(
scale=self.models.ScaleProfile(
manual=[
self.models.ManualScaleProfile(
sizes=sizes,
size=sizes[0],
count=count,
)
]
Expand Down
24 changes: 18 additions & 6 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,9 @@ def aks_agentpool_manual_scale_add(cmd,
operation_group="managed_clusters",
)
sizes = [x.strip() for x in vm_sizes.split(",")]
new_manual_scale_profile = ManualScaleProfile(sizes=sizes, count=int(node_count))
if len(sizes) != 1:
raise ClientRequestError("We only accept single sku size for manual profile.")
new_manual_scale_profile = ManualScaleProfile(size=sizes[0], count=int(node_count))
instance.virtual_machines_profile.scale.manual.append(new_manual_scale_profile)

return sdk_no_wait(
Expand Down Expand Up @@ -1710,19 +1712,25 @@ def aks_agentpool_manual_scale_update(cmd, # pylint: disable=unused-argument
raise ClientRequestError("Cannot update manual in a non-virtualmachines node pool.")

_current_vm_sizes = [x.strip() for x in current_vm_sizes.split(",")]
if len(_current_vm_sizes) != 1:
raise InvalidArgumentValueError(
f"We only accept single sku size for manual profile. {current_vm_sizes} is invalid."
)
_vm_sizes = [x.strip() for x in vm_sizes.split(",")] if vm_sizes else []
if len(_vm_sizes) != 1:
raise InvalidArgumentValueError(f"We only accept single sku size for manual profile. {vm_sizes} is invalid.")
manual_exists = False
for m in instance.virtual_machines_profile.scale.manual:
if m.sizes == _current_vm_sizes:
if m.size == _current_vm_sizes[0]:
manual_exists = True
if vm_sizes:
m.sizes = _vm_sizes
m.size = _vm_sizes[0]
if node_count:
m.count = int(node_count)
break
if not manual_exists:
raise InvalidArgumentValueError(
f"Manual with sizes {current_vm_sizes} doesn't exist in node pool {nodepool_name}"
f"Manual with size {current_vm_sizes[0]} doesn't exist in node pool {nodepool_name}"
)

return sdk_no_wait(
Expand All @@ -1746,15 +1754,19 @@ def aks_agentpool_manual_scale_delete(cmd, # pylint: disable=unused-argument
if instance.type_properties_type != CONST_VIRTUAL_MACHINES:
raise CLIError("Cannot delete manual in a non-virtualmachines node pool.")
_current_vm_sizes = [x.strip() for x in current_vm_sizes.split(",")]
if len(_current_vm_sizes) != 1:
raise InvalidArgumentValueError(
f"We only accept single sku size for manual profile. {current_vm_sizes} is invalid."
)
manual_exists = False
for m in instance.virtual_machines_profile.scale.manual:
if m.sizes == _current_vm_sizes:
if m.size == _current_vm_sizes[0]:
manual_exists = True
instance.virtual_machines_profile.scale.manual.remove(m)
break
if not manual_exists:
raise InvalidArgumentValueError(
f"Manual with sizes {current_vm_sizes} doesn't exist in node pool {nodepool_name}"
f"Manual with size {current_vm_sizes[0]} doesn't exist in node pool {nodepool_name}"
)

return sdk_no_wait(
Expand Down
Loading
Loading