diff --git a/src/k8s-extension/HISTORY.rst b/src/k8s-extension/HISTORY.rst index 5855f96591f..295bb0e4136 100644 --- a/src/k8s-extension/HISTORY.rst +++ b/src/k8s-extension/HISTORY.rst @@ -3,6 +3,12 @@ Release History =============== +0.6.1 +++++++++++++++++++ +* Remove sending identity for clusters in Dogfood +* Provide fix for getting tested distros for microsoft.openservicemesh +* Add location to model for identity + 0.6.0 ++++++++++++++++++ * Update extension resource models to Track2 diff --git a/src/k8s-extension/azext_k8s_extension/consts.py b/src/k8s-extension/azext_k8s_extension/consts.py index c75489d2362..b7fe91cb8eb 100644 --- a/src/k8s-extension/azext_k8s_extension/consts.py +++ b/src/k8s-extension/azext_k8s_extension/consts.py @@ -8,3 +8,4 @@ EXTENSION_PACKAGE_NAME = "azext_k8s_extension" PROVIDER_NAMESPACE = 'Microsoft.KubernetesConfiguration' REGISTERED = "Registered" +DF_RM_ENDPOINT = 'https://api-dogfood.resources.windows-int.net/' diff --git a/src/k8s-extension/azext_k8s_extension/custom.py b/src/k8s-extension/azext_k8s_extension/custom.py index 9a6bdb10656..42f5d3234fc 100644 --- a/src/k8s-extension/azext_k8s_extension/custom.py +++ b/src/k8s-extension/azext_k8s_extension/custom.py @@ -138,7 +138,8 @@ def create_k8s_extension(cmd, client, resource_group_name, cluster_name, name, c validate_cc_registration(cmd) # Create identity, if required - if create_identity: + # We don't create the identity if we are in DF + if create_identity and not __is_dogfood_cluster(cmd): extension_instance.identity, extension_instance.location = \ __create_identity(cmd, resource_group_name, cluster_name, cluster_type, cluster_rp) @@ -292,3 +293,7 @@ def __get_config_settings_from_file(file_path): raise Exception("File {} is empty".format(file_path)) return settings + + +def __is_dogfood_cluster(cmd): + return cmd.cli_ctx.cloud.endpoints.resource_manager == consts.DF_RM_ENDPOINT 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 048dfe58637..ff65193b3dd 100644 --- a/src/k8s-extension/azext_k8s_extension/partner_extensions/OpenServiceMesh.py +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/OpenServiceMesh.py @@ -14,6 +14,7 @@ from packaging import version import yaml +import requests from ..partner_extensions import PartnerExtensionModel @@ -32,8 +33,6 @@ class OpenServiceMesh(PartnerExtensionModel): - CHART_NAME = "osm-arc" - CHART_LOCATION = "https://azure.github.io/osm-azure" 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, @@ -67,7 +66,7 @@ def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_t # NOTE-2: Return a valid ExtensionInstance object, Instance name and flag for Identity create_identity = False - # _validate_tested_distro(cmd, resource_group_name, cluster_name, version) + _validate_tested_distro(cmd, resource_group_name, cluster_name, version) extension_instance = ExtensionInstance( extension_type=extension_type, @@ -105,58 +104,52 @@ 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): +def _validate_tested_distro(cmd, cluster_resource_group_name, cluster_name, extension_version): -# field_unavailable_error = '\"testedDistros\" field unavailable for version {0} of microsoft.openservicemesh, ' \ -# 'cannot determine if this Kubernetes distribution has been properly tested'.format(extension_version) + field_unavailable_error = '\"testedDistros\" field unavailable for version {0} of microsoft.openservicemesh, ' \ + 'cannot determine if this Kubernetes distribution has been properly tested'.format(extension_version) -# if version.parse(str(extension_version)) <= version.parse("0.8.3"): -# logger.warning(field_unavailable_error) -# return + if version.parse(str(extension_version)) <= version.parse("0.8.3"): + logger.warning(field_unavailable_error) + return -# subscription_id = get_subscription_id(cmd.cli_ctx) -# resources = cf_resources(cmd.cli_ctx, subscription_id) + subscription_id = get_subscription_id(cmd.cli_ctx) + resources = cf_resources(cmd.cli_ctx, subscription_id) -# cluster_resource_id = '/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Kubernetes' \ -# '/connectedClusters/{2}'.format(subscription_id, cluster_resource_group_name, cluster_name) + cluster_resource_id = '/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Kubernetes' \ + '/connectedClusters/{2}'.format(subscription_id, cluster_resource_group_name, cluster_name) -# resource = resources.get_by_id(cluster_resource_id, '2020-01-01-preview') -# cluster_distro = resource.properties['distribution'].lower() + resource = resources.get_by_id(cluster_resource_id, '2020-01-01-preview') + cluster_distro = resource.properties['distribution'].lower() -# if cluster_distro == "general": -# logger.warning('Unable to determine if distro has been tested for microsoft.openservicemesh, ' -# 'kubernetes distro: \"general\"') -# return + if cluster_distro == "general": + logger.warning('Unable to determine if distro has been tested for microsoft.openservicemesh, ' + 'kubernetes distro: \"general\"') + return -# tested_distros = _get_tested_distros(extension_version) + tested_distros = _get_tested_distros(extension_version) -# if tested_distros is None: -# logger.warning(field_unavailable_error) -# elif cluster_distro not in tested_distros.split(): -# logger.warning('Untested kubernetes distro for microsoft.openservicemesh, Kubernetes distro is %s', -# cluster_distro) + if tested_distros is None: + logger.warning(field_unavailable_error) + elif cluster_distro not in tested_distros.split(): + logger.warning('Untested kubernetes distro for microsoft.openservicemesh, Kubernetes distro is %s', + cluster_distro) -# def _get_tested_distros(chart_version): +def _get_tested_distros(chart_version): -# try: -# chart_arc = ChartBuilder({ -# "name": OpenServiceMesh.CHART_NAME, -# "version": str(chart_version), -# "source": { -# "type": "repo", -# "location": OpenServiceMesh.CHART_LOCATION -# } -# }) -# except VersionError: -# raise InvalidArgumentValueError( -# "Invalid version '{}' for microsoft.openservicemesh".format(chart_version) -# ) + chart_url = 'https://raw.githubusercontent.com/Azure/osm-azure/' \ + 'v{0}/charts/osm-arc/values.yaml'.format(chart_version) + chart_request = requests.get(url=chart_url) -# values = chart_arc.get_values() -# values_yaml = yaml.load(values.raw, Loader=yaml.FullLoader) + if chart_request.status_code == 404: + raise InvalidArgumentValueError( + "Invalid version '{}' for microsoft.openservicemesh".format(chart_version) + ) + + values_yaml = yaml.load(chart_request.text, Loader=yaml.FullLoader) -# try: -# return values_yaml['OpenServiceMesh']['testedDistros'] -# except KeyError: -# return None + try: + return values_yaml['OpenServiceMesh']['testedDistros'] + except KeyError: + return None diff --git a/src/k8s-extension/azext_k8s_extension/tests/latest/test_open_service_mesh.py b/src/k8s-extension/azext_k8s_extension/tests/latest/test_open_service_mesh.py index 61b774045ce..72e94a06831 100644 --- a/src/k8s-extension/azext_k8s_extension/tests/latest/test_open_service_mesh.py +++ b/src/k8s-extension/azext_k8s_extension/tests/latest/test_open_service_mesh.py @@ -9,15 +9,14 @@ import unittest from azure.cli.core.azclierror import InvalidArgumentValueError -# from azext_k8s_extension.partner_extensions.OpenServiceMesh import _get_tested_distros +from azext_k8s_extension.partner_extensions.OpenServiceMesh import _get_tested_distros TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) class TestOpenServiceMesh(unittest.TestCase): def test_bad_osm_arc_version(self): - # version = "0.7.1" - # err = "Invalid version \'" + str(version) + "\' for microsoft.openservicemesh" - # with self.assertRaises(InvalidArgumentValueError) as argError: - # _get_tested_distros(version) - # self.assertEqual(str(argError.exception), err) - pass + version = "0.7.1" + err = "Invalid version \'" + str(version) + "\' for microsoft.openservicemesh" + with self.assertRaises(InvalidArgumentValueError) as argError: + _get_tested_distros(version) + self.assertEqual(str(argError.exception), err) diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models.py index 315237c6587..9370d28bbff 100644 --- a/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models.py +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models.py @@ -279,6 +279,8 @@ class ExtensionInstance(ProxyResource): :param identity: The identity of the configuration. :type identity: ~azure.mgmt.kubernetesconfiguration.v2020_07_01_preview.models.ConfigurationIdentity + :param location: Location of resource type + :type location: str """ _validation = { @@ -311,6 +313,7 @@ class ExtensionInstance(ProxyResource): 'last_status_time': {'key': 'properties.lastStatusTime', 'type': 'str'}, 'error_info': {'key': 'properties.errorInfo', 'type': 'ErrorDefinition'}, 'identity': {'key': 'identity', 'type': 'ConfigurationIdentity'}, + 'location': {'key': 'location', 'type': 'str'}, } def __init__( @@ -332,6 +335,7 @@ def __init__( self.last_status_time = None self.error_info = None self.identity = kwargs.get('identity', None) + self.location = kwargs.get('location', None) class ExtensionInstancesList(msrest.serialization.Model): diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models_py3.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models_py3.py index f749d3d7078..a3cb0d37faf 100644 --- a/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models_py3.py +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models_py3.py @@ -297,6 +297,8 @@ class ExtensionInstance(ProxyResource): :param identity: The identity of the configuration. :type identity: ~azure.mgmt.kubernetesconfiguration.v2020_07_01_preview.models.ConfigurationIdentity + :param location: Location of resource type + :type location: str """ _validation = { @@ -329,6 +331,7 @@ class ExtensionInstance(ProxyResource): 'last_status_time': {'key': 'properties.lastStatusTime', 'type': 'str'}, 'error_info': {'key': 'properties.errorInfo', 'type': 'ErrorDefinition'}, 'identity': {'key': 'identity', 'type': 'ConfigurationIdentity'}, + 'location': {'key': 'location', 'type': 'str'}, } def __init__( @@ -344,6 +347,7 @@ def __init__( configuration_protected_settings: Optional[Dict[str, str]] = None, statuses: Optional[List["ExtensionStatus"]] = None, identity: Optional["ConfigurationIdentity"] = None, + location: Optional[str] = None, **kwargs ): super(ExtensionInstance, self).__init__(system_data=system_data, **kwargs) @@ -361,6 +365,7 @@ def __init__( self.last_status_time = None self.error_info = None self.identity = identity + self.location = location class ExtensionInstancesList(msrest.serialization.Model): diff --git a/src/k8s-extension/setup.py b/src/k8s-extension/setup.py index 6efb1bc5a59..014ed287490 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.0" +VERSION = "0.6.1" with open('README.rst', 'r', encoding='utf-8') as f: README = f.read()