Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change extension validation logic osm-arc #116

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/k8s-extension/azext_k8s_extension/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def ExtensionFactory(extension_name):
"microsoft.openservicemesh": OpenServiceMesh,
"microsoft.azureml.kubernetes": AzureMLKubernetes,
"microsoft.dapr": Dapr,
"microsoft.azurebackup.backupagent": DefaultExtension,
}

# Return the extension if we find it in the map, else return the default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# pylint: disable=redefined-outer-name
# pylint: disable=no-member

import json
from knack.log import get_logger

from azure.cli.core.azclierror import InvalidArgumentValueError
Expand Down Expand Up @@ -51,7 +52,7 @@ def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_t
# NOTE-2: Return a valid Extension object, Instance name and flag for Identity
create_identity = True

_validate_tested_distro(cmd, resource_group_name, cluster_name, version)
_validate_tested_distro(cmd, resource_group_name, cluster_name, version, release_train)

extension = Extension(
extension_type=extension_type,
Expand All @@ -67,15 +68,12 @@ def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_t
return extension, name, create_identity


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, extension_release_train):

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)

logger.debug('Input version: %s', version)
if version.parse(str(extension_version)) <= version.parse("0.8.3"):
logger.warning(field_unavailable_error)
return
logger.debug('Input version: %s', extension_version)

subscription_id = get_subscription_id(cmd.cli_ctx)
resources = cf_resources(cmd.cli_ctx, subscription_id)
Expand All @@ -84,8 +82,30 @@ def _validate_tested_distro(cmd, cluster_resource_group_name, cluster_name, exte
'/connectedClusters/{2}'.format(subscription_id, cluster_resource_group_name, cluster_name)

resource = resources.get_by_id(cluster_resource_id, '2021-10-01')
cluster_location = resource.location
cluster_distro = resource.properties['distribution'].lower()

if extension_version is None and extension_release_train != "staging":
if str(cluster_location) == "eastus2euap":
ring = "canary"
else:
ring = "batch1"

if extension_release_train is None:
extension_release_train = "stable"

req_url = 'https://mcr.microsoft.com/v2/oss/openservicemesh/{0}/{1}/osm-arc/tags/list'\
.format(ring, extension_release_train)
req = requests.get(url=req_url)
req_json = json.loads(req.text)
tags = req_json['tags']

extension_version = tags[len(tags) - 1]

if version.parse(str(extension_version)) <= version.parse("0.8.3"):
logger.warning(field_unavailable_error)
return

if cluster_distro == "general":
logger.warning('Unable to determine if distro has been tested for microsoft.openservicemesh, '
'kubernetes distro: \"general\"')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

# pylint: disable=protected-access

import os
import unittest

from azure.cli.core.azclierror import InvalidArgumentValueError
Expand Down