-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[k8s-configuration] Adding k8s-configuration extension, Deprecating k…
…8sconfiguration (#2999)
- Loading branch information
1 parent
19b4eaa
commit 8910046
Showing
36 changed files
with
3,480 additions
and
45 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.. :changelog: | ||
Release History | ||
=============== | ||
|
||
1.0.0 | ||
++++++++++++++++++ | ||
* Support api-version 2021-03-01 | ||
* Update helm operator parameter aliases | ||
* Migrate from k8sconfiguration to k8s-configuration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
Microsoft Azure CLI 'k8s-configuration' Extension | ||
========================================== | ||
|
||
This package is for the 'k8s-configuration' extension. | ||
i.e. 'az k8s-configuration' | ||
|
||
### How to use ### | ||
Install this extension using the below CLI command | ||
``` | ||
az extension add --name k8s-configuration | ||
``` | ||
|
||
### Included Features | ||
#### Kubernetes Configuration: | ||
Kubernetes SourceControl Configuration: [more info](https://docs.microsoft.com/en-us/azure/kubernetessconfiguration/)\ | ||
*Examples:* | ||
|
||
##### Create a KubernetesConfiguration | ||
``` | ||
az k8s-configuration create \ | ||
--resource-group groupName \ | ||
--cluster-name clusterName \ | ||
--cluster-type clusterType \ | ||
--name configurationName \ | ||
--operator-instance-name operatorInstanceName \ | ||
--operator-namespace operatorNamespace \ | ||
--repository-url githubRepoUrl \ | ||
--operator-params operatorParameters \ | ||
--enable-helm-operator \ | ||
--helm-operator-version chartVersion \ | ||
--helm-operator-params chartParameters | ||
``` | ||
|
||
##### Get a KubernetesConfiguration | ||
``` | ||
az k8s-configuration show \ | ||
--resource-group groupName \ | ||
--cluster-name clusterName \ | ||
--cluster-type clusterType \ | ||
--name configurationName | ||
``` | ||
|
||
##### Delete a KubernetesConfiguration | ||
``` | ||
az k8s-configuration delete \ | ||
--resource-group groupName \ | ||
--cluster-name clusterName \ | ||
--cluster-type clusterType \ | ||
--name configurationName | ||
``` | ||
|
||
##### Update a KubernetesConfiguration | ||
``` | ||
az k8s-configuration create \ | ||
--resource-group groupName \ | ||
--cluster-name clusterName \ | ||
--cluster-type clusterType \ | ||
--name configurationName \ | ||
--repository-url githubRepoUrl \ | ||
--operator-params operatorParameters \ | ||
--enable-helm-operator \ | ||
--helm-operator-version chartVersion \ | ||
--helm-operator-params chartParameters | ||
``` | ||
|
||
##### List all KubernetesConfigurations of a cluster | ||
``` | ||
az k8s-configuration list \ | ||
--resource-group groupName \ | ||
--cluster-name clusterName \ | ||
--cluster-type clusterType | ||
``` | ||
|
||
If you have issues, please give feedback by opening an issue at https://github.com/Azure/azure-cli-extensions/issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from azure.cli.core import AzCommandsLoader | ||
|
||
from azext_k8s_configuration._help import helps # pylint: disable=unused-import | ||
|
||
|
||
class K8sConfigurationCommandsLoader(AzCommandsLoader): | ||
|
||
def __init__(self, cli_ctx=None): | ||
from azure.cli.core.commands import CliCommandType | ||
from azext_k8s_configuration._client_factory import cf_k8s_configuration | ||
k8s_configuration_custom = CliCommandType( | ||
operations_tmpl='azext_k8s_configuration.custom#{}', | ||
client_factory=cf_k8s_configuration) | ||
super(K8sConfigurationCommandsLoader, self).__init__(cli_ctx=cli_ctx, | ||
custom_command_type=k8s_configuration_custom) | ||
|
||
def load_command_table(self, args): | ||
from azext_k8s_configuration.commands import load_command_table | ||
load_command_table(self, args) | ||
return self.command_table | ||
|
||
def load_arguments(self, command): | ||
from azext_k8s_configuration._params import load_arguments | ||
load_arguments(self, command) | ||
|
||
|
||
COMMAND_LOADER_CLS = K8sConfigurationCommandsLoader |
15 changes: 15 additions & 0 deletions
15
src/k8s-configuration/azext_k8s_configuration/_client_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
|
||
def cf_k8s_configuration(cli_ctx, *_): | ||
|
||
from azure.cli.core.commands.client_factory import get_mgmt_service_client | ||
from azext_k8s_configuration.vendored_sdks import SourceControlConfigurationClient | ||
return get_mgmt_service_client(cli_ctx, SourceControlConfigurationClient) | ||
|
||
|
||
def cf_k8s_configuration_operation(cli_ctx, _): | ||
return cf_k8s_configuration(cli_ctx).source_control_configurations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from collections import OrderedDict | ||
|
||
|
||
def k8s_configuration_list_table_format(results): | ||
return [__get_table_row(result) for result in results] | ||
|
||
|
||
def k8s_configuration_show_table_format(result): | ||
return __get_table_row(result) | ||
|
||
|
||
def __get_table_row(result): | ||
return OrderedDict([ | ||
('name', result['name']), | ||
('repositoryUrl', result['repositoryUrl']), | ||
('operatorName', result['operatorInstanceName']), | ||
('operatorNamespace', result['operatorNamespace']), | ||
('scope', result['operatorScope']), | ||
('provisioningState', result['provisioningState']) | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from knack.help_files import helps # pylint: disable=unused-import | ||
|
||
|
||
helps['k8s-configuration'] = """ | ||
type: group | ||
short-summary: Commands to manage Kubernetes configuration. | ||
""" | ||
|
||
helps['k8s-configuration create'] = """ | ||
type: command | ||
short-summary: Create a Kubernetes configuration. | ||
examples: | ||
- name: Create a Kubernetes configuration | ||
text: |- | ||
az k8s-configuration create --resource-group MyResourceGroup --cluster-name MyClusterName \\ | ||
--cluster-type connectedClusters --name MyGitConfig --operator-instance-name OperatorInst01 \\ | ||
--operator-namespace OperatorNamespace01 --operator-type flux --operator-params "'--git-readonly'" \\ | ||
--repository-url git://github.com/fluxHowTo/flux-get-started --enable-helm-operator \\ | ||
--helm-operator-chart-version 1.2.0 --scope namespace --helm-operator-params '--set helm.versions=v3' \\ | ||
--ssh-private-key '' --ssh-private-key-file '' --https-user '' --https-key '' \\ | ||
--ssh-known-hosts '' --ssh-known-hosts-file '' | ||
""" | ||
|
||
helps['k8s-configuration list'] = """ | ||
type: command | ||
short-summary: List Kubernetes configurations. | ||
examples: | ||
- name: List all Kubernetes configurations of a cluster | ||
text: |- | ||
az k8s-configuration list --resource-group MyResourceGroup --cluster-name MyClusterName \\ | ||
--cluster-type connectedClusters | ||
""" | ||
|
||
helps['k8s-configuration delete'] = """ | ||
type: command | ||
short-summary: Delete a Kubernetes configuration. | ||
examples: | ||
- name: Delete a Kubernetes configuration | ||
text: |- | ||
az k8s-configuration delete --resource-group MyResourceGroup --cluster-name MyClusterName \\ | ||
--cluster-type connectedClusters --name MyConfigurationName | ||
""" | ||
|
||
helps['k8s-configuration show'] = """ | ||
type: command | ||
short-summary: Show details of a Kubernetes configuration. | ||
examples: | ||
- name: Show a Kubernetes configuration | ||
text: |- | ||
az k8s-configuration show --resource-group MyResourceGroup --cluster-name MyClusterName \\ | ||
--cluster-type connectedClusters --name MyConfigurationName | ||
""" | ||
|
||
helps['k8s-configuration update'] = """ | ||
type: command | ||
short-summary: Update a Kubernetes configuration. | ||
examples: | ||
- name: Update an existing Kubernetes configuration | ||
text: |- | ||
az k8s-configuration update --resource-group MyResourceGroup --cluster-name MyClusterName \\ | ||
--cluster-type connectedClusters --name MyConfigurationName --enable-helm-operator \\ | ||
--repository-url git://github.com/fluxHowTo/flux-get-started --operator-params "'--git-readonly'" \\ | ||
--helm-operator-chart-version 1.2.0 --helm-operator-params '--set helm.versions=v3' | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
# pylint: disable=line-too-long | ||
|
||
from knack.arguments import CLIArgumentType | ||
|
||
from azure.cli.core.commands.parameters import ( | ||
get_three_state_flag, | ||
get_enum_type, | ||
tags_type | ||
) | ||
|
||
from azure.cli.core.commands.validators import get_default_location_from_resource_group | ||
from ._validators import validate_configuration_type, validate_operator_namespace, validate_operator_instance_name | ||
|
||
|
||
def load_arguments(self, _): | ||
sourcecontrolconfiguration_type = CLIArgumentType(help='Name of the Kubernetes Configuration') | ||
|
||
with self.argument_context('k8s-configuration') as c: | ||
c.argument('tags', tags_type) | ||
c.argument('location', | ||
validator=get_default_location_from_resource_group) | ||
c.argument('name', sourcecontrolconfiguration_type, | ||
options_list=['--name', '-n']) | ||
c.argument('cluster_name', | ||
options_list=['--cluster-name', '-c'], | ||
help='Name of the Kubernetes cluster') | ||
c.argument('cluster_type', | ||
arg_type=get_enum_type(['connectedClusters', 'managedClusters']), | ||
help='Specify Arc clusters or AKS managed clusters.') | ||
c.argument('repository_url', | ||
options_list=['--repository-url', '-u'], | ||
help='Url of the source control repository') | ||
c.argument('scope', | ||
arg_type=get_enum_type(['namespace', 'cluster']), | ||
help='''Specify scope of the operator to be 'namespace' or 'cluster' ''') | ||
c.argument('configuration_type', | ||
validator=validate_configuration_type, | ||
arg_type=get_enum_type(['sourceControlConfiguration']), | ||
help='Type of the configuration') | ||
c.argument('enable_helm_operator', | ||
arg_group="Helm Operator", | ||
arg_type=get_three_state_flag(), | ||
options_list=['--enable-helm-operator', '--enable-hop'], | ||
help='Enable support for Helm chart deployments') | ||
c.argument('helm_operator_params', | ||
arg_group="Helm Operator", | ||
options_list=['--helm-operator-params', '--hop-params'], | ||
help='Chart values for the Helm Operator (if enabled)') | ||
c.argument('helm_operator_chart_version', | ||
arg_group="Helm Operator", | ||
options_list=['--helm-operator-chart-version', '--hop-chart-version'], | ||
help='Chart version of the Helm Operator (if enabled)') | ||
c.argument('operator_params', | ||
arg_group="Operator", | ||
help='Parameters for the Operator') | ||
c.argument('operator_instance_name', | ||
arg_group="Operator", | ||
help='Instance name of the Operator', | ||
validator=validate_operator_instance_name) | ||
c.argument('operator_namespace', | ||
arg_group="Operator", | ||
help='Namespace in which to install the Operator', | ||
validator=validate_operator_namespace) | ||
c.argument('operator_type', | ||
arg_group="Operator", | ||
help='''Type of the operator. Valid value is 'flux' ''') | ||
c.argument('ssh_private_key', | ||
arg_group="Auth", | ||
help='Specify Base64-encoded private ssh key for private repository sync') | ||
c.argument('ssh_private_key_file', | ||
arg_group="Auth", | ||
help='Specify filepath to private ssh key for private repository sync') | ||
c.argument('https_user', | ||
arg_group="Auth", | ||
help='Specify HTTPS username for private repository sync') | ||
c.argument('https_key', | ||
arg_group="Auth", | ||
help='Specify HTTPS token/password for private repository sync') | ||
c.argument('ssh_known_hosts', | ||
arg_group="Auth", | ||
help='Specify Base64-encoded known_hosts contents containing public SSH keys required to access private Git instances') | ||
c.argument('ssh_known_hosts_file', | ||
arg_group="Auth", | ||
help='Specify filepath to known_hosts contents containing public SSH keys required to access private Git instances') |
46 changes: 46 additions & 0 deletions
46
src/k8s-configuration/azext_k8s_configuration/_validators.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
import re | ||
from azure.cli.core.azclierror import InvalidArgumentValueError | ||
|
||
|
||
# Parameter-Level Validation | ||
def validate_configuration_type(configuration_type): | ||
if configuration_type.lower() != 'sourcecontrolconfiguration': | ||
raise InvalidArgumentValueError( | ||
'Invalid configuration-type', | ||
'Try specifying the valid value "sourceControlConfiguration"') | ||
|
||
|
||
def validate_operator_namespace(namespace): | ||
if namespace.operator_namespace: | ||
__validate_k8s_name(namespace.operator_namespace, "--operator-namespace", 23) | ||
|
||
|
||
def validate_operator_instance_name(namespace): | ||
if namespace.operator_instance_name: | ||
__validate_k8s_name(namespace.operator_instance_name, "--operator-instance-name", 23) | ||
|
||
|
||
# Create Parameter Validation | ||
def validate_configuration_name(configuration_name): | ||
__validate_k8s_name(configuration_name, "--name", 63) | ||
|
||
|
||
# Helper | ||
def __validate_k8s_name(param_value, param_name, max_len): | ||
if len(param_value) > max_len: | ||
raise InvalidArgumentValueError( | ||
'Error! Invalid {0}'.format(param_name), | ||
'Parameter {0} can be a maximum of {1} characters'.format(param_name, max_len)) | ||
if not re.match(r'^[a-z0-9]([-a-z0-9]*[a-z0-9])?$', param_value): | ||
if param_value[0] == "-" or param_value[-1] == "-": | ||
raise InvalidArgumentValueError( | ||
'Error! Invalid {0}'.format(param_name), | ||
'Parameter {0} cannot begin or end with a hyphen'.format(param_name)) | ||
raise InvalidArgumentValueError( | ||
'Error! Invalid {0}'.format(param_name), | ||
'Parameter {0} can only contain lowercase alphanumeric characters and hyphens'.format(param_name)) |
3 changes: 3 additions & 0 deletions
3
src/k8s-configuration/azext_k8s_configuration/azext_metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"azext.minCliCoreVersion": "2.15.0" | ||
} |
Oops, something went wrong.