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 OSM as Public Preview Extension #34

Merged
merged 8 commits into from
May 13, 2021
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
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
2 changes: 2 additions & 0 deletions src/k8s-extension/azext_k8s_extension/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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
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
97 changes: 97 additions & 0 deletions testing/test/extensions/public/OpenServiceMesh.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
Describe 'Azure OpenServiceMesh Testing' {
BeforeAll {
$extensionType = "microsoft.openservicemesh"
$extensionName = "openservicemesh"
$extensionVersion = "0.8.3"
$extensionAgentName = "osm-controller"
$extensionAgentNamespace = "arc-osm-system"
$releaseTrain = "pilot"

. $PSScriptRoot/../../helper/Constants.ps1
. $PSScriptRoot/../../helper/Helper.ps1
}

It 'Creates the extension and checks that it onboards correctly' {
$output = az $Env:K8sExtensionName create -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters --extension-type $extensionType -n $extensionName --release-train $releaseTrain --version $extensionVersion
$? | Should -BeTrue

$output = az $Env:K8sExtensionName show -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName
$? | Should -BeTrue

$isAutoUpgradeMinorVersion = ($output | ConvertFrom-Json).autoUpgradeMinorVersion
$isAutoUpgradeMinorVersion.ToString() -eq "False" | Should -BeTrue

# Loop and retry until the extension installs
$n = 0
do
{
if (Get-ExtensionStatus $extensionName -eq $SUCCESS_MESSAGE) {
if (Get-PodStatus $extensionAgentName -Namespace $extensionAgentNamespace -eq $POD_RUNNING) {
break
}
}
Start-Sleep -Seconds 10
$n += 1
} while ($n -le $MAX_RETRY_ATTEMPTS)
$n | Should -BeLessOrEqual $MAX_RETRY_ATTEMPTS
}

It "Performs a show on the extension" {
$output = az $Env:K8sExtensionName show -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName
$? | Should -BeTrue
$output | Should -Not -BeNullOrEmpty
}

It "Runs an update on the extension on the cluster" {
Set-ItResult -Skipped -Because "Update is not a valid scenario for now"

# az $Env:K8sExtensionName update -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName --auto-upgrade-minor-version false
# $? | Should -BeTrue

# $output = az $Env:K8sExtensionName show -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName
# $? | Should -BeTrue

# $isAutoUpgradeMinorVersion = ($output | ConvertFrom-Json).autoUpgradeMinorVersion
# $isAutoUpgradeMinorVersion.ToString() -eq "False" | Should -BeTrue

# # Loop and retry until the extension config updates
# $n = 0
# do
# {
# $isAutoUpgradeMinorVersion = (Get-ExtensionData $extensionName).spec.autoUpgradeMinorVersion
# if (!$isAutoUpgradeMinorVersion) { #autoUpgradeMinorVersion doesn't exist in ExtensionConfig CRD if false
# if (Get-ExtensionStatus $extensionName -eq $SUCCESS_MESSAGE) {
# if (Get-PodStatus $extensionAgentName -Namespace $extensionAgentNamespace -eq $POD_RUNNING) {
# break
# }
# }
# }
# Start-Sleep -Seconds 10
# $n += 1
# } while ($n -le $MAX_RETRY_ATTEMPTS)
# $n | Should -BeLessOrEqual $MAX_RETRY_ATTEMPTS
}

It "Lists the extensions on the cluster" {
$output = az $Env:K8sExtensionName list -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters
$? | Should -BeTrue

$extensionExists = $output | ConvertFrom-Json | Where-Object { $_.extensionType -eq $extensionType }
$extensionExists | Should -Not -BeNullOrEmpty
}

It "Deletes the extension from the cluster" {
az $Env:K8sExtensionName delete -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName
$? | Should -BeTrue

# Extension should not be found on the cluster
az $Env:K8sExtensionName show -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName
$? | Should -BeFalse
}

It "Performs another list after the delete" {
$output = az $Env:K8sExtensionName list -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters
$extensionExists = $output | ConvertFrom-Json | Where-Object { $_.extensionType -eq $extensionName }
$extensionExists | Should -BeNullOrEmpty
}
}