Skip to content

Commit

Permalink
Change extension validation logic osm-arc (#116)
Browse files Browse the repository at this point in the history
* added default identity support for microsoft.azurebackup.backupagent (#115)

* Change extension validation logic osm-arc

Signed-off-by: nshankar13 <nshankar@microsoft.com>

Co-authored-by: sangitaray2021 <82883570+sangitaray2021@users.noreply.github.com>
Co-authored-by: Jonathan Innis <jonathan.innis.ji@gmail.com>
  • Loading branch information
3 people authored Apr 8, 2022
1 parent bccbf7f commit 1238f1e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
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

0 comments on commit 1238f1e

Please sign in to comment.