Skip to content

Commit

Permalink
[k8s-extension] Release v0.4.0 with OpenServiceMesh (#3376)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis authored May 16, 2021
1 parent 0e629c1 commit 459a2fb
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/k8s-extension/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Release History
===============

0.4.0
++++++++++++++++++

* Release customization for microsoft.openservicemesh

0.3.1
++++++++++++++++++

Expand Down
4 changes: 2 additions & 2 deletions src/k8s-extension/azext_k8s_extension/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@


# pylint: disable=broad-except
def _validate_cc_registration(cmd):
def validate_cc_registration(cmd):
try:
rp_client = _resource_providers_client(cmd.cli_ctx)
registration_state = rp_client.get(consts.PROVIDER_NAMESPACE).registration_state

if registration_state != "Registered":
if registration_state.lower() != consts.REGISTERED.lower():
logger.warning("'Extensions' cannot be used because '%s' provider has not been registered."
"More details for registering this provider can be found here - "
"https://aka.ms/RegisterKubernetesConfigurationProvider", consts.PROVIDER_NAMESPACE)
Expand Down
1 change: 1 addition & 0 deletions src/k8s-extension/azext_k8s_extension/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
EXTENSION_NAME = 'k8s-extension'
EXTENSION_PACKAGE_NAME = "azext_k8s_extension"
PROVIDER_NAMESPACE = 'Microsoft.KubernetesConfiguration'
REGISTERED = "Registered"
6 changes: 4 additions & 2 deletions src/k8s-extension/azext_k8s_extension/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
from azext_k8s_extension.vendored_sdks.models import ConfigurationIdentity
from azext_k8s_extension.vendored_sdks.models import ErrorResponseException
from azext_k8s_extension.vendored_sdks.models import Scope
from azext_k8s_extension._validators import _validate_cc_registration
from azext_k8s_extension._validators import validate_cc_registration

from .partner_extensions.ContainerInsights import ContainerInsights
from .partner_extensions.AzureDefender import AzureDefender
from .partner_extensions.Cassandra import Cassandra
from .partner_extensions.AzureMLKubernetes import AzureMLKubernetes
from .partner_extensions.OpenServiceMesh import OpenServiceMesh
from .partner_extensions.DefaultExtension import DefaultExtension
from . import consts

Expand All @@ -35,6 +36,7 @@ def ExtensionFactory(extension_name):
extension_map = {
'microsoft.azuremonitor.containers': ContainerInsights,
'microsoft.azuredefender.kubernetes': AzureDefender,
'microsoft.openservicemesh': OpenServiceMesh,
'microsoft.azureml.kubernetes': AzureMLKubernetes,
'cassandradatacentersoperator': Cassandra,
}
Expand Down Expand Up @@ -136,7 +138,7 @@ def create_k8s_extension(cmd, client, resource_group_name, cluster_name, name, c
__validate_scope_after_customization(extension_instance.scope)

# Check that registration has been done on Microsoft.KubernetesConfiguration for the subscription
_validate_cc_registration(cmd)
validate_cc_registration(cmd)

# Create identity, if required
if create_identity:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument

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 .PartnerExtensionModel import PartnerExtensionModel

logger = get_logger(__name__)


class OpenServiceMesh(PartnerExtensionModel):
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,
configuration_settings_file, configuration_protected_settings_file):

"""ExtensionType 'microsoft.openservicemesh' specific validations & defaults for Create
Must create and return a valid 'ExtensionInstance' object.
"""
# NOTE-1: Replace default scope creation with your customization, if required
# Scope must always be cluster
ext_scope = None
if scope == 'namespace':
raise InvalidArgumentValueError("Invalid scope '{}'. This extension can be installed "
"only at 'cluster' scope.".format(scope))

scope_cluster = ScopeCluster(release_namespace=release_namespace)
ext_scope = Scope(cluster=scope_cluster, namespace=None)

valid_release_trains = ['staging', 'pilot']
# If release-train is not input, set it to 'stable'
if release_train is None:
raise RequiredArgumentMissingError(
"A release-train must be provided. Valid values are 'staging', 'pilot'."
)

if release_train.lower() in valid_release_trains:
# version is a mandatory if release-train is staging or pilot
if version is None:
raise RequiredArgumentMissingError(
"A version must be provided for release-train {}.".format(release_train)
)
# If the release-train is 'staging' or 'pilot' then auto-upgrade-minor-version MUST be set to False
if auto_upgrade_minor_version or auto_upgrade_minor_version is None:
auto_upgrade_minor_version = False
logger.warning("Setting auto-upgrade-minor-version to False since release-train is '%s'", release_train)
else:
raise InvalidArgumentValueError(
"Invalid release-train '{}'. Valid values are 'staging', 'pilot'.".format(release_train)
)

# NOTE-2: Return a valid ExtensionInstance object, Instance name and flag for Identity
create_identity = False
extension_instance = ExtensionInstance(
extension_type=extension_type,
auto_upgrade_minor_version=auto_upgrade_minor_version,
release_train=release_train,
version=version,
scope=ext_scope,
configuration_settings=configuration_settings,
configuration_protected_settings=configuration_protected_settings,
identity=None,
location=""
)
return extension_instance, name, create_identity

def Update(self, extension, auto_upgrade_minor_version, release_train, version):
"""ExtensionType 'microsoft.openservicemesh' specific validations & defaults for Update
Must create and return a valid 'ExtensionInstanceUpdate' object.
"""
# auto-upgrade-minor-version MUST be set to False if release_train is staging or pilot
if release_train.lower() in ['staging', 'pilot']:
if auto_upgrade_minor_version or auto_upgrade_minor_version is None:
auto_upgrade_minor_version = False
# Set version to None to always get the latest version - user cannot override
version = None
logger.warning("Setting auto-upgrade-minor-version to False since release-train is '%s'", release_train)

return ExtensionInstanceUpdate(
auto_upgrade_minor_version=auto_upgrade_minor_version,
release_train=release_train,
version=version
)
2 changes: 1 addition & 1 deletion src/k8s-extension/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# TODO: Add any additional SDK dependencies here
DEPENDENCIES = []

VERSION = "0.3.1"
VERSION = "0.4.0"

with open('README.rst', 'r', encoding='utf-8') as f:
README = f.read()
Expand Down

0 comments on commit 459a2fb

Please sign in to comment.