From 06bcae22c029e3abd390a176026b76df933889a0 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Tue, 12 May 2020 14:05:04 +0000 Subject: [PATCH 1/2] feat: add aks-custom-headers for nodepool and update add version change add parameters --- src/aks-preview/HISTORY.md | 4 +++ src/aks-preview/azext_aks_preview/_params.py | 2 ++ src/aks-preview/azext_aks_preview/custom.py | 31 ++++++++++++-------- src/aks-preview/setup.py | 2 +- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/aks-preview/HISTORY.md b/src/aks-preview/HISTORY.md index d4ba6a51c0a..6b5aeb291f7 100644 --- a/src/aks-preview/HISTORY.md +++ b/src/aks-preview/HISTORY.md @@ -2,6 +2,10 @@ Release History =============== +0.4.45 ++++++ +* Add "--aks-custom-headers" for "az aks nodepool add" and "az aks update" + 0.4.43 +++++ * Fix issues with monitoring addon enabling with CLI versions 2.4.0+ diff --git a/src/aks-preview/azext_aks_preview/_params.py b/src/aks-preview/azext_aks_preview/_params.py index badf811cd07..338a44cc4fe 100644 --- a/src/aks-preview/azext_aks_preview/_params.py +++ b/src/aks-preview/azext_aks_preview/_params.py @@ -119,6 +119,7 @@ def load_arguments(self, _): c.argument('disable_pod_security_policy', action='store_true') c.argument('attach_acr', acr_arg_type, validator=validate_acr) c.argument('detach_acr', acr_arg_type, validator=validate_acr) + c.argument('aks_custom_headers') with self.argument_context('aks scale') as c: c.argument('nodepool_name', type=str, @@ -146,6 +147,7 @@ def load_arguments(self, _): c.argument('spot_max_price', type=float, validator=validate_spot_max_price) c.argument('labels', nargs='*', validator=validate_nodepool_labels) c.argument('mode', arg_type=get_enum_type([CONST_NODEPOOL_MODE_SYSTEM, CONST_NODEPOOL_MODE_USER])) + c.argument('aks_custom_headers') for scope in ['aks nodepool show', 'aks nodepool delete', 'aks nodepool scale', 'aks nodepool upgrade', 'aks nodepool update']: with self.argument_context(scope) as c: diff --git a/src/aks-preview/azext_aks_preview/custom.py b/src/aks-preview/azext_aks_preview/custom.py index 229a780afb6..22baac37d91 100644 --- a/src/aks-preview/azext_aks_preview/custom.py +++ b/src/aks-preview/azext_aks_preview/custom.py @@ -1009,15 +1009,7 @@ def aks_create(cmd, # pylint: disable=too-many-locals,too-many-statements,to tier="Paid" ) - headers = {} - if aks_custom_headers is not None: - if aks_custom_headers != "": - for pair in aks_custom_headers.split(','): - parts = pair.split('=') - if len(parts) != 2: - raise CLIError('custom headers format is incorrect') - - headers[parts[0]] = parts[1] + headers = get_aks_custom_headers(aks_custom_headers) # Due to SPN replication latency, we do a few retries here max_retry = 30 @@ -1096,7 +1088,8 @@ def aks_update(cmd, # pylint: disable=too-many-statements,too-many-branches, attach_acr=None, detach_acr=None, aad_tenant_id=None, - aad_admin_group_object_ids=None): + aad_admin_group_object_ids=None, + aks_custom_headers=None): update_autoscaler = enable_cluster_autoscaler or disable_cluster_autoscaler or update_cluster_autoscaler update_acr = attach_acr is not None or detach_acr is not None update_pod_security = enable_pod_security_policy or disable_pod_security_policy @@ -1244,7 +1237,8 @@ def aks_update(cmd, # pylint: disable=too-many-statements,too-many-branches, if aad_admin_group_object_ids is not None: instance.aad_profile.admin_group_object_ids = _parse_comma_separated_list(aad_admin_group_object_ids) - return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, name, instance) + headers = get_aks_custom_headers(aks_custom_headers) + return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, name, instance, custom_headers=headers) def aks_show(cmd, client, resource_group_name, name): # pylint: disable=unused-argument @@ -2071,6 +2065,7 @@ def aks_agentpool_add(cmd, # pylint: disable=unused-argument,too-many-local spot_max_price=float('nan'), labels=None, mode="User", + aks_custom_headers=None, no_wait=False): instances = client.list(resource_group_name, cluster_name) for agentpool_profile in instances: @@ -2124,7 +2119,8 @@ def aks_agentpool_add(cmd, # pylint: disable=unused-argument,too-many-local if node_osdisk_size: agent_pool.os_disk_size_gb = int(node_osdisk_size) - return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, cluster_name, nodepool_name, agent_pool) + headers = get_aks_custom_headers(aks_custom_headers) + return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, cluster_name, nodepool_name, agent_pool, custom_headers=headers) def aks_agentpool_scale(cmd, # pylint: disable=unused-argument @@ -2677,3 +2673,14 @@ def format_bright(msg): def format_hyperlink(the_link): return f'\033[1m{colorama.Style.BRIGHT}{colorama.Fore.BLUE}{the_link}{colorama.Style.RESET_ALL}' + +def get_aks_custom_headers(aks_custom_headers=None): + headers = {} + if aks_custom_headers is not None: + if aks_custom_headers != "": + for pair in aks_custom_headers.split(','): + parts = pair.split('=') + if len(parts) != 2: + raise CLIError('custom headers format is incorrect') + headers[parts[0]] = parts[1] + return headers \ No newline at end of file diff --git a/src/aks-preview/setup.py b/src/aks-preview/setup.py index 3b4bf7610f3..7acb3a823c0 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.44" +VERSION = "0.4.45" CLASSIFIERS = [ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', From 7fa2742b049a624448d0cad123856093d4894940 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Wed, 13 May 2020 06:47:38 +0000 Subject: [PATCH 2/2] fix test failure add help --- src/aks-preview/azext_aks_preview/_help.py | 6 ++++++ src/aks-preview/azext_aks_preview/custom.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/aks-preview/azext_aks_preview/_help.py b/src/aks-preview/azext_aks_preview/_help.py index 7e9a89fda3d..45075dc7b35 100644 --- a/src/aks-preview/azext_aks_preview/_help.py +++ b/src/aks-preview/azext_aks_preview/_help.py @@ -355,6 +355,9 @@ - name: --aad-tenant-id type: string short-summary: The ID of an Azure Active Directory tenant. + - name: --aks-custom-headers + type: string + short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2 examples: - name: Enable cluster-autoscaler within node count range [1,5] text: az aks update --enable-cluster-autoscaler --min-count 1 --max-count 5 -g MyResourceGroup -n MyManagedCluster @@ -511,6 +514,9 @@ - name: --mode type: string short-summary: The mode for a node pool which defines a node pool's primary function. If set as "System", AKS prefers system pods scheduling to node pools with mode `System`. Learn more at https://aka.ms/aks/nodepool/mode. + - name: --aks-custom-headers + type: string + short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2 """ helps['aks nodepool scale'] = """ diff --git a/src/aks-preview/azext_aks_preview/custom.py b/src/aks-preview/azext_aks_preview/custom.py index 22baac37d91..37a673da365 100644 --- a/src/aks-preview/azext_aks_preview/custom.py +++ b/src/aks-preview/azext_aks_preview/custom.py @@ -2674,6 +2674,7 @@ def format_bright(msg): def format_hyperlink(the_link): return f'\033[1m{colorama.Style.BRIGHT}{colorama.Fore.BLUE}{the_link}{colorama.Style.RESET_ALL}' + def get_aks_custom_headers(aks_custom_headers=None): headers = {} if aks_custom_headers is not None: @@ -2683,4 +2684,4 @@ def get_aks_custom_headers(aks_custom_headers=None): if len(parts) != 2: raise CLIError('custom headers format is incorrect') headers[parts[0]] = parts[1] - return headers \ No newline at end of file + return headers