From 1c35ced92eb9bd0c8601cc40748f179b23ce2ffc Mon Sep 17 00:00:00 2001 From: Jonathan Innis Date: Tue, 31 Aug 2021 23:10:41 -0700 Subject: [PATCH] [k8s-extension] Release v0.7.0 (#3838) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create pull.yml * Update pull.yml * Update azure-pipelines.yml * Initial commit of k8s-extension * Update pipelines file * Update CODEOWNERS * Update private preview pipelines * Remove open service mesh from public release * Update pipeline files * Update public extension pipeline * Change condition variable * Add version to public preview/private preview * Update pipelines * Add different testing based on private branch * Add annotations to extension model * Update k8s-custom-pipelines.yml * Update SDKs with Updated Swagger Spec for 2020-07-01-preview (#13) * Update sdks with updated swagger spec * Update version and history rst * Reorder release history timeline * Fix ExtensionInstanceForCreate for import * remove py2 bdist support * Add custom table formatting * Remove unnecessary files * Fix style issues * Fix branch based on comments * Update identity piece manually * Don't handle defaults at the CLI level * Remove defaults from CLI client * Check null target namespace with namespace scope * Update style * Add cassandra operator and location to model * Stage Public Version of k8s-extension 0.2.0 for official release (#15) * Create pull.yml * Update pull.yml * Update azure-pipelines.yml * Initial commit of k8s-extension * Update pipelines file * Update CODEOWNERS * Update private preview pipelines * Remove open service mesh from public release * Update pipeline files * Update public extension pipeline * Change condition variable * Add version to public preview/private preview * Update pipelines * Add different testing based on private branch * Add annotations to extension model * Update k8s-custom-pipelines.yml * Update SDKs with Updated Swagger Spec for 2020-07-01-preview (#13) * Update sdks with updated swagger spec * Update version and history rst * Reorder release history timeline * Fix ExtensionInstanceForCreate for import * remove py2 bdist support * Add custom table formatting * Remove unnecessary files * Fix style issues * Fix branch based on comments * Update identity piece manually * Don't handle defaults at the CLI level * Remove defaults from CLI client * Check null target namespace with namespace scope * Update style * Add cassandra operator and location to model Co-authored-by: action@github.com * Remove custom pipelines file * Update extension description, remove private const * Update pipeline file * Disable refs docs * Update to include better create warning logs and remove update context (#20) * Update to include better create warning logs and remove update context * Remove help text for update * Fix spelling error * Update message * Fix k8s-extension conflict with private version * Fix style errors * Fix filename * add customization for microsoft.azureml.kubernetes (#23) * add customization for microsoft.azureml.kubernetes * Update release history Co-authored-by: Yue Yu Co-authored-by: jonathan-innis * Add E2E Testing from Separate branch into internal code (#26) * Add internal e2e testing * Change to testing folder * Inference CLI validation for Scoring FE (#24) * cli validation starter * added the call to the fe validation function * nodeport validation not required * test fix Co-authored-by: Jonathan Innis * legal warning added (#27) * Remove deprecated method logger.warn * Update k8s-custom-pipelines.yml for Azure Pipelines * Update k8s-custom-pipelines.yml for Azure Pipelines * Add Azure Defender to E2E testing (#28) * Add azure defender testing to e2e * Remove the debug flag * Add configuration testing * Fix pipeline failures * Make test script more intuitive * Remove parameter from testing * Fix wrong location for k8s config whl * Fix pip upgrade issue * Fix pip install upgrade issue * Fix pip install issue * delete resurce in testcase (#29) Co-authored-by: Yue Yu Co-authored-by: Jonathan Innis * Check Provider is Registered with Subscription Before Making Requests (#18) * Add check for KubernetesConfiguration * Disable pylint and rename * Update provider registration link * Update version * Remove extra blank line * Fix bug in import * only validate scoring fe when inference is enabled (#31) * only validate scoring fe when inference is enabled * Fix versioning Co-authored-by: Yue Yu Co-authored-by: jonathan-innis * Provider registration case insensitive * do not validate against scoring fe if inference is not enabled. (#33) * do not validate against scoring fe if inference is not enabled. * add inference enabled scenario * refine * increase sleeping time * fix Co-authored-by: Yue Yu Co-authored-by: Jonathan Innis * Add OSM as Public Preview Extension (#34) * Add OSM as public preview extension * Add osm testing * Add release train to tests * Fix failing osm test * Upgrade pip in integration testing * Remove ununsed import * Fix release train check in update * Parallelize E2E Testing (#36) * Add OSM as public preview extension * Add osm testing * Update test logic to parallelize * Fix test success checking * Parallelize extension testing * Better error checking logic * Fix azureml deletion * Fix private build (#40) * change amlk8s to amlarc (#42) Co-authored-by: Yue Yu * Servicebus client model changes (#44) * Servicebus client model changes * Fix testing script * Update history file and pipeline * Update min cli core version for track 2 updates * Read SSL cert and key from files (#38) * first sketch of the change fixes removed extra blank lines changes regarding param renaming added ssl tests added more detail to the unit test additional import moved pem files out of public folder fixed import chenged import changed import unit tests fix unit test fix fixed unit tests fixed unit test unit test fix changes int test cert and key * test protected config * fix test typo * temporary changes reverted * fixing tests * fixed file paths * removed accidentally added file * changes according to review comments * more changes according to review comments * changes according to review comments Co-authored-by: Jonathan Innis * Upgrade release version * Liakaz/inference read ssl from file (#47) * first sketch of the change fixes removed extra blank lines changes regarding param renaming added ssl tests added more detail to the unit test additional import moved pem files out of public folder fixed import chenged import changed import unit tests fix unit test fix fixed unit tests fixed unit test unit test fix changes int test cert and key * test protected config * fix test typo * temporary changes reverted * fixing tests * fixed file paths * removed accidentally added file * changes according to review comments * more changes according to review comments * changes according to review comments * fixed decode error * renamed the experimental param Co-authored-by: Jonathan Innis * Fix style issues (#51) * Fixed scoring fe related extension param names (#49) * fixed scoring fe related extension params * bug fix and style fixes * variable rename * fixed the error type * set cluster to prod by default * Add distro validation for osm-arc (#50) * Add distro validation for osm-arc * fixed indentation * Fix linting * Resolve comments * Add unit test * fix lint Co-authored-by: Jonathan Innis * Add distro validation for osm-arc (#50) * Add distro validation for osm-arc * fixed indentation * Fix linting * Resolve comments * Add unit test * fix lint Co-authored-by: Jonathan Innis * Add distro validation for osm-arc (#53) removed release-train logic * Add Custom Delete Logic for Partners (#54) * Add custom delete logic * Fix failing unit tests * Add warning message when deleting amlarc extension (#55) * add warning message * fix indentation * Update release version * Remove Pyhelm from OSM customization (#58) * Fix OSM pyhelm bug * Debug bootstrap error * Update release message * Remove pyhelm dependency * Update tests to only check extensionconfig creation (#61) * Update tests to only check extensionconfig creation * Single set of CRUD for AzureML * Debug logs for connectedk8s * Increase open service mesh version number * Update k8s-extension Models to Track2 (#64) * Update k8s-extension models to track2 * Add debug for failed cleanup * Increase version number * Exit 0 on failed cleanup * Fix identity in wrong place in model (#66) * Readd osm-arc distro validation (#62) * Add distro validation for osm-arc removed release-train logic * Readd osm_arc distro validation * Fix style * Rm space * Edit test * Fixed tests and error logic * Remove dependency * Add delete method Co-authored-by: Jonathan Innis * Don't Send Identity Headers If In DF (#67) * Don't send identity for clusters in dogfood * Add location to model for identity * Add identity validation to testing * Use default extension with identity instead of Cassandra specific (#69) * Remove the identity check for now * Add -t for clusterType parameter (#71) * Adding a flag for AKS to AMLARC migration and set up corresponding FE… (#65) * Adding a flag for AKS to AMLARC migration and set up corresponding FE helm values * Remove one extra line * Adding Scoring FE IS_AKS_MIGRATION check logic for helm values Co-authored-by: Harry Yang Co-authored-by: Jonathan Innis * remove version requirement and auto upgrade minor version check (#72) * Custom User Confirmation for Partners (#70) * Custom user confirmation * Check for disable confirm prompty for confirmation * Add yes to delete command * Code cleanup and style fixes (#73) * Enabled identity by default (#74) * Increase version * Remove testing files Co-authored-by: action@github.com Co-authored-by: yuyue9284 <15863499+yuyue9284@users.noreply.github.com> Co-authored-by: Yue Yu Co-authored-by: Lia Kazakova <58274127+liakaz@users.noreply.github.com> Co-authored-by: Niranjan Shankar Co-authored-by: jingyizhu99 <83610845+jingyizhu99@users.noreply.github.com> Co-authored-by: Harry Yang Co-authored-by: Harry Yang Co-authored-by: Thomas Stringer --- src/k8s-extension/HISTORY.rst | 8 +++ .../azext_k8s_extension/__init__.py | 4 +- .../azext_k8s_extension/_help.py | 40 ++++++++++--- .../azext_k8s_extension/_params.py | 6 ++ .../azext_k8s_extension/action.py | 12 ++-- .../azext_k8s_extension/commands.py | 2 +- .../azext_k8s_extension/custom.py | 34 +++++------ .../partner_extensions/AzureDefender.py | 19 +----- .../partner_extensions/AzureMLKubernetes.py | 25 ++++---- .../partner_extensions/Cassandra.py | 60 ------------------- .../partner_extensions/ContainerInsights.py | 19 +----- .../partner_extensions/DefaultExtension.py | 14 ++++- .../partner_extensions/OpenServiceMesh.py | 22 ++----- .../PartnerExtensionModel.py | 2 +- src/k8s-extension/setup.py | 2 +- 15 files changed, 104 insertions(+), 165 deletions(-) delete mode 100644 src/k8s-extension/azext_k8s_extension/partner_extensions/Cassandra.py diff --git a/src/k8s-extension/HISTORY.rst b/src/k8s-extension/HISTORY.rst index 295bb0e4136..4e56486b0fb 100644 --- a/src/k8s-extension/HISTORY.rst +++ b/src/k8s-extension/HISTORY.rst @@ -3,6 +3,14 @@ Release History =============== +0.7.0 +++++++++++++++++++ +* Enable identity by default for extensions +* Use custom delete confirmation for partners +* microsoft.azureml.kubernetes: Adding a flag for AKS to AMLARC migration and set up corresponding FE helm values +* microsoft.openservicemesh: Remove version requirement and auto upgrade minor version check +* Adds -t as alternative to --cluster-type + 0.6.1 ++++++++++++++++++ * Remove sending identity for clusters in Dogfood diff --git a/src/k8s-extension/azext_k8s_extension/__init__.py b/src/k8s-extension/azext_k8s_extension/__init__.py index 2da15ca787d..983be708cb6 100644 --- a/src/k8s-extension/azext_k8s_extension/__init__.py +++ b/src/k8s-extension/azext_k8s_extension/__init__.py @@ -17,8 +17,8 @@ def __init__(self, cli_ctx=None): k8s_extension_custom = CliCommandType( operations_tmpl=consts.EXTENSION_PACKAGE_NAME + '.custom#{}', client_factory=cf_k8s_extension) - super(K8sExtensionCommandsLoader, self).__init__(cli_ctx=cli_ctx, - custom_command_type=k8s_extension_custom) + super().__init__(cli_ctx=cli_ctx, + custom_command_type=k8s_extension_custom) def load_command_table(self, args): from .commands import load_command_table diff --git a/src/k8s-extension/azext_k8s_extension/_help.py b/src/k8s-extension/azext_k8s_extension/_help.py index 862bf4572ac..23601420648 100644 --- a/src/k8s-extension/azext_k8s_extension/_help.py +++ b/src/k8s-extension/azext_k8s_extension/_help.py @@ -10,25 +10,47 @@ helps[f'{consts.EXTENSION_NAME}'] = """ type: group - short-summary: Commands to manage K8s-extensions. + short-summary: Commands to manage Kubernetes Extensions. """ -helps[f'{consts.EXTENSION_NAME} create'] = """ +helps[f'{consts.EXTENSION_NAME} create'] = f""" type: command - short-summary: Create a K8s-extension. + short-summary: Create a Kubernetes Extension. + examples: + - name: Create a Kubernetes Extension + text: |- + az {consts.EXTENSION_NAME} create --resource-group my-resource-group \\ + --cluster-name mycluster --cluster-type connectedClusters \\ + --name myextension --extension-type microsoft.openservicemesh \\ + --scope cluster --release-train stable """ -helps[f'{consts.EXTENSION_NAME} list'] = """ +helps[f'{consts.EXTENSION_NAME} list'] = f""" type: command - short-summary: List K8s-extensions. + short-summary: List Kubernetes Extensions. + examples: + - name: List all Kubernetes Extensions on a cluster + text: |- + az {consts.EXTENSION_NAME} list --resource-group my-resource-group \\ + --cluster-name mycluster --cluster-type connectedClusters """ -helps[f'{consts.EXTENSION_NAME} delete'] = """ +helps[f'{consts.EXTENSION_NAME} delete'] = f""" type: command - short-summary: Delete a K8s-extension. + short-summary: Delete a Kubernetes Extension. + examples: + - name: Delete an existing Kubernetes Extension + text: |- + az {consts.EXTENSION_NAME} delete --resource-group my-resource-group \\ + --cluster-name mycluster --cluster-type connectedClusters --name myextension """ -helps[f'{consts.EXTENSION_NAME} show'] = """ +helps[f'{consts.EXTENSION_NAME} show'] = f""" type: command - short-summary: Show details of a K8s-extension. + short-summary: Show a Kubernetes Extension. + examples: + - name: Show details of a Kubernetes Extension + text: |- + az {consts.EXTENSION_NAME} show --resource-group my-resource-group \\ + --cluster-name mycluster --cluster-type connectedClusters --name myextension """ diff --git a/src/k8s-extension/azext_k8s_extension/_params.py b/src/k8s-extension/azext_k8s_extension/_params.py index 52b680a69f7..58b252e7a16 100644 --- a/src/k8s-extension/azext_k8s_extension/_params.py +++ b/src/k8s-extension/azext_k8s_extension/_params.py @@ -32,6 +32,7 @@ def load_arguments(self, _): help='Name of the Kubernetes cluster') c.argument('cluster_type', arg_type=get_enum_type(['connectedClusters', 'managedClusters', 'appliances']), + options_list=['--cluster-type', '-t'], help='Specify Arc clusters or AKS managed clusters or Arc appliances.') c.argument('scope', arg_type=get_enum_type(['cluster', 'namespace']), @@ -73,3 +74,8 @@ def load_arguments(self, _): c.argument('target_namespace', help='Specify the target namespace to install to for the extension instance. This' ' parameter is required if extension scope is set to \'namespace\'') + + with self.argument_context(f"{consts.EXTENSION_NAME} delete") as c: + c.argument('yes', + options_list=['--yes', '-y'], + help='Ignore confirmation prompts') diff --git a/src/k8s-extension/azext_k8s_extension/action.py b/src/k8s-extension/azext_k8s_extension/action.py index 4afbbbcd611..cb37e500267 100644 --- a/src/k8s-extension/azext_k8s_extension/action.py +++ b/src/k8s-extension/azext_k8s_extension/action.py @@ -16,10 +16,10 @@ def __call__(self, parser, namespace, values, option_string=None): try: key, value = item.split('=', 1) settings[key] = value - except ValueError: + except ValueError as ex: raise ArgumentUsageError('Usage error: {} configuration_setting_key=configuration_setting_value'. - format(option_string)) - super(AddConfigurationSettings, self).__call__(parser, namespace, settings, option_string) + format(option_string)) from ex + super().__call__(parser, namespace, settings, option_string) # pylint: disable=protected-access, too-few-public-methods @@ -31,7 +31,7 @@ def __call__(self, parser, namespace, values, option_string=None): try: key, value = item.split('=', 1) prot_settings[key] = value - except ValueError: + except ValueError as ex: raise ArgumentUsageError('Usage error: {} configuration_protected_setting_key=' - 'configuration_protected_setting_value'.format(option_string)) - super(AddConfigurationProtectedSettings, self).__call__(parser, namespace, prot_settings, option_string) + 'configuration_protected_setting_value'.format(option_string)) from ex + super().__call__(parser, namespace, prot_settings, option_string) diff --git a/src/k8s-extension/azext_k8s_extension/commands.py b/src/k8s-extension/azext_k8s_extension/commands.py index abe6f501b79..96875ee06df 100644 --- a/src/k8s-extension/azext_k8s_extension/commands.py +++ b/src/k8s-extension/azext_k8s_extension/commands.py @@ -20,6 +20,6 @@ def load_command_table(self, _): is_preview=True) \ as g: g.custom_command('create', 'create_k8s_extension') - g.custom_command('delete', 'delete_k8s_extension', confirmation=True) + g.custom_command('delete', 'delete_k8s_extension') g.custom_command('list', 'list_k8s_extension', table_transformer=k8s_extension_list_table_format) g.custom_show_command('show', 'show_k8s_extension', table_transformer=k8s_extension_show_table_format) diff --git a/src/k8s-extension/azext_k8s_extension/custom.py b/src/k8s-extension/azext_k8s_extension/custom.py index 42f5d3234fc..0719c48dc83 100644 --- a/src/k8s-extension/azext_k8s_extension/custom.py +++ b/src/k8s-extension/azext_k8s_extension/custom.py @@ -17,7 +17,6 @@ from .partner_extensions.ContainerInsights import ContainerInsights from .partner_extensions.AzureDefender import AzureDefender -from .partner_extensions.Cassandra import Cassandra from .partner_extensions.AzureMLKubernetes import AzureMLKubernetes from .partner_extensions.OpenServiceMesh import OpenServiceMesh from .partner_extensions.DefaultExtension import DefaultExtension @@ -35,7 +34,6 @@ def ExtensionFactory(extension_name): 'microsoft.azuredefender.kubernetes': AzureDefender, 'microsoft.openservicemesh': OpenServiceMesh, 'microsoft.azureml.kubernetes': AzureMLKubernetes, - 'cassandradatacentersoperator': Cassandra, } # Return the extension if we find it in the map, else return the default @@ -67,7 +65,8 @@ def show_k8s_extension(client, resource_group_name, cluster_name, name, cluster_ cluster_rp, cluster_type, cluster_name, name) else: message = ex.message - raise ResourceNotFoundError(message) + raise ResourceNotFoundError(message) from ex + raise ex def create_k8s_extension(cmd, client, resource_group_name, cluster_name, name, cluster_type, @@ -98,7 +97,7 @@ def create_k8s_extension(cmd, client, resource_group_name, cluster_name, name, c config_protected_settings = {} # Get Configuration Settings from file if configuration_settings_file is not None: - config_settings = __get_config_settings_from_file(configuration_settings_file) + config_settings = __read_config_settings_file(configuration_settings_file) if configuration_settings is not None: for dicts in configuration_settings: @@ -107,7 +106,7 @@ def create_k8s_extension(cmd, client, resource_group_name, cluster_name, name, c # Get Configuration Protected Settings from file if configuration_protected_settings_file is not None: - config_protected_settings = __get_config_settings_from_file(configuration_protected_settings_file) + config_protected_settings = __read_config_settings_file(configuration_protected_settings_file) if configuration_protected_settings is not None: for dicts in configuration_protected_settings: @@ -191,7 +190,7 @@ def update_k8s_extension(client, resource_group_name, cluster_type, cluster_name # return client.update(resource_group_name, cluster_rp, cluster_type, cluster_name, name, upd_extension) -def delete_k8s_extension(client, resource_group_name, cluster_name, name, cluster_type): +def delete_k8s_extension(cmd, client, resource_group_name, cluster_name, name, cluster_type, yes=False): """Delete an existing Kubernetes Extension. """ @@ -201,12 +200,12 @@ def delete_k8s_extension(client, resource_group_name, cluster_name, name, cluste try: extension = client.get(resource_group_name, cluster_rp, cluster_type, cluster_name, name) except HttpResponseError: - logger.warning("No extension with name '%s' found on cluster '%s', so nothing to delete", cluster_name, name) + logger.warning("No extension with name '%s' found on cluster '%s', so nothing to delete", name, cluster_name) return None extension_class = ExtensionFactory(extension.extension_type.lower()) # If there is any custom delete logic, this will call the logic - extension_class.Delete(client, resource_group_name, cluster_name, name, cluster_type) + extension_class.Delete(cmd, client, resource_group_name, cluster_name, name, cluster_type, yes) return client.delete(resource_group_name, cluster_rp, cluster_type, cluster_name, name) @@ -281,18 +280,15 @@ def __validate_version_and_auto_upgrade(version, auto_upgrade_minor_version): auto_upgrade_minor_version = False -def __get_config_settings_from_file(file_path): +def __read_config_settings_file(file_path): try: - config_file = open(file_path,) - settings = json.load(config_file) - except ValueError: - raise Exception("File {} is not a valid JSON file".format(file_path)) - - files = len(settings) - if files == 0: - raise Exception("File {} is empty".format(file_path)) - - return settings + with open(file_path, 'r') as f: + settings = json.load(f) + if len(settings) == 0: + raise Exception("File {} is empty".format(file_path)) + return settings + except ValueError as ex: + raise Exception("File {} is not a valid JSON file".format(file_path)) from ex def __is_dogfood_cluster(cmd): diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/AzureDefender.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/AzureDefender.py index ffb6a926328..b8da6a293b6 100644 --- a/src/k8s-extension/azext_k8s_extension/partner_extensions/AzureDefender.py +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/AzureDefender.py @@ -8,17 +8,16 @@ from knack.log import get_logger from ..vendored_sdks.models import ExtensionInstance -from ..vendored_sdks.models import ExtensionInstanceUpdate from ..vendored_sdks.models import ScopeCluster from ..vendored_sdks.models import Scope -from .PartnerExtensionModel import PartnerExtensionModel +from .DefaultExtension import DefaultExtension from .ContainerInsights import _get_container_insights_settings logger = get_logger(__name__) -class AzureDefender(PartnerExtensionModel): +class AzureDefender(DefaultExtension): def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, extension_type, scope, auto_upgrade_minor_version, release_train, version, target_namespace, release_namespace, configuration_settings, configuration_protected_settings, @@ -59,17 +58,3 @@ def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_t configuration_protected_settings=configuration_protected_settings ) return extension_instance, name, create_identity - - def Update(self, extension, auto_upgrade_minor_version, release_train, version): - """ExtensionType 'microsoft.azuredefender.kubernetes' specific validations & defaults for Update - Must create and return a valid 'ExtensionInstanceUpdate' object. - - """ - return ExtensionInstanceUpdate( - auto_upgrade_minor_version=auto_upgrade_minor_version, - release_train=release_train, - version=version - ) - - def Delete(self, client, resource_group_name, cluster_name, name, cluster_type): - pass diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/AzureMLKubernetes.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/AzureMLKubernetes.py index 9f6aff45aac..c85b88c943b 100644 --- a/src/k8s-extension/azext_k8s_extension/partner_extensions/AzureMLKubernetes.py +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/AzureMLKubernetes.py @@ -10,6 +10,7 @@ import copy from hashlib import md5 from typing import Any, Dict, List, Tuple +from azext_k8s_extension.partner_extensions.DefaultExtension import DefaultExtension import azure.mgmt.relay import azure.mgmt.relay.models @@ -27,10 +28,9 @@ from msrestazure.azure_exceptions import CloudError from .._client_factory import cf_resources -from .PartnerExtensionModel import PartnerExtensionModel +from .DefaultExtension import DefaultExtension, user_confirmation_factory from ..vendored_sdks.models import ( ExtensionInstance, - ExtensionInstanceUpdate, Scope, ScopeCluster ) @@ -41,7 +41,7 @@ # pylint: disable=too-many-instance-attributes -class AzureMLKubernetes(PartnerExtensionModel): +class AzureMLKubernetes(DefaultExtension): def __init__(self): # constants for configuration settings. self.DEFAULT_RELEASE_NAMESPACE = 'azureml' @@ -82,6 +82,9 @@ def __init__(self): self.privateEndpointNodeport = 'privateEndpointNodeport' self.inferenceLoadBalancerHA = 'inferenceLoadBalancerHA' + # constants for existing AKS to AMLARC migration + self.IS_AKS_MIGRATION = 'isAKSMigration' + # reference mapping self.reference_mapping = { self.RELAY_SERVER_CONNECTION_STRING: [self.RELAY_CONNECTION_STRING_KEY, self.RELAY_CONNECTION_STRING_DEPRECATED_KEY], @@ -155,18 +158,12 @@ def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_t ) return extension_instance, name, create_identity - def Update(self, extension, auto_upgrade_minor_version, release_train, version): - return ExtensionInstanceUpdate( - auto_upgrade_minor_version=auto_upgrade_minor_version, - release_train=release_train, - version=version - ) - - def Delete(self, client, resource_group_name, cluster_name, name, cluster_type): + def Delete(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, yes): # Give a warning message logger.warning("If nvidia.com/gpu or fuse resource is not recognized by kubernetes after this deletion, " "you probably have installed nvidia-device-plugin or fuse-device-plugin before installing AMLArc extension. " "Please try to reinstall device plugins to fix this issue.") + user_confirmation_factory(cmd, yes) def __validate_config(self, configuration_settings, configuration_protected_settings): # perform basic validation of the input config @@ -211,6 +208,12 @@ def __validate_scoring_fe_settings(self, configuration_settings, configuration_p configuration_settings['clusterPurpose'] = 'DevTest' else: configuration_settings['clusterPurpose'] = 'FastProd' + isAKSMigration = _get_value_from_config_protected_config( + self.IS_AKS_MIGRATION, configuration_settings, configuration_protected_settings) + isAKSMigration = str(isAKSMigration).lower() == 'true' + if isAKSMigration: + configuration_settings['scoringFe.namespace'] = "default" + configuration_settings[self.IS_AKS_MIGRATION] = "true" feSslCertFile = configuration_protected_settings.get(self.sslCertPemFile) feSslKeyFile = configuration_protected_settings.get(self.sslKeyPemFile) allowInsecureConnections = _get_value_from_config_protected_config( diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/Cassandra.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/Cassandra.py deleted file mode 100644 index 289e8053223..00000000000 --- a/src/k8s-extension/azext_k8s_extension/partner_extensions/Cassandra.py +++ /dev/null @@ -1,60 +0,0 @@ -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- - -# pylint: disable=unused-argument - -from ..vendored_sdks.models import ExtensionInstance -from ..vendored_sdks.models import ExtensionInstanceUpdate -from ..vendored_sdks.models import ScopeCluster -from ..vendored_sdks.models import ScopeNamespace -from ..vendored_sdks.models import Scope - -from .PartnerExtensionModel import PartnerExtensionModel - - -class Cassandra(PartnerExtensionModel): - def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, extension_type, - scope, auto_upgrade_minor_version, release_train, version, target_namespace, - release_namespace, configuration_settings, configuration_protected_settings, - configuration_settings_file, configuration_protected_settings_file): - - """Default validations & defaults for Create - Must create and return a valid 'ExtensionInstance' object. - - """ - ext_scope = None - if scope is not None: - if scope.lower() == 'cluster': - scope_cluster = ScopeCluster(release_namespace=release_namespace) - ext_scope = Scope(cluster=scope_cluster, namespace=None) - elif scope.lower() == 'namespace': - scope_namespace = ScopeNamespace(target_namespace=target_namespace) - ext_scope = Scope(namespace=scope_namespace, cluster=None) - - create_identity = True - extension_instance = ExtensionInstance( - extension_type=extension_type, - auto_upgrade_minor_version=auto_upgrade_minor_version, - release_train=release_train, - version=version, - scope=ext_scope, - configuration_settings=configuration_settings, - configuration_protected_settings=configuration_protected_settings, - ) - return extension_instance, name, create_identity - - def Update(self, extension, auto_upgrade_minor_version, release_train, version): - """Default validations & defaults for Update - Must create and return a valid 'ExtensionInstanceUpdate' object. - - """ - return ExtensionInstanceUpdate( - auto_upgrade_minor_version=auto_upgrade_minor_version, - release_train=release_train, - version=version - ) - - def Delete(self, client, resource_group_name, cluster_name, name, cluster_type): - pass diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py index 1c2a334cdda..3d4663ace14 100644 --- a/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py @@ -17,11 +17,10 @@ from msrestazure.tools import parse_resource_id, is_valid_resource_id from ..vendored_sdks.models import ExtensionInstance -from ..vendored_sdks.models import ExtensionInstanceUpdate from ..vendored_sdks.models import ScopeCluster from ..vendored_sdks.models import Scope -from .PartnerExtensionModel import PartnerExtensionModel +from .DefaultExtension import DefaultExtension from .._client_factory import ( cf_resources, cf_resource_groups, cf_log_analytics) @@ -29,7 +28,7 @@ logger = get_logger(__name__) -class ContainerInsights(PartnerExtensionModel): +class ContainerInsights(DefaultExtension): def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, extension_type, scope, auto_upgrade_minor_version, release_train, version, target_namespace, release_namespace, configuration_settings, configuration_protected_settings, @@ -71,20 +70,6 @@ def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_t ) return extension_instance, name, create_identity - def Update(self, extension, auto_upgrade_minor_version, release_train, version): - """ExtensionType 'microsoft.azuremonitor.containers' specific validations & defaults for Update - Must create and return a valid 'ExtensionInstanceUpdate' object. - - """ - return ExtensionInstanceUpdate( - auto_upgrade_minor_version=auto_upgrade_minor_version, - release_train=release_train, - version=version - ) - - def Delete(self, client, resource_group_name, cluster_name, name, cluster_type): - pass - # Custom Validation Logic for Container Insights diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/DefaultExtension.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/DefaultExtension.py index 8977ec4187e..0adec037a8f 100644 --- a/src/k8s-extension/azext_k8s_extension/partner_extensions/DefaultExtension.py +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/DefaultExtension.py @@ -5,6 +5,8 @@ # pylint: disable=unused-argument +from azure.cli.core.util import user_confirmation + from ..vendored_sdks.models import ExtensionInstance from ..vendored_sdks.models import ExtensionInstanceUpdate from ..vendored_sdks.models import ScopeCluster @@ -33,7 +35,7 @@ def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_t scope_namespace = ScopeNamespace(target_namespace=target_namespace) ext_scope = Scope(namespace=scope_namespace, cluster=None) - create_identity = False + create_identity = True extension_instance = ExtensionInstance( extension_type=extension_type, auto_upgrade_minor_version=auto_upgrade_minor_version, @@ -56,5 +58,11 @@ def Update(self, extension, auto_upgrade_minor_version, release_train, version): version=version ) - def Delete(self, client, resource_group_name, cluster_name, name, cluster_type): - pass + def Delete(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, yes): + user_confirmation_factory(cmd, yes) + + +def user_confirmation_factory(cmd, yes, message="Are you sure you want to perform this operation?"): + if cmd.cli_ctx.config.getboolean('core', 'disable_confirm_prompt', fallback=False): + return + user_confirmation(message, yes=yes) diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/OpenServiceMesh.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/OpenServiceMesh.py index ff65193b3dd..8480d155b05 100644 --- a/src/k8s-extension/azext_k8s_extension/partner_extensions/OpenServiceMesh.py +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/OpenServiceMesh.py @@ -7,18 +7,17 @@ # pylint: disable=redefined-outer-name # pylint: disable=no-member +from azext_k8s_extension.partner_extensions.DefaultExtension import DefaultExtension from knack.log import get_logger -from azure.cli.core.azclierror import InvalidArgumentValueError, RequiredArgumentMissingError +from azure.cli.core.azclierror import InvalidArgumentValueError from azure.cli.core.commands.client_factory import get_subscription_id from packaging import version import yaml import requests -from ..partner_extensions import PartnerExtensionModel - -from .PartnerExtensionModel import PartnerExtensionModel +from .DefaultExtension import DefaultExtension from ..vendored_sdks.models import ( ExtensionInstance, @@ -32,7 +31,7 @@ logger = get_logger(__name__) -class OpenServiceMesh(PartnerExtensionModel): +class OpenServiceMesh(DefaultExtension): def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, extension_type, scope, auto_upgrade_minor_version, release_train, version, target_namespace, @@ -53,16 +52,6 @@ def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_t scope_cluster = ScopeCluster(release_namespace=release_namespace) ext_scope = Scope(cluster=scope_cluster, namespace=None) - # version is a mandatory if release-train is staging or pilot - if version is None: - raise RequiredArgumentMissingError( - "A version must be provided for release-train {}.".format(release_train) - ) - # If the release-train is 'staging' or 'pilot' then auto-upgrade-minor-version MUST be set to False - if auto_upgrade_minor_version or auto_upgrade_minor_version is None: - auto_upgrade_minor_version = False - logger.warning("Setting auto-upgrade-minor-version to False since release-train is '%s'", release_train) - # NOTE-2: Return a valid ExtensionInstance object, Instance name and flag for Identity create_identity = False @@ -100,9 +89,6 @@ def Update(self, extension, auto_upgrade_minor_version, release_train, version): version=version ) - def Delete(self, client, resource_group_name, cluster_name, name, cluster_type): - pass - def _validate_tested_distro(cmd, cluster_resource_group_name, cluster_name, extension_version): diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/PartnerExtensionModel.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/PartnerExtensionModel.py index 98a6c1ea63f..8e89bfa15fc 100644 --- a/src/k8s-extension/azext_k8s_extension/partner_extensions/PartnerExtensionModel.py +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/PartnerExtensionModel.py @@ -23,5 +23,5 @@ def Update(self, extension: ExtensionInstance, auto_upgrade_minor_version: bool, pass @abstractmethod - def Delete(self, client, resource_group_name: str, cluster_name: str, name: str, cluster_type: str): + def Delete(self, cmd, client, resource_group_name: str, cluster_name: str, name: str, cluster_type: str, yes: bool): pass diff --git a/src/k8s-extension/setup.py b/src/k8s-extension/setup.py index 014ed287490..276b7502a01 100644 --- a/src/k8s-extension/setup.py +++ b/src/k8s-extension/setup.py @@ -32,7 +32,7 @@ # TODO: Add any additional SDK dependencies here DEPENDENCIES = [] -VERSION = "0.6.1" +VERSION = "0.7.0" with open('README.rst', 'r', encoding='utf-8') as f: README = f.read()