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

Add vpa support #5352

Merged
merged 15 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 12 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
7 changes: 7 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Pending

* Update to use 2022-08-02-preview api version.

+++++++

0.5.101
+++++++

* Add --enable-vpa/--disable-vpa to enable/disable vertical pod autoscaler feature.
huizhifan marked this conversation as resolved.
Show resolved Hide resolved

0.5.100
+++++++

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 @@ -469,6 +469,9 @@
- name: --defender-config
type: string
short-summary: Path to JSON file containing Microsoft Defender profile configurations.
- name: --enable-vpa
type: bool
short-summary: Enable vertical pod autoscaler for cluster.
examples:
- name: Create a Kubernetes cluster with an existing SSH public key.
text: az aks create -g MyResourceGroup -n MyManagedCluster --ssh-key-value /path/to/publickey
Expand Down Expand Up @@ -835,6 +838,12 @@
- name: --private-dns-zone
type: string
short-summary: The private dns zone mode for private cluster.
- name: --enable-vpa
huizhifan marked this conversation as resolved.
Show resolved Hide resolved
type: bool
short-summary: Enable vertical pod autoscaler for cluster.
- name: --disable-vpa
type: bool
short-summary: Disable vertical pod autoscaler for cluster.
examples:
- name: Reconcile the cluster back to its current state.
text: az aks update -g MyResourceGroup -n MyManagedCluster
Expand Down
3 changes: 3 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def load_arguments(self, _):
c.argument('workload_runtime', arg_type=get_enum_type(workload_runtimes), default=CONST_WORKLOAD_RUNTIME_OCI_CONTAINER)
# no validation for aks create because it already only supports Linux.
c.argument('enable_custom_ca_trust', action='store_true')
c.argument('enable_vpa', action='store_true', is_preview=True, help="enable vertical pod autoscaler for cluster")

with self.argument_context('aks update') as c:
# managed cluster paramerters
Expand Down Expand Up @@ -427,6 +428,8 @@ def load_arguments(self, _):
c.argument('enable_private_cluster', action='store_true', is_preview=True, help='enable private cluster for apiserver vnet integration')
c.argument('disable_private_cluster', action='store_true', is_preview=True, help='disable private cluster for apiserver vnet integration')
c.argument('private_dns_zone', is_preview=True)
c.argument('enable_vpa', action='store_true', is_preview=True, help="enable vertical pod autoscaler for cluster")
c.argument('disable_vpa', action='store_true', is_preview=True, help="disable vertical pod autoscaler for cluster")

with self.argument_context('aks upgrade') as c:
c.argument('kubernetes_version', completer=get_k8s_upgrades_completion_list)
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 @@ -670,6 +670,7 @@ def aks_create(
dns_zone_resource_id=None,
enable_keda=False,
enable_node_restriction=False,
enable_vpa=False,
# nodepool
host_group_id=None,
crg_id=None,
Expand Down Expand Up @@ -794,6 +795,8 @@ def aks_update(
enable_private_cluster=False,
disable_private_cluster=False,
private_dns_zone=None,
enable_vpa=False,
disable_vpa=False,
):
# DO NOT MOVE: get all the original parameters and save them as a dictionary
raw_parameters = locals()
Expand Down
106 changes: 106 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 @@ -85,6 +85,7 @@
ManagedClusterIngressProfileWebAppRouting = TypeVar("ManagedClusterIngressProfileWebAppRouting")
ManagedClusterSecurityProfileDefender = TypeVar("ManagedClusterSecurityProfileDefender")
ManagedClusterSecurityProfileNodeRestriction = TypeVar("ManagedClusterSecurityProfileNodeRestriction")
ManagedClusterWorkloadProfileVerticalPodAutoscaler = TypeVar("ManagedClusterWorkloadProfileVerticalPodAutoscaler")


# pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -1904,6 +1905,64 @@ def get_disable_node_restriction(self) -> bool:
"""
return self._get_disable_node_restriction(enable_validation=True)

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

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

return enable_vpa

def get_enable_vpa(self) -> bool:
"""Obtain the value of enable_vpa.

This function will verify the parameter by default. If both enable_vpa and disable_vpa are specified, raise
a MutuallyExclusiveArgumentError.

:return: bool
"""
return self._get_enable_vpa(enable_validation=True)

def _get_disable_vpa(self, enable_validation: bool = False) -> bool:
"""Internal function to obtain the value of disable_vpa.

This function supports the option of enable_vpa. When enabled, if both enable_vpa and disable_vpa are specified,
raise a MutuallyExclusiveArgumentError.

:return: bool
"""
# Read the original value passed by the command.
disable_vpa = self.raw_param.get("disable_vpa")

# 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_vpa and self._get_enable_vpa(enable_validation=False):
raise MutuallyExclusiveArgumentError(
"Cannot specify --enable-vpa and --disable-vpa at the same time."
)

return disable_vpa

def get_disable_vpa(self) -> bool:
"""Obtain the value of disable_vpa.

This function will verify the parameter by default. If both enable_vpa and disable_vpa are specified, raise a MutuallyExclusiveArgumentError.

:return: bool
"""
return self._get_disable_vpa(enable_validation=True)


class AKSPreviewManagedClusterCreateDecorator(AKSManagedClusterCreateDecorator):
def __init__(
Expand Down Expand Up @@ -2253,6 +2312,22 @@ def set_up_node_restriction(self, mc: ManagedCluster) -> ManagedCluster:

return mc

def set_up_vpa(self, mc: ManagedCluster) -> ManagedCluster:
"""Set up workload auto-scaler profile vpa for the ManagedCluster object.

:return: the ManagedCluster object
"""
self._ensure_mc(mc)

if self.context.get_enable_vpa():
if mc.workload_auto_scaler_profile is None:
mc.workload_auto_scaler_profile = self.models.ManagedClusterWorkloadAutoScalerProfile()
if mc.workload_auto_scaler_profile.vertical_pod_autoscaler is None:
mc.workload_auto_scaler_profile.vertical_pod_autoscaler = self.models.ManagedClusterWorkloadAutoScalerProfileVerticalPodAutoscaler(enabled=True)
else:
mc.workload_auto_scaler_profile.vertical_pod_autoscaler.enabled = True
return mc

def construct_mc_profile_preview(self, bypass_restore_defaults: bool = False) -> ManagedCluster:
"""The overall controller used to construct the default ManagedCluster profile.

Expand Down Expand Up @@ -2293,6 +2368,8 @@ def construct_mc_profile_preview(self, bypass_restore_defaults: bool = False) ->
mc = self.set_up_ingress_web_app_routing(mc)
# set up workload auto scaler profile
mc = self.set_up_workload_auto_scaler_profile(mc)
# set up vpa
mc = self.set_up_vpa(mc)

# DO NOT MOVE: keep this at the bottom, restore defaults
mc = self._restore_defaults_in_mc(mc)
Expand Down Expand Up @@ -2689,6 +2766,33 @@ def update_node_restriction(self, mc: ManagedCluster) -> ManagedCluster:

return mc

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

:return: the ManagedCluster object
"""
self._ensure_mc(mc)

if self.context.get_enable_vpa():
if mc.workload_auto_scaler_profile is None:
mc.workload_auto_scaler_profile = self.models.ManagedClusterWorkloadAutoScalerProfile()
if mc.workload_auto_scaler_profile.vertical_pod_autoscaler is None:
mc.workload_auto_scaler_profile.vertical_pod_autoscaler = self.models.ManagedClusterWorkloadAutoScalerProfileVerticalPodAutoscaler()

# set enabled
mc.workload_auto_scaler_profile.vertical_pod_autoscaler.enabled = True

if self.context.get_disable_vpa():
if mc.workload_auto_scaler_profile is None:
mc.workload_auto_scaler_profile = self.models.ManagedClusterWorkloadAutoScalerProfile()
if mc.workload_auto_scaler_profile.vertical_pod_autoscaler is None:
mc.workload_auto_scaler_profile.vertical_pod_autoscaler = self.models.ManagedClusterWorkloadAutoScalerProfileVerticalPodAutoscaler()

# set disabled
mc.workload_auto_scaler_profile.vertical_pod_autoscaler.enabled = False

return mc

def update_mc_profile_preview(self) -> ManagedCluster:
"""The overall controller used to update the preview ManagedCluster profile.

Expand Down Expand Up @@ -2725,5 +2829,7 @@ def update_mc_profile_preview(self) -> ManagedCluster:
mc = self.update_storage_profile(mc)
# update workload auto scaler profile
mc = self.update_workload_auto_scaler_profile(mc)
# update vpa
mc = self.update_vpa(mc)

return mc
Loading