From 61677567e3c71611045d76e42851b342cd84f2f5 Mon Sep 17 00:00:00 2001 From: jonathan-innis Date: Thu, 13 May 2021 10:41:10 -0700 Subject: [PATCH 1/6] Add OSM as public preview extension --- src/k8s-extension/HISTORY.rst | 5 + .../azext_k8s_extension/custom.py | 2 + .../partner_extensions/OpenServiceMesh.py | 95 +++++++++++++++++++ src/k8s-extension/setup.py | 2 +- 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 src/k8s-extension/azext_k8s_extension/partner_extensions/OpenServiceMesh.py diff --git a/src/k8s-extension/HISTORY.rst b/src/k8s-extension/HISTORY.rst index 02562364f13..75f127f4afd 100644 --- a/src/k8s-extension/HISTORY.rst +++ b/src/k8s-extension/HISTORY.rst @@ -3,6 +3,11 @@ Release History =============== +0.4.0 +++++++++++++++++++ + +* Release customization for microsoft.openservicemesh + 0.3.1 ++++++++++++++++++ diff --git a/src/k8s-extension/azext_k8s_extension/custom.py b/src/k8s-extension/azext_k8s_extension/custom.py index 30971ba265a..f4f2e1cafdd 100644 --- a/src/k8s-extension/azext_k8s_extension/custom.py +++ b/src/k8s-extension/azext_k8s_extension/custom.py @@ -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 @@ -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, } diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/OpenServiceMesh.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/OpenServiceMesh.py new file mode 100644 index 00000000000..0cbc799ffa4 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/OpenServiceMesh.py @@ -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 + ) diff --git a/src/k8s-extension/setup.py b/src/k8s-extension/setup.py index b3512c976db..64819fc940a 100644 --- a/src/k8s-extension/setup.py +++ b/src/k8s-extension/setup.py @@ -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() From 6d45c21bd1a57c8e8c6588990ec6be1c84134f09 Mon Sep 17 00:00:00 2001 From: jonathan-innis Date: Thu, 13 May 2021 10:49:51 -0700 Subject: [PATCH 2/6] Add osm testing --- .../public/OpenServiceMesh.Tests.ps1 | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 testing/test/extensions/public/OpenServiceMesh.Tests.ps1 diff --git a/testing/test/extensions/public/OpenServiceMesh.Tests.ps1 b/testing/test/extensions/public/OpenServiceMesh.Tests.ps1 new file mode 100644 index 00000000000..0ed3c30840e --- /dev/null +++ b/testing/test/extensions/public/OpenServiceMesh.Tests.ps1 @@ -0,0 +1,93 @@ +Describe 'Azure OpenServiceMesh Testing' { + BeforeAll { + $extensionType = "microsoft.openservicemesh" + $extensionName = "openservicemesh" + $extensionAgentNamespace = "azuredefender" + + . $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 + $? | 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 "True" | Should -BeTrue + + # Loop and retry until the extension installs + $n = 0 + do + { + # Only check the extension config, not the pod since this doesn't bring up pods + if (Get-ExtensionStatus $extensionName -eq $SUCCESS_MESSAGE) { + 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 + } +} From d6cdc76251627b1b0b81a178f45c06deafc79f4b Mon Sep 17 00:00:00 2001 From: jonathan-innis Date: Thu, 13 May 2021 13:06:11 -0700 Subject: [PATCH 3/6] Add release train to tests --- testing/test/extensions/public/OpenServiceMesh.Tests.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testing/test/extensions/public/OpenServiceMesh.Tests.ps1 b/testing/test/extensions/public/OpenServiceMesh.Tests.ps1 index 0ed3c30840e..139691748ab 100644 --- a/testing/test/extensions/public/OpenServiceMesh.Tests.ps1 +++ b/testing/test/extensions/public/OpenServiceMesh.Tests.ps1 @@ -3,13 +3,14 @@ Describe 'Azure OpenServiceMesh Testing' { $extensionType = "microsoft.openservicemesh" $extensionName = "openservicemesh" $extensionAgentNamespace = "azuredefender" + $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 + $output = az $Env:K8sExtensionName create -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters --extension-type $extensionType -n $extensionName --release-train $releaseTrain $? | Should -BeTrue $output = az $Env:K8sExtensionName show -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName From 49be9fdf100c2b2f9a30c7c86f46ad550b2273b1 Mon Sep 17 00:00:00 2001 From: jonathan-innis Date: Thu, 13 May 2021 13:54:15 -0700 Subject: [PATCH 4/6] Fix failing osm test --- .../extensions/public/OpenServiceMesh.Tests.ps1 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/testing/test/extensions/public/OpenServiceMesh.Tests.ps1 b/testing/test/extensions/public/OpenServiceMesh.Tests.ps1 index 139691748ab..2d3d549529a 100644 --- a/testing/test/extensions/public/OpenServiceMesh.Tests.ps1 +++ b/testing/test/extensions/public/OpenServiceMesh.Tests.ps1 @@ -2,7 +2,9 @@ Describe 'Azure OpenServiceMesh Testing' { BeforeAll { $extensionType = "microsoft.openservicemesh" $extensionName = "openservicemesh" - $extensionAgentNamespace = "azuredefender" + $extensionVersion = "0.8.3" + $extensionAgentName = "osm-controller" + $extensionAgentNamespace = "arc-osm-system" $releaseTrain = "pilot" . $PSScriptRoot/../../helper/Constants.ps1 @@ -10,22 +12,23 @@ Describe 'Azure OpenServiceMesh Testing' { } 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 + $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 "True" | Should -BeTrue + $isAutoUpgradeMinorVersion.ToString() -eq "False" | Should -BeTrue # Loop and retry until the extension installs $n = 0 do { - # Only check the extension config, not the pod since this doesn't bring up pods if (Get-ExtensionStatus $extensionName -eq $SUCCESS_MESSAGE) { - break + if (Get-PodStatus $extensionAgentName -Namespace $extensionAgentNamespace -eq $POD_RUNNING) { + break + } } Start-Sleep -Seconds 10 $n += 1 From e1d9860b5d14074180fc4f5fb59c02680a9849ff Mon Sep 17 00:00:00 2001 From: jonathan-innis Date: Thu, 13 May 2021 14:08:21 -0700 Subject: [PATCH 5/6] Upgrade pip in integration testing --- k8s-custom-pipelines.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/k8s-custom-pipelines.yml b/k8s-custom-pipelines.yml index bca200cd7cc..2083500446f 100644 --- a/k8s-custom-pipelines.yml +++ b/k8s-custom-pipelines.yml @@ -292,7 +292,9 @@ stages: displayName: 'Use Python $(python.version)' inputs: versionSpec: '$(python.version)' - - bash: pip install wheel==0.30.0 + - bash: | + pip install --upgrade pip + pip install wheel==0.30.0 displayName: 'Install wheel==0.30.0' - bash: ./scripts/ci/test_source.sh displayName: 'Run integration test and build test' From 9fab8c6fad80fc1b91e524718d696c1040aa9a51 Mon Sep 17 00:00:00 2001 From: jonathan-innis Date: Thu, 13 May 2021 14:33:17 -0700 Subject: [PATCH 6/6] Remove ununsed import --- k8s-custom-pipelines.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/k8s-custom-pipelines.yml b/k8s-custom-pipelines.yml index 2083500446f..bca200cd7cc 100644 --- a/k8s-custom-pipelines.yml +++ b/k8s-custom-pipelines.yml @@ -292,9 +292,7 @@ stages: displayName: 'Use Python $(python.version)' inputs: versionSpec: '$(python.version)' - - bash: | - pip install --upgrade pip - pip install wheel==0.30.0 + - bash: pip install wheel==0.30.0 displayName: 'Install wheel==0.30.0' - bash: ./scripts/ci/test_source.sh displayName: 'Run integration test and build test'