Skip to content

Commit

Permalink
Merge branch 'k8s-extension/public' into huayang/fe-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis authored Jul 27, 2021
2 parents c0cc8c9 + bc48fdb commit 8432720
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from packaging import version
import yaml
import requests

from ..partner_extensions import PartnerExtensionModel

Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 8432720

Please sign in to comment.