From 559bbb6468fb2bcf4d22915a4149e52381c15648 Mon Sep 17 00:00:00 2001 From: Sean Hobbs Date: Thu, 8 Feb 2024 09:47:03 -0800 Subject: [PATCH 1/4] Add az fleet updaterun create --upgrade-type parameter "ControlPlaneOnly" --- src/fleet/HISTORY.rst | 6 +++++- src/fleet/azext_fleet/_help.py | 4 ++-- src/fleet/azext_fleet/_params.py | 2 +- src/fleet/azext_fleet/constants.py | 14 ++++++++++++++ src/fleet/azext_fleet/custom.py | 17 ++++++++++++----- src/fleet/setup.py | 2 +- 6 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 src/fleet/azext_fleet/constants.py diff --git a/src/fleet/HISTORY.rst b/src/fleet/HISTORY.rst index edd685d497a..becbf2337fd 100644 --- a/src/fleet/HISTORY.rst +++ b/src/fleet/HISTORY.rst @@ -72,4 +72,8 @@ Release History 1.0.3 ++++++ -* Added `az fleet reconcile` & `az fleet member reconcile` commands. \ No newline at end of file +* Added `az fleet reconcile` & `az fleet member reconcile` commands. + +1.0.4 +++++++ +* Added new --upgrade-type parameter "ControlPlaneOnly" for command `az fleet updaterun create --upgrade-type`. \ No newline at end of file diff --git a/src/fleet/azext_fleet/_help.py b/src/fleet/azext_fleet/_help.py index 87bf734ea59..8b7d00a00e1 100644 --- a/src/fleet/azext_fleet/_help.py +++ b/src/fleet/azext_fleet/_help.py @@ -181,10 +181,10 @@ parameters: - name: --upgrade-type type: string - short-summary: Specify the upgrade type of members. Acceptable values are 'Full' and 'NodeImageOnly'. + short-summary: Specify the upgrade type of members. Acceptable values are 'Full', 'ControlPlaneOnly', and 'NodeImageOnly'. - name: --kubernetes-version type: string - short-summary: Specify the kubernetes version to upgrade member(s) to, when --upgrade-type is set to 'Full'. Acceptable format is x.x.x (eg. 1.2.3). + short-summary: Specify the kubernetes version to upgrade member(s) to, when --upgrade-type is set to 'Full' or 'ControlPlaneOnly'. Acceptable format is x.x.x (eg. 1.2.3). - name: --stages type: string short-summary: Path to a JSON file that defines stages to upgrade a fleet. See examples for reference. diff --git a/src/fleet/azext_fleet/_params.py b/src/fleet/azext_fleet/_params.py index 23c47ddef16..af8f820b43d 100644 --- a/src/fleet/azext_fleet/_params.py +++ b/src/fleet/azext_fleet/_params.py @@ -59,7 +59,7 @@ def load_arguments(self, _): c.argument('fleet_name', options_list=['--fleet-name', '-f'], help='Specify the fleet name.') with self.argument_context('fleet updaterun create') as c: - c.argument('upgrade_type', arg_type=get_enum_type(['Full', 'NodeImageOnly'])) + c.argument('upgrade_type', arg_type=get_enum_type(['Full', 'NodeImageOnly', 'ControlPlaneOnly'])) c.argument('kubernetes_version', validator=validate_kubernetes_version) c.argument('node_image_selection', arg_type=get_enum_type(['Latest', 'Consistent']), help='Node Image Selection is an option that lets you choose how your clusters\' nodes are upgraded') c.argument('stages', type=file_type, completer=FilesCompleter(), help='Path to a json file that defines stages to upgrade a fleet. See examples for further reference.') diff --git a/src/fleet/azext_fleet/constants.py b/src/fleet/azext_fleet/constants.py new file mode 100644 index 00000000000..9dcdcab2c00 --- /dev/null +++ b/src/fleet/azext_fleet/constants.py @@ -0,0 +1,14 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +UPGRADE_TYPE_CONTROLPLANEONLY = "ControlPlaneOnly" +UPGRADE_TYPE_FULL = "Full" +UPGRADE_TYPE_NODEIMAGEONLY = "NodeImageOnly" + +UPGRADE_TYPE_ERROR_MESSAGES = { + UPGRADE_TYPE_CONTROLPLANEONLY: f"Please set kubernetes version when upgrade type is '{UPGRADE_TYPE_CONTROLPLANEONLY}'.", + UPGRADE_TYPE_FULL: f"Please set kubernetes version when upgrade type is '{UPGRADE_TYPE_FULL}'.", + UPGRADE_TYPE_NODEIMAGEONLY: f"Cannot set kubernetes version when upgrade type is '{UPGRADE_TYPE_NODEIMAGEONLY}'." +} \ No newline at end of file diff --git a/src/fleet/azext_fleet/custom.py b/src/fleet/azext_fleet/custom.py index 166e71b40fc..487d31a72b1 100644 --- a/src/fleet/azext_fleet/custom.py +++ b/src/fleet/azext_fleet/custom.py @@ -14,7 +14,7 @@ from azext_fleet._client_factory import CUSTOM_MGMT_FLEET from azext_fleet._helpers import print_or_merge_credentials - +from azext_fleet.constants import * # pylint: disable=too-many-locals def create_fleet(cmd, @@ -316,10 +316,17 @@ def create_update_run(cmd, stages=None, update_strategy_name=None, no_wait=False): - if upgrade_type == "Full" and kubernetes_version is None: - raise CLIError("Please set kubernetes version when upgrade type is 'Full'.") - if upgrade_type == "NodeImageOnly" and kubernetes_version is not None: - raise CLIError("Cannot set kubernetes version when upgrade type is 'NodeImageOnly'.") + + if upgrade_type in UPGRADE_TYPE_ERROR_MESSAGES: + if ( + ((upgrade_type == "Full" or upgrade_type == "ControlPlaneOnly") and kubernetes_version is None) or + (upgrade_type == "NodeImageOnly" and kubernetes_version is not None) + ): + raise CLIError(UPGRADE_TYPE_ERROR_MESSAGES[upgrade_type]) + else: + raise CLIError((f"The upgrade type parameter '{upgrade_type}' is not valid." + f"Valid options are: '{UPGRADE_TYPE_FULL}', '{UPGRADE_TYPE_CONTROLPLANEONLY}', or '{UPGRADE_TYPE_NODEIMAGEONLY}'")) + if stages is not None and update_strategy_name is not None: raise CLIError("Cannot set stages when update strategy name is set.") diff --git a/src/fleet/setup.py b/src/fleet/setup.py index 98899dca7a7..7c19c452842 100644 --- a/src/fleet/setup.py +++ b/src/fleet/setup.py @@ -16,7 +16,7 @@ # TODO: Confirm this is the right version number you want and it matches your # HISTORY.rst entry. -VERSION = '1.0.3' +VERSION = '1.0.4' # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers From 2eed4526ada124b4ba88b1be38c8e7989770d4d9 Mon Sep 17 00:00:00 2001 From: Sean Hobbs Date: Tue, 13 Feb 2024 13:13:17 -0800 Subject: [PATCH 2/4] style fixes --- src/fleet/azext_fleet/constants.py | 2 +- src/fleet/azext_fleet/custom.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/fleet/azext_fleet/constants.py b/src/fleet/azext_fleet/constants.py index 9dcdcab2c00..b846773d46b 100644 --- a/src/fleet/azext_fleet/constants.py +++ b/src/fleet/azext_fleet/constants.py @@ -11,4 +11,4 @@ UPGRADE_TYPE_CONTROLPLANEONLY: f"Please set kubernetes version when upgrade type is '{UPGRADE_TYPE_CONTROLPLANEONLY}'.", UPGRADE_TYPE_FULL: f"Please set kubernetes version when upgrade type is '{UPGRADE_TYPE_FULL}'.", UPGRADE_TYPE_NODEIMAGEONLY: f"Cannot set kubernetes version when upgrade type is '{UPGRADE_TYPE_NODEIMAGEONLY}'." -} \ No newline at end of file +} diff --git a/src/fleet/azext_fleet/custom.py b/src/fleet/azext_fleet/custom.py index 487d31a72b1..10f34cd75fd 100644 --- a/src/fleet/azext_fleet/custom.py +++ b/src/fleet/azext_fleet/custom.py @@ -14,7 +14,11 @@ from azext_fleet._client_factory import CUSTOM_MGMT_FLEET from azext_fleet._helpers import print_or_merge_credentials -from azext_fleet.constants import * +from azext_fleet.constants import UPGRADE_TYPE_CONTROLPLANEONLY +from azext_fleet.constants import UPGRADE_TYPE_FULL +from azext_fleet.constants import UPGRADE_TYPE_NODEIMAGEONLY +from azext_fleet.constants import UPGRADE_TYPE_ERROR_MESSAGES + # pylint: disable=too-many-locals def create_fleet(cmd, @@ -325,7 +329,7 @@ def create_update_run(cmd, raise CLIError(UPGRADE_TYPE_ERROR_MESSAGES[upgrade_type]) else: raise CLIError((f"The upgrade type parameter '{upgrade_type}' is not valid." - f"Valid options are: '{UPGRADE_TYPE_FULL}', '{UPGRADE_TYPE_CONTROLPLANEONLY}', or '{UPGRADE_TYPE_NODEIMAGEONLY}'")) + f"Valid options are: '{UPGRADE_TYPE_FULL}', '{UPGRADE_TYPE_CONTROLPLANEONLY}', or '{UPGRADE_TYPE_NODEIMAGEONLY}'")) if stages is not None and update_strategy_name is not None: raise CLIError("Cannot set stages when update strategy name is set.") From c7bc0c54954daafd91f4f33c801e94b42a5c7c45 Mon Sep 17 00:00:00 2001 From: Sean Hobbs Date: Tue, 13 Feb 2024 13:19:31 -0800 Subject: [PATCH 3/4] Replaced strings with constants. --- src/fleet/azext_fleet/custom.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fleet/azext_fleet/custom.py b/src/fleet/azext_fleet/custom.py index 10f34cd75fd..73b7dcfed97 100644 --- a/src/fleet/azext_fleet/custom.py +++ b/src/fleet/azext_fleet/custom.py @@ -323,8 +323,8 @@ def create_update_run(cmd, if upgrade_type in UPGRADE_TYPE_ERROR_MESSAGES: if ( - ((upgrade_type == "Full" or upgrade_type == "ControlPlaneOnly") and kubernetes_version is None) or - (upgrade_type == "NodeImageOnly" and kubernetes_version is not None) + ((upgrade_type == UPGRADE_TYPE_FULL or upgrade_type == UPGRADE_TYPE_CONTROLPLANEONLY) and kubernetes_version is None) or + (upgrade_type == UPGRADE_TYPE_NODEIMAGEONLY and kubernetes_version is not None) ): raise CLIError(UPGRADE_TYPE_ERROR_MESSAGES[upgrade_type]) else: From c01b49c73fe4f26f894a51de1adddb914b762f97 Mon Sep 17 00:00:00 2001 From: Sean Hobbs Date: Tue, 13 Feb 2024 14:37:28 -0800 Subject: [PATCH 4/4] style fixes round 2 --- src/fleet/azext_fleet/constants.py | 2 +- src/fleet/azext_fleet/custom.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fleet/azext_fleet/constants.py b/src/fleet/azext_fleet/constants.py index b846773d46b..0c0d3877ea8 100644 --- a/src/fleet/azext_fleet/constants.py +++ b/src/fleet/azext_fleet/constants.py @@ -8,7 +8,7 @@ UPGRADE_TYPE_NODEIMAGEONLY = "NodeImageOnly" UPGRADE_TYPE_ERROR_MESSAGES = { - UPGRADE_TYPE_CONTROLPLANEONLY: f"Please set kubernetes version when upgrade type is '{UPGRADE_TYPE_CONTROLPLANEONLY}'.", + UPGRADE_TYPE_CONTROLPLANEONLY: f"Please set kubernetes version when upgrade type is '{UPGRADE_TYPE_CONTROLPLANEONLY}'.", # pylint: disable=line-too-long UPGRADE_TYPE_FULL: f"Please set kubernetes version when upgrade type is '{UPGRADE_TYPE_FULL}'.", UPGRADE_TYPE_NODEIMAGEONLY: f"Cannot set kubernetes version when upgrade type is '{UPGRADE_TYPE_NODEIMAGEONLY}'." } diff --git a/src/fleet/azext_fleet/custom.py b/src/fleet/azext_fleet/custom.py index 73b7dcfed97..e3e8e0a5cd8 100644 --- a/src/fleet/azext_fleet/custom.py +++ b/src/fleet/azext_fleet/custom.py @@ -323,13 +323,13 @@ def create_update_run(cmd, if upgrade_type in UPGRADE_TYPE_ERROR_MESSAGES: if ( - ((upgrade_type == UPGRADE_TYPE_FULL or upgrade_type == UPGRADE_TYPE_CONTROLPLANEONLY) and kubernetes_version is None) or + ((upgrade_type in (UPGRADE_TYPE_FULL, UPGRADE_TYPE_CONTROLPLANEONLY)) and kubernetes_version is None) or # pylint: disable=line-too-long (upgrade_type == UPGRADE_TYPE_NODEIMAGEONLY and kubernetes_version is not None) ): raise CLIError(UPGRADE_TYPE_ERROR_MESSAGES[upgrade_type]) else: raise CLIError((f"The upgrade type parameter '{upgrade_type}' is not valid." - f"Valid options are: '{UPGRADE_TYPE_FULL}', '{UPGRADE_TYPE_CONTROLPLANEONLY}', or '{UPGRADE_TYPE_NODEIMAGEONLY}'")) + f"Valid options are: '{UPGRADE_TYPE_FULL}', '{UPGRADE_TYPE_CONTROLPLANEONLY}', or '{UPGRADE_TYPE_NODEIMAGEONLY}'")) # pylint: disable=line-too-long if stages is not None and update_strategy_name is not None: raise CLIError("Cannot set stages when update strategy name is set.")