diff --git a/src/k8s-extension/HISTORY.rst b/src/k8s-extension/HISTORY.rst index 4e56486b0fb..117967b4c23 100644 --- a/src/k8s-extension/HISTORY.rst +++ b/src/k8s-extension/HISTORY.rst @@ -3,6 +3,10 @@ Release History =============== +0.7.1 +++++++++++++++++++ +* Fix DF resource manager endpoint check + 0.7.0 ++++++++++++++++++ * Enable identity by default for extensions diff --git a/src/k8s-extension/azext_k8s_extension/consts.py b/src/k8s-extension/azext_k8s_extension/consts.py index b7fe91cb8eb..350344bc53a 100644 --- a/src/k8s-extension/azext_k8s_extension/consts.py +++ b/src/k8s-extension/azext_k8s_extension/consts.py @@ -8,4 +8,4 @@ EXTENSION_PACKAGE_NAME = "azext_k8s_extension" PROVIDER_NAMESPACE = 'Microsoft.KubernetesConfiguration' REGISTERED = "Registered" -DF_RM_ENDPOINT = 'https://api-dogfood.resources.windows-int.net/' +DF_RM_HOSTNAME = '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 0719c48dc83..4a5985bb1b3 100644 --- a/src/k8s-extension/azext_k8s_extension/custom.py +++ b/src/k8s-extension/azext_k8s_extension/custom.py @@ -7,6 +7,7 @@ import json from knack.log import get_logger +from urllib.parse import urlparse from azure.cli.core.azclierror import ResourceNotFoundError, MutuallyExclusiveArgumentError, \ InvalidArgumentValueError, CommandNotFoundError, RequiredArgumentMissingError @@ -138,7 +139,7 @@ def create_k8s_extension(cmd, client, resource_group_name, cluster_name, name, c # Create identity, if required # We don't create the identity if we are in DF - if create_identity and not __is_dogfood_cluster(cmd): + 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) @@ -291,5 +292,5 @@ def __read_config_settings_file(file_path): raise Exception("File {} is not a valid JSON file".format(file_path)) from ex -def __is_dogfood_cluster(cmd): - return cmd.cli_ctx.cloud.endpoints.resource_manager == consts.DF_RM_ENDPOINT +def is_dogfood_cluster(cmd): + return urlparse(cmd.cli_ctx.cloud.endpoints.resource_manager).hostname == consts.DF_RM_HOSTNAME diff --git a/src/k8s-extension/azext_k8s_extension/tests/latest/MockClasses.py b/src/k8s-extension/azext_k8s_extension/tests/latest/MockClasses.py new file mode 100644 index 00000000000..8a6313c9ce6 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/tests/latest/MockClasses.py @@ -0,0 +1,24 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + + +from azure.cli.core import AzCommandsLoader + + +class MockCommand: + def __init__(self): + self.cli_ctx = MockCLIContext() + +class MockCLIContext: + def __init__(self): + self.cloud = MockCloud() + +class MockCloud: + def __init__(self): + self.endpoints = Endpoints() + +class Endpoints: + def __init__(self): + self.resource_manager = "" \ No newline at end of file diff --git a/src/k8s-extension/azext_k8s_extension/tests/latest/test_custom.py b/src/k8s-extension/azext_k8s_extension/tests/latest/test_custom.py new file mode 100644 index 00000000000..0ea7cefb9ba --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/tests/latest/test_custom.py @@ -0,0 +1,38 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import os +from typing import no_type_check +import unittest + +from .MockClasses import MockCLIContext, MockCommand +from azext_k8s_extension.custom import is_dogfood_cluster + + +class TestIsDogfoodCluster(unittest.TestCase): + def test_dogfood_cluster(self): + cmd = MockCommand() + cmd.cli_ctx.cloud.endpoints.resource_manager = "https://api-dogfood.resources.windows-int.net" + assert is_dogfood_cluster(cmd) + + def test_dogfood_cluster_with_slash(self): + cmd = MockCommand() + cmd.cli_ctx.cloud.endpoints.resource_manager = "https://api-dogfood.resources.windows-int.net/" + assert is_dogfood_cluster(cmd) + + def test_longer_hostname(self): + cmd = MockCommand() + cmd.cli_ctx.cloud.endpoints.resource_manager = "https://api-dogfood.resources.windows-int.otherwebsite.net/" + assert not is_dogfood_cluster(cmd) + + def malformed_url(self): + cmd = MockCommand() + cmd.cli_ctx.cloud.endpoints.resource_manager = "htmalformed~2987493" + assert not is_dogfood_cluster(cmd) + + def test_prod_cluster(self): + cmd = MockCommand() + cmd.cli_ctx.cloud.endpoints.resource_manager = "https://management.azure.com" + assert not is_dogfood_cluster(cmd) \ No newline at end of file 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 72e94a06831..b087be716d8 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 @@ -11,7 +11,6 @@ from azure.cli.core.azclierror import InvalidArgumentValueError 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): diff --git a/src/k8s-extension/setup.py b/src/k8s-extension/setup.py index 276b7502a01..69ce92ae3e3 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.7.0" +VERSION = "0.7.1" with open('README.rst', 'r', encoding='utf-8') as f: README = f.read()