Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3cc8452
Kubernetes Data Protection Extension CLI (#173)
Miraj50 Aug 25, 2022
6c56613
{AKS - ARC} fix: Update DCR creation to Clusters resource group inste…
bragi92 Sep 28, 2022
083ed6d
Add self-signed cert to fix PR gate for azureml extension
Sep 27, 2022
0a6208d
adding the api version to the operation definition in the client factory
Sep 29, 2022
2121a2e
Merge pull request #181 from AzureArcForKubernetes/deesharma/exttypes
deeksha345 Sep 29, 2022
9c6835c
bump k8s-extension version to 1.3.6
Sep 29, 2022
1aaef92
Merge pull request #182 from AzureArcForKubernetes/release-1.3.6
deeksha345 Sep 29, 2022
700bee5
adding tests for all 4 extension types calls
Sep 30, 2022
efd86d4
adding to test config file
Sep 30, 2022
8dcef49
updating the api version for extension types to be the correct versio…
Sep 30, 2022
2ecb63a
add test case for flux extension (#184)
bavneetsingh16 Oct 3, 2022
f1c9348
Merge branch 'k8s-extension/public' into deesharma/exttypestests
deeksha345 Oct 5, 2022
5c57791
Merge pull request #183 from AzureArcForKubernetes/deesharma/exttypes…
deeksha345 Oct 5, 2022
84dcc92
Merge branch 'main' of https://github.com/Azure/azure-cli-extensions …
Oct 5, 2022
4ae3aa6
bump k8s-extension version to 1.3.6
Oct 5, 2022
0213a71
bump k8s-extension version to 1.3.6
Oct 6, 2022
a2a8be4
Merge pull request #186 from AzureArcForKubernetes/release-1.3.6
deeksha345 Oct 6, 2022
ef3e79f
adding upstream test for extension types
Oct 17, 2022
eeadb2b
Merge pull request #189 from AzureArcForKubernetes/deesharma/addingex…
deeksha345 Oct 17, 2022
0378ecf
Merge branch 'main' of https://github.com/Azure/azure-cli-extensions …
Oct 17, 2022
929928f
updating history.rst
Oct 17, 2022
374edcf
Merge pull request #190 from AzureArcForKubernetes/release-1.3.6
deeksha345 Oct 18, 2022
5b6b4dc
Merge branch 'main' of https://github.com/Azure/azure-cli-extensions …
Oct 18, 2022
e95cd6e
Merge branch 'k8s-extension/public' into release-1.3.6
Oct 18, 2022
477613d
Merge pull request #191 from AzureArcForKubernetes/release-1.3.6
deeksha345 Oct 18, 2022
cbd30bf
[Dapr] Prompt user for existing Dapr installation during extension cr…
shubham1172 Nov 10, 2022
5d8592e
Merge branch 'main' of github.com:Azure/azure-cli-extensions into rel…
Nov 15, 2022
155fb01
bump k8s-extension version to 1.3.7
Nov 15, 2022
0d74a15
Merge branch 'main' of github.com:Azure/azure-cli-extensions into rel…
Nov 16, 2022
c88e8ef
Merge branch 'main' of github.com:Azure/azure-cli-extensions into rel…
Nov 18, 2022
464cca7
Merge pull request #196 from AzureArcForKubernetes/release-1.3.7
bavneetsingh16 Nov 18, 2022
705ea0a
remove unnecessary test files
Nov 18, 2022
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
4 changes: 4 additions & 0 deletions src/k8s-extension/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

1.3.7
++++++++++++++++++
* microsoft.dapr: prompt user for existing dapr installation during extension create

1.3.6
++++++++++++++++++
* Update the api version and add tests for extension type calls
Expand Down
128 changes: 114 additions & 14 deletions src/k8s-extension/azext_k8s_extension/partner_extensions/Dapr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,143 @@
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument
# pylint: disable=line-too-long
# pylint: disable=too-many-locals
# pylint: disable=too-many-instance-attributes

from typing import Tuple

from azure.cli.core.azclierror import InvalidArgumentValueError
from knack.log import get_logger
from knack.prompting import prompt, prompt_y_n

from ..vendored_sdks.models import Extension, Scope, ScopeCluster
from .DefaultExtension import DefaultExtension

from ..vendored_sdks.models import (
Extension,
)
logger = get_logger(__name__)


class Dapr(DefaultExtension):
def __init__(self):
self.TSG_LINK = "https://docs.microsoft.com/en-us/azure/aks/dapr"
self.DEFAULT_RELEASE_NAME = 'dapr'
self.DEFAULT_RELEASE_NAMESPACE = 'dapr-system'
self.DEFAULT_RELEASE_TRAIN = 'stable'
self.DEFAULT_CLUSTER_TYPE = 'managedclusters'
self.DEFAULT_HA = 'true'

# constants for configuration settings.
self.CLUSTER_TYPE = 'global.clusterType'
self.CLUSTER_TYPE_KEY = 'global.clusterType'
self.HA_KEY_ENABLED_KEY = 'global.ha.enabled'
self.SKIP_EXISTING_DAPR_CHECK_KEY = 'skipExistingDaprCheck'
self.EXISTING_DAPR_RELEASE_NAME_KEY = 'existingDaprReleaseName'
self.EXISTING_DAPR_RELEASE_NAMESPACE_KEY = 'existingDaprReleaseNamespace'

# constants for message prompts.
self.MSG_IS_DAPR_INSTALLED = "Is Dapr already installed in the cluster?"
self.MSG_ENTER_RELEASE_NAME = "Enter the Helm release name for Dapr, "\
f"or press Enter to use the default name [{self.DEFAULT_RELEASE_NAME}]: "
self.MSG_ENTER_RELEASE_NAMESPACE = "Enter the namespace where Dapr is installed, "\
f"or press Enter to use the default namespace [{self.DEFAULT_RELEASE_NAMESPACE}]: "
self.MSG_WARN_EXISTING_INSTALLATION = "The extension will use your existing Dapr installation. "\
f"Note, if you have updated the default values for global.ha.* or dapr_placement.* in your existing "\
"Dapr installation, you must provide them via --configuration-settings. Failing to do so will result in"\
"an error, since Helm upgrade will try to modify the StatefulSet."\
f"Please refer to {self.TSG_LINK} for more information."

self.RELEASE_INFO_HELP_STRING = "The Helm release name and namespace can be found by running 'helm list -A'."

# constants for error messages.
self.ERR_MSG_INVALID_SCOPE_TPL = "Invalid scope '{}'. This extension can be installed only at 'cluster' scope."\
f" Check {self.TSG_LINK} for more information."

def _get_release_info(self, release_name: str, release_namespace: str, configuration_settings: dict)\
-> Tuple[str, str, bool]:
'''
Check if Dapr is already installed in the cluster and get the release name and namespace.
If user has provided the release name and namespace in configuration settings, use those.
Otherwise, prompt the user for the release name and namespace.
If Dapr is not installed, return the default release name and namespace.
'''
name, namespace, dapr_exists = release_name, release_namespace, False

# Set the default release name and namespace if not provided.
name = name or self.DEFAULT_RELEASE_NAME
namespace = namespace or self.DEFAULT_RELEASE_NAMESPACE

if configuration_settings.get(self.SKIP_EXISTING_DAPR_CHECK_KEY, 'false') == 'true':
logger.info("%s is set to true, skipping existing Dapr check.", self.SKIP_EXISTING_DAPR_CHECK_KEY)
return name, namespace, False

cfg_name = configuration_settings.get(self.EXISTING_DAPR_RELEASE_NAME_KEY, None)
cfg_namespace = configuration_settings.get(self.EXISTING_DAPR_RELEASE_NAMESPACE_KEY, None)

def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, cluster_rp,
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):
# If the user has specified the release name and namespace in configuration settings, then use it.
if cfg_name and cfg_namespace:
logger.info("Using the release name and namespace specified in the configuration settings.")
return cfg_name, cfg_namespace, True

# If either release name or namespace is missing, ignore the configuration settings and prompt the user.
if cfg_name or cfg_namespace:
logger.warning("Both '%s' and '%s' must be specified via --configuration-settings. Only one of them is "
"specified, ignoring.", self.EXISTING_DAPR_RELEASE_NAME_KEY,
self.EXISTING_DAPR_RELEASE_NAMESPACE_KEY)

# Check explictly if Dapr is already installed in the cluster.
# If so, reuse the release name and namespace to avoid conflicts.
if prompt_y_n(self.MSG_IS_DAPR_INSTALLED, default='n'):
dapr_exists = True

name = prompt(self.MSG_ENTER_RELEASE_NAME, self.RELEASE_INFO_HELP_STRING) or self.DEFAULT_RELEASE_NAME
if release_name and name != release_name:
logger.warning("The release name has been changed from '%s' to '%s'.", release_name, name)

namespace = prompt(self.MSG_ENTER_RELEASE_NAMESPACE, self.RELEASE_INFO_HELP_STRING)\
or self.DEFAULT_RELEASE_NAMESPACE
if release_namespace and namespace != release_namespace:
logger.warning("The release namespace has been changed from '%s' to '%s'.",
release_namespace, namespace)

return name, namespace, dapr_exists

def Create(self, cmd, client, resource_group_name: str, cluster_name: str, name: str, cluster_type: str,
cluster_rp: str, extension_type: str, scope: str, auto_upgrade_minor_version: bool,
release_train: str, version: str, target_namespace: str, release_namespace: str,
configuration_settings: dict, configuration_protected_settings: dict,
configuration_settings_file: str, configuration_protected_settings_file: str):
"""ExtensionType 'Microsoft.Dapr' specific validations & defaults for Create
Must create and return a valid 'ExtensionInstance' object.
"""

if cluster_type.lower() == '' or cluster_type.lower() == 'managedclusters':
configuration_settings[self.CLUSTER_TYPE] = 'managedclusters'
# Dapr extension is only supported at the cluster scope.
if scope == 'namespace':
raise InvalidArgumentValueError(self.ERR_MSG_INVALID_SCOPE_TPL.format(scope))

release_name, release_namespace, dapr_exists = \
self._get_release_info(name, release_namespace, configuration_settings)

# Inform the user that the extension will be installed on an existing Dapr installation.
# Disable HA mode if Dapr is already installed in the cluster.
if dapr_exists:
logger.warning(self.MSG_WARN_EXISTING_INSTALLATION)
if self.HA_KEY_ENABLED_KEY not in configuration_settings:
configuration_settings[self.HA_KEY_ENABLED_KEY] = 'false'

scope_cluster = ScopeCluster(release_namespace=release_namespace or self.DEFAULT_RELEASE_NAMESPACE)
extension_scope = Scope(cluster=scope_cluster, namespace=None)

if cluster_type.lower() == '' or cluster_type.lower() == self.DEFAULT_CLUSTER_TYPE:
configuration_settings[self.CLUSTER_TYPE_KEY] = self.DEFAULT_CLUSTER_TYPE

create_identity = False
extension_instance = Extension(
extension_type=extension_type,
auto_upgrade_minor_version=auto_upgrade_minor_version,
release_train=release_train,
release_train=release_train or self.DEFAULT_RELEASE_TRAIN,
version=version,
scope=scope,
scope=extension_scope,
configuration_settings=configuration_settings,
configuration_protected_settings=configuration_protected_settings,
identity=None,
location=""
)
return extension_instance, name, create_identity
return extension_instance, release_name, create_identity
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_k8s_extension(self):

self.cmd('k8s-extension create -g {rg} -n {name} -c {cluster_name} --cluster-type {cluster_type} '
'--extension-type {extension_type} --release-train {release_train} --version {version} '
'--no-wait')
'--configuration-settings "skipExistingDaprCheck=true" --no-wait')

# Update requires agent running in k8s cluster that is connected to Azure - so no update tests here
# self.cmd('k8s-extension update -g {rg} -n {name} --tags foo=boo', checks=[
Expand Down
2 changes: 1 addition & 1 deletion src/k8s-extension/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# TODO: Add any additional SDK dependencies here
DEPENDENCIES = []

VERSION = "1.3.6"
VERSION = "1.3.7"

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