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

Add distro validation for osm-arc #50

Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,32 @@
from azure.cli.core.azclierror import InvalidArgumentValueError, RequiredArgumentMissingError
from knack.log import get_logger

from ..vendored_sdks.models import ExtensionInstance
from ..vendored_sdks.models import ExtensionInstanceUpdate
from ..vendored_sdks.models import ScopeCluster
from ..vendored_sdks.models import Scope
from azure.cli.core.commands.client_factory import get_subscription_id
nshankar13 marked this conversation as resolved.
Show resolved Hide resolved

from pyhelm.chartbuilder import ChartBuilder
from packaging import version
import yaml

from ..partner_extensions import PartnerExtensionModel

from .PartnerExtensionModel import PartnerExtensionModel

from ..vendored_sdks.models import (
ExtensionInstance,
ExtensionInstanceUpdate,
ScopeCluster,
Scope
)

from .._client_factory import cf_resources

logger = get_logger(__name__)


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,
release_namespace, configuration_settings, configuration_protected_settings,
Expand Down Expand Up @@ -62,6 +77,9 @@ 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)

extension_instance = ExtensionInstance(
extension_type=extension_type,
auto_upgrade_minor_version=auto_upgrade_minor_version,
Expand Down Expand Up @@ -93,3 +111,56 @@ def Update(self, extension, auto_upgrade_minor_version, release_train, version):
release_train=release_train,
version=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)

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)

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()

if cluster_distro == "general":
logger.warning('Unable to determine if distro has been tested for Microsoft.openservicemesh, '
nshankar13 marked this conversation as resolved.
Show resolved Hide resolved
'kubernetes distro: \"general\"')
return

tested_distros = _get_tested_distros(extension_version)

if tested_distros is None:
logger.warning(field_unavailable_error)
elif cluster_distro in tested_distros.split():
logger.warning('%s is a tested kubernetes distribution for Microsoft.openservicemesh', cluster_distro)
else:
logger.warning('Untested kubernetes distro for Microsoft.openservicemesh, Kubernetes distro is %s',
cluster_distro)


def _get_tested_distros(chart_version):

chart_arc = ChartBuilder({
"name": OpenServiceMesh.CHART_NAME,
"version": str(chart_version),
"source": {
"type": "repo",
"location": OpenServiceMesh.CHART_LOCATION
}
})
values = chart_arc.get_values()
nshankar13 marked this conversation as resolved.
Show resolved Hide resolved
values_yaml = yaml.load(values.raw, Loader=yaml.FullLoader)

try:
return values_yaml['OpenServiceMesh']['testedDistros']
except KeyError:
return None
4 changes: 3 additions & 1 deletion src/k8s-extension/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
]

# TODO: Add any additional SDK dependencies here
DEPENDENCIES = []
DEPENDENCIES = [
'pyhelm'
]

VERSION = "0.4.3"

Expand Down