diff --git a/src/aks-preview/HISTORY.md b/src/aks-preview/HISTORY.md index f08db4c3087..a83b1f809a5 100644 --- a/src/aks-preview/HISTORY.md +++ b/src/aks-preview/HISTORY.md @@ -2,6 +2,10 @@ Release History =============== +0.4.47 ++++++ +* Add "--node-image-only" for "az aks nodepool upgrade" and "az aks upgrade"". + 0.4.46 +++++ * Fix issues for az aks kollect on private clusters diff --git a/src/aks-preview/azext_aks_preview/_help.py b/src/aks-preview/azext_aks_preview/_help.py index 45075dc7b35..232a6cda3f6 100644 --- a/src/aks-preview/azext_aks_preview/_help.py +++ b/src/aks-preview/azext_aks_preview/_help.py @@ -290,6 +290,9 @@ - name: --control-plane-only type: bool short-summary: Upgrade the cluster control plane only. If not specified, control plane AND all node pools will be upgraded. + - name: --node-image-only + type: bool + short-summary: Only upgrade node image for agent pools. """ helps['aks update'] = """ @@ -535,6 +538,9 @@ - name: --kubernetes-version -k type: string short-summary: Version of Kubernetes to upgrade the node pool to, such as "1.11.12". + - name: --node-image-only + type: bool + short-summary: Only upgrade agent pool's node image. """ helps['aks nodepool update'] = """ diff --git a/src/aks-preview/azext_aks_preview/custom.py b/src/aks-preview/azext_aks_preview/custom.py index df5dbb184d6..60490472c2a 100644 --- a/src/aks-preview/azext_aks_preview/custom.py +++ b/src/aks-preview/azext_aks_preview/custom.py @@ -71,6 +71,7 @@ from ._client_factory import get_resource_by_name from ._client_factory import cf_container_registry_service from ._client_factory import cf_storage +from ._client_factory import cf_agent_pools from ._helpers import (_populate_api_server_access_profile, _set_vm_set_type, @@ -1534,12 +1535,34 @@ def aks_upgrade(cmd, # pylint: disable=unused-argument client, resource_group_name, name, - kubernetes_version, + kubernetes_version='', control_plane_only=False, no_wait=False, + node_image_only=False, **kwargs): # pylint: disable=unused-argument + from knack.prompting import prompt_y_n instance = client.get(resource_group_name, name) + if kubernetes_version != '' and node_image_only: + raise CLIError('Conflicting flags. Upgrading the Kubernetes version will also upgrade node image version. If you only want to upgrade the node version please use the "--node-image-only" option only.') + + vmas_cluster = False + for agent_profile in instance.agent_pool_profiles: + if agent_profile.type.lower() == "availabilityset": + vmas_cluster = True + break + + if node_image_only: + msg = "This node image upgrade operation will run across every node pool in the cluster and might take a while, do you wish to continue?" + if not prompt_y_n(msg, default="n"): + return None + agent_pool_client = cf_agent_pools(cmd.cli_ctx) + for agent_pool_profile in instance.agent_pool_profiles: + if vmas_cluster: + raise CLIError('This cluster is not using VirtualMachineScaleSets. Node image upgrade only operation can only be applied on VirtualMachineScaleSets cluster.') + _upgrade_single_agent_pool_node_image(agent_pool_client, resource_group_name, name, agent_pool_profile, no_wait) + return None + if instance.kubernetes_version == kubernetes_version: if instance.provisioning_state == "Succeeded": logger.warning("The cluster is already on version %s and is not in a failed state. No operations " @@ -1549,17 +1572,9 @@ def aks_upgrade(cmd, # pylint: disable=unused-argument logger.warning("Cluster currently in failed state. Proceeding with upgrade to existing version %s to " "attempt resolution of failed cluster state.", instance.kubernetes_version) - from knack.prompting import prompt_y_n - upgrade_all = False instance.kubernetes_version = kubernetes_version - vmas_cluster = False - for agent_profile in instance.agent_pool_profiles: - if agent_profile.type.lower() == "availabilityset": - vmas_cluster = True - break - # for legacy clusters, we always upgrade node pools with CCP. if instance.max_agent_pools < 8 or vmas_cluster: if control_plane_only: @@ -1592,6 +1607,12 @@ def aks_upgrade(cmd, # pylint: disable=unused-argument return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, name, instance) +def _upgrade_single_agent_pool_node_image(client, resource_group_name, cluster_name, agent_pool_profile, no_wait): + instance = client.get(resource_group_name, cluster_name, agent_pool_profile.name) + instance.node_image_version = 'latest' + return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, cluster_name, agent_pool_profile.name, instance) + + def _handle_addons_args(cmd, addons_str, subscription_id, resource_group_name, addon_profiles=None, workspace_resource_id=None, appgw_name=None, appgw_subnet_prefix=None, appgw_id=None, appgw_subnet_id=None, appgw_shared=False, appgw_watch_namespace=None): if not addon_profiles: @@ -2142,11 +2163,23 @@ def aks_agentpool_upgrade(cmd, # pylint: disable=unused-argument client, resource_group_name, cluster_name, - kubernetes_version, nodepool_name, - no_wait=False): + kubernetes_version='', + no_wait=False, + node_image_only=False): + + from knack.prompting import prompt_y_n instance = client.get(resource_group_name, cluster_name, nodepool_name) + if kubernetes_version != '' and node_image_only: + raise CLIError('Conflicting flags. Upgrading the Kubernetes version will also upgrade node image version. If you only want to upgrade the node version please use the "--node-image-only" option only.') + instance.orchestrator_version = kubernetes_version + if node_image_only: + msg = "This node image upgrade operation will run across every node in this node pool and might take a while, " \ + "do you wish to continue? " + if not prompt_y_n(msg, default="n"): + return None + instance.node_image_version = 'latest' return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, cluster_name, nodepool_name, instance) diff --git a/src/aks-preview/setup.py b/src/aks-preview/setup.py index 7acb3a823c0..e5e69abc8b9 100644 --- a/src/aks-preview/setup.py +++ b/src/aks-preview/setup.py @@ -8,7 +8,7 @@ from codecs import open as open1 from setuptools import setup, find_packages -VERSION = "0.4.45" +VERSION = "0.4.47" CLASSIFIERS = [ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers',