Skip to content

Commit

Permalink
AKS support node image upgrade feature (#1750)
Browse files Browse the repository at this point in the history
  • Loading branch information
gtxistxgao authored May 23, 2020
1 parent ddefab4 commit 35f599f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/aks-preview/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = """
Expand Down Expand Up @@ -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'] = """
Expand Down
55 changes: 44 additions & 11 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 "
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/aks-preview/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 35f599f

Please sign in to comment.