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][aks-preview] az aks nodepool upgrade: Add new parameter --aks-custom-headers #3658

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Release History
===============

0.5.24
+++++
* * Add "--aks-custom-headers" for "az aks nodepool upgrade"

0.5.23
+++++
* Fix issue that `maintenanceconfiguration add` subcommand cannot work
Expand Down
3 changes: 3 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,9 @@
- name: --max-surge
type: string
short-summary: Extra nodes used to speed upgrade. When specified, it represents the number or percent used, eg. 5 or 33%
- name: --aks-custom-headers
type: string
short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2
"""

helps['aks nodepool update'] = """
Expand Down
1 change: 1 addition & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def load_arguments(self, _):

with self.argument_context('aks nodepool upgrade') as c:
c.argument('max_surge', type=str, validator=validate_max_surge)
c.argument('aks_custom_headers')

with self.argument_context('aks nodepool update') as c:
c.argument('enable_cluster_autoscaler', options_list=["--enable-cluster-autoscaler", "-e"], action='store_true')
Expand Down
7 changes: 5 additions & 2 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3308,7 +3308,8 @@ def aks_agentpool_upgrade(cmd, # pylint: disable=unused-argument
kubernetes_version='',
no_wait=False,
node_image_only=False,
max_surge=None):
max_surge=None,
aks_custom_headers=None):
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.')
Expand All @@ -3329,7 +3330,9 @@ def aks_agentpool_upgrade(cmd, # pylint: disable=unused-argument
if max_surge:
instance.upgrade_settings.max_surge = max_surge

return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name, cluster_name, nodepool_name, instance)
headers = get_aks_custom_headers(aks_custom_headers)

return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name, cluster_name, nodepool_name, instance, headers=headers)


def aks_agentpool_get_upgrade_profile(cmd, # pylint: disable=unused-argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from azure.cli.testsdk import (
ResourceGroupPreparer, RoleBasedServicePrincipalPreparer, ScenarioTest, live_only)
from azure.cli.command_modules.acs._format import version_to_tuple
from azure_devtools.scenario_tests import AllowLargeResponse

from .recording_processors import KeyReplacer
Expand All @@ -26,6 +27,18 @@ def __init__(self, method_name):
method_name, recording_processors=[KeyReplacer()]
)

def _get_versions(self, location):
"""Return the previous and current Kubernetes minor release versions, such as ("1.11.6", "1.12.4")."""
versions = self.cmd(
"az aks get-versions -l westus2 --query 'orchestrators[].orchestratorVersion'").get_output_in_json()
# sort by semantic version, from newest to oldest
versions = sorted(versions, key=version_to_tuple, reverse=True)
upgrade_version = versions[0]
# find the first version that doesn't start with the latest major.minor.
prefix = upgrade_version[:upgrade_version.rfind('.')]
create_version = next(x for x in versions if not x.startswith(prefix))
return create_version, upgrade_version

@live_only() # without live only fails with need az login
@AllowLargeResponse()
def test_get_version(self):
Expand Down Expand Up @@ -896,6 +909,63 @@ def test_aks_upgrade_node_image_only_nodepool(self, resource_group, resource_gro
self.check('provisioningState', 'UpgradingNodeImageVersion')
])


@live_only() #without live only fails with need az login
@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='westus2')
def test_aks_upgrade_nodepool(self, resource_group, resource_group_location):
create_version, upgrade_version = self._get_versions(resource_group_location)
# reset the count so in replay mode the random names will start with 0
self.test_resources_count = 0
# kwargs for string formatting
aks_name = self.create_random_name('cliakstest', 16)
self.kwargs.update({
'resource_group': resource_group,
'name': aks_name,
'dns_name_prefix': self.create_random_name('cliaksdns', 16),
'location': resource_group_location,
'resource_type': 'Microsoft.ContainerService/ManagedClusters',
'windows_admin_username': 'azureuser1',
'windows_admin_password': 'replace-Password1234$',
'nodepool2_name': 'npwin',
'k8s_version': create_version,
'upgrade_k8s_version': upgrade_version,
})

# create AKS cluster
create_cmd = 'aks create --resource-group={resource_group} --name={name} --location={location} ' \
'--dns-name-prefix={dns_name_prefix} --node-count=1 --generate-ssh-keys ' \
'--windows-admin-username={windows_admin_username} --windows-admin-password={windows_admin_password} ' \
'--load-balancer-sku=standard --vm-set-type=virtualmachinescalesets --network-plugin=azure' \
mainred marked this conversation as resolved.
Show resolved Hide resolved
'-kubernetes-version {k8s_version}'
self.cmd(create_cmd, checks=[
self.exists('fqdn'),
self.exists('nodeResourceGroup'),
self.check('provisioningState', 'Succeeded'),
self.check('windowsProfile.adminUsername', 'azureuser1')
])

# add Windows nodepool
self.cmd('aks nodepool add --resource-group={resource_group} --cluster-name={name} --name={nodepool2_name} --os-type Windows --node-count=1', checks=[
self.check('provisioningState', 'Succeeded')
])

# upgrade cluster control plane only
self.cmd('aks upgrade --resource-group={resource_group} --name={name} --kubernetes-version={upgrade_k8s_version}', check=[
self.check('provisioningState', 'Succeeded')
])

# upgrade Windows nodepool
self.cmd('aks nodepool upgrade --resource-group={resource_group} --cluster-name={name} ' \
'--name={nodepool2_name} --kubernetes-version={upgrade_k8s_version} ' \
'--aks-custom-headers WindowsContainerRuntime=containerd', check=[
self.check('provisioningState', 'Succeeded')
])

# delete AKS cluster
self.cmd(
'aks delete -g {resource_group} -n {name} --yes --no-wait', checks=[self.is_empty()])

@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='westus2')
def test_aks_create_with_windows(self, resource_group, resource_group_location):
Expand Down Expand Up @@ -937,7 +1007,7 @@ def test_aks_create_with_windows(self, resource_group, resource_group_location):
self.check('windowsProfile.licenseType', 'Windows_Server')
])

# #nodepool delete
# nodepool delete
self.cmd(
'aks nodepool delete --resource-group={resource_group} --cluster-name={name} --name={nodepool2_name} --no-wait', checks=[self.is_empty()])

Expand Down Expand Up @@ -1021,7 +1091,7 @@ def test_aks_create_with_ahub(self, resource_group, resource_group_location):
self.check('windowsProfile.licenseType', 'None')
])

# #nodepool delete
# nodepool delete
self.cmd(
'aks nodepool delete --resource-group={resource_group} --cluster-name={name} --name={nodepool2_name} --no-wait', checks=[self.is_empty()])

Expand Down Expand Up @@ -1053,7 +1123,7 @@ def test_aks_update_to_msi_cluster(self, resource_group, resource_group_location
self.cmd(
'aks delete -g {resource_group} -n {name} --yes --no-wait', checks=[self.is_empty()])

@live_only() # without live only fails with need az login
@live_only() # without live only fails with need az login
@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='eastus')
def test_aks_create_with_gitops_addon(self, resource_group, resource_group_location):
Expand All @@ -1070,7 +1140,7 @@ def test_aks_create_with_gitops_addon(self, resource_group, resource_group_locat
self.check('addonProfiles.gitops.enabled', True),
])

@live_only() # without live only fails with need az login
@live_only() # without live only fails with need az login
@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='eastus')
def test_aks_enable_addon_with_gitops(self, resource_group, resource_group_location):
Expand All @@ -1093,7 +1163,7 @@ def test_aks_enable_addon_with_gitops(self, resource_group, resource_group_locat
self.check('addonProfiles.gitops.enabled', True),
])

@live_only() # without live only fails with need az login
@live_only() # without live only fails with need az login
@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='eastus')
def test_aks_disable_addon_gitops(self, resource_group, resource_group_location):
Expand Down Expand Up @@ -1819,7 +1889,7 @@ def test_aks_update_with_windows_password(self, resource_group, resource_group_l
self.check('provisioningState', 'Succeeded'),
])

# #nodepool delete
# nodepool delete
self.cmd(
'aks nodepool delete --resource-group={resource_group} --cluster-name={name} --name={nodepool2_name} --no-wait', checks=[self.is_empty()])

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.5.23"
VERSION = "0.5.24"
CLASSIFIERS = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
Expand Down