Skip to content
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

{AKS} Add addon autoscaling preview CLI flag #7151

Merged
merged 10 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++

1.0.0b1
+++++++
* Add `--enable-addon-autoscaling` and `--disable-addon-autoscaling` to the `az aks update` command.
* Add `--enable-addon-autoscaling` to the `az aks create` command.

0.5.174
+++++++
* Fix the response format for `az aks mesh get-revisions` and `az aks mesh get-upgrades`.
Expand Down
9 changes: 9 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
- name: --enable-vpa
type: bool
short-summary: Enable vertical pod autoscaler for cluster.
- name: --enable-addon-autoscaling
type: bool
short-summary: Enable addon autoscaling for cluster.
- name: --nodepool-allowed-host-ports
type: string
short-summary: Expose host ports on the node pool. When specified, format should be a comma-separated list of ranges with protocol, eg. 80/TCP,443/TCP,4000-5000/TCP.
Expand Down Expand Up @@ -1079,6 +1082,12 @@
- name: --disable-vpa
type: bool
short-summary: Disable vertical pod autoscaler for cluster.
- name: --enable-addon-autoscaling
type: bool
short-summary: Enable addon autoscaling for cluster.
- name: --disable-addon-autoscaling
type: bool
short-summary: Disable addon autoscaling for cluster.
- name: --cluster-snapshot-id
type: string
short-summary: The source cluster snapshot id is used to update existing cluster.
Expand Down
18 changes: 18 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@ def load_arguments(self, _):
is_preview=True,
help="enable vertical pod autoscaler for cluster",
)
c.argument(
"enable_addon_autoscaling",
action="store_true",
is_preview=True,
help="enable addon autoscaling for cluster",
)
c.argument(
"enable_node_restriction",
action="store_true",
Expand Down Expand Up @@ -1094,6 +1100,18 @@ def load_arguments(self, _):
is_preview=True,
help="disable vertical pod autoscaler for cluster",
)
c.argument(
"enable_addon_autoscaling",
action="store_true",
is_preview=True,
help="enable addon autoscaling for cluster",
)
c.argument(
"disable_addon_autoscaling",
action="store_true",
is_preview=True,
help="disable addon autoscaling for cluster",
)
c.argument(
"cluster_snapshot_id",
validator=validate_cluster_snapshot_id,
Expand Down
3 changes: 3 additions & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ def aks_create(
dns_zone_resource_ids=None,
enable_keda=False,
enable_vpa=False,
enable_addon_autoscaling=False,
enable_node_restriction=False,
enable_cilium_dataplane=False,
custom_ca_trust_certificates=None,
Expand Down Expand Up @@ -775,6 +776,8 @@ def aks_update(
disable_azure_monitor_metrics=False,
enable_vpa=False,
disable_vpa=False,
enable_addon_autoscaling=False,
disable_addon_autoscaling=False,
cluster_snapshot_id=None,
custom_ca_trust_certificates=None,
# guardrails parameters
Expand Down
111 changes: 111 additions & 0 deletions src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,63 @@ def get_disable_vpa(self) -> bool:
"""
return self._get_disable_vpa(enable_validation=True)

def _get_enable_addon_autoscaling(self, enable_validation: bool = False) -> bool:
"""Internal function to obtain the value of enable_addon_autoscaling.
This function supports the option of enable_addon_autoscaling.
When enabled, if both enable_addon_autoscaling and disable_addon_autoscaling are
specified, raise a MutuallyExclusiveArgumentError.
:return: bool
"""
# Read the original value passed by the command.
enable_addon_autoscaling = self.raw_param.get("enable_addon_autoscaling")

# This parameter does not need dynamic completion.
if enable_validation:
if enable_addon_autoscaling and self._get_disable_addon_autoscaling(enable_validation=False):
raise MutuallyExclusiveArgumentError(
"Cannot specify --enable-addon-autoscaling and --disable-addon-autoscaling at the same time."
)

return enable_addon_autoscaling

def get_enable_addon_autoscaling(self) -> bool:
"""Obtain the value of enable_addon_autoscaling.
This function will verify the parameter by default.
If both enable_addon_autoscaling and disable_addon_autoscaling are specified,
raise a MutuallyExclusiveArgumentError.
:return: bool
"""
return self._get_enable_addon_autoscaling(enable_validation=True)

def _get_disable_addon_autoscaling(self, enable_validation: bool = False) -> bool:
"""Internal function to obtain the value of disable_addon_autoscaling.
This function supports the option of enable_addon_autoscaling.
When enabled, if both enable_addon_autoscaling and disable_addon_autoscaling are specified,
raise a MutuallyExclusiveArgumentError.
:return: bool
"""
# Read the original value passed by the command.
disable_addon_autoscaling = self.raw_param.get("disable_addon_autoscaling")

# This option is not supported in create mode, hence we do not read the property value from the `mc` object.
# This parameter does not need dynamic completion.
if enable_validation:
if disable_addon_autoscaling and self._get_enable_addon_autoscaling(enable_validation=False):
raise MutuallyExclusiveArgumentError(
"Cannot specify --enable-addon-autoscaling and --disable-addon-autoscaling at the same time."
)

return disable_addon_autoscaling

def get_disable_addon_autoscaling(self) -> bool:
"""Obtain the value of disable_addon_autoscaling.
This function will verify the parameter by default.
If both enable_addon_autoscaling and disable_addon_autoscaling are specified,
raise a MutuallyExclusiveArgumentError.
:return: bool
"""
return self._get_disable_addon_autoscaling(enable_validation=True)

def get_ssh_key_value_for_update(self) -> Tuple[str, bool]:
"""Obtain the value of ssh_key_value for "az aks update".

Expand Down Expand Up @@ -2829,6 +2886,26 @@ def set_up_vpa(self, mc: ManagedCluster) -> ManagedCluster:
mc.workload_auto_scaler_profile.vertical_pod_autoscaler.enabled = True
return mc

def set_up_addon_autoscaling(self, mc: ManagedCluster) -> ManagedCluster:
"""Set up workload auto-scaler vertical pod autsocaler profile
for the ManagedCluster object.
:return: the ManagedCluster object
"""
self._ensure_mc(mc)

if self.context.get_enable_addon_autoscaling():
if mc.workload_auto_scaler_profile is None:
mc.workload_auto_scaler_profile = self.models.ManagedClusterWorkloadAutoScalerProfile() # pylint: disable=no-member
if mc.workload_auto_scaler_profile.vertical_pod_autoscaler is None:
mc.workload_auto_scaler_profile.vertical_pod_autoscaler = (
self.models.ManagedClusterWorkloadAutoScalerProfileVerticalPodAutoscaler() # pylint: disable=no-member
)
# set enabled
mc.workload_auto_scaler_profile.vertical_pod_autoscaler.enabled = True
mc.workload_auto_scaler_profile.vertical_pod_autoscaler.addon_autoscaling = "Enabled"

return mc

def set_up_kube_proxy_config(self, mc: ManagedCluster) -> ManagedCluster:
"""Set up kube-proxy config for the ManagedCluster object.

Expand Down Expand Up @@ -3092,6 +3169,8 @@ def construct_mc_profile_preview(self, bypass_restore_defaults: bool = False) ->
mc = self.set_up_workload_auto_scaler_profile(mc)
# set up vpa
mc = self.set_up_vpa(mc)
# set up addon autoscaling
mc = self.set_up_addon_autoscaling(mc)
# set up kube-proxy config
mc = self.set_up_kube_proxy_config(mc)
# set up custom ca trust certificates
Expand Down Expand Up @@ -3951,6 +4030,36 @@ def update_vpa(self, mc: ManagedCluster) -> ManagedCluster:

return mc

def update_addon_autoscaling(self, mc: ManagedCluster) -> ManagedCluster:
"""Update workload auto-scaler vertical pod auto-scaler profile
for the ManagedCluster object.
:return: the ManagedCluster object
"""
self._ensure_mc(mc)

if self.context.get_enable_addon_autoscaling():
if mc.workload_auto_scaler_profile is None:
mc.workload_auto_scaler_profile = self.models.ManagedClusterWorkloadAutoScalerProfile() # pylint: disable=no-member
if mc.workload_auto_scaler_profile.vertical_pod_autoscaler is None:
mc.workload_auto_scaler_profile.vertical_pod_autoscaler = (
self.models.ManagedClusterWorkloadAutoScalerProfileVerticalPodAutoscaler() # pylint: disable=no-member
)
# set enabled
mc.workload_auto_scaler_profile.vertical_pod_autoscaler.enabled = True
mc.workload_auto_scaler_profile.vertical_pod_autoscaler.addon_autoscaling = "Enabled"

if self.context.get_disable_addon_autoscaling():
if mc.workload_auto_scaler_profile is None:
mc.workload_auto_scaler_profile = self.models.ManagedClusterWorkloadAutoScalerProfile() # pylint: disable=no-member
if mc.workload_auto_scaler_profile.vertical_pod_autoscaler is None:
mc.workload_auto_scaler_profile.vertical_pod_autoscaler = (
self.models.ManagedClusterWorkloadAutoScalerProfileVerticalPodAutoscaler() # pylint: disable=no-member
)
# set disabled
mc.workload_auto_scaler_profile.vertical_pod_autoscaler.addon_autoscaling = "Disabled"

return mc

def update_creation_data(self, mc: ManagedCluster) -> ManagedCluster:
self._ensure_mc(mc)
snapshot_id = self.context.get_cluster_snapshot_id()
Expand Down Expand Up @@ -4339,6 +4448,8 @@ def update_mc_profile_preview(self) -> ManagedCluster:
mc = self.update_azure_monitor_profile(mc)
# update vpa
mc = self.update_vpa(mc)
# update addon autoscaling
mc = self.update_addon_autoscaling(mc)
# update creation data
mc = self.update_creation_data(mc)
# update linux profile
Expand Down
Loading