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

[k8s-configuration] Adding k8s-configuration extension, Deprecating k8sconfiguration #2999

Merged
merged 43 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6f9c044
Push updates to k8sconfiguration keys and fix issue with known hosts
jonathan-innis Nov 23, 2020
b24dd9c
Remove print statement
jonathan-innis Nov 23, 2020
867e0d2
Increase CLI version and add to changelog
jonathan-innis Nov 25, 2020
7cf2ca2
Remove deprecated CLIError and reduce history.rst text
Nov 29, 2020
b9ef423
Joinnis/add validators (#1)
jonathan-innis Dec 4, 2020
a2b8c1b
Merge branch 'master' of github.com:jonathan-innis/azure-cli-extensions
jonathan-innis Dec 4, 2020
de54467
Remove dots from the regex for naming
jonathan-innis Dec 4, 2020
e85b6ea
Add the scenario tests back
jonathan-innis Dec 4, 2020
944b620
Add good key scenario test to scenarios
jonathan-innis Dec 4, 2020
e507608
Remove numeric checks for configurations
jonathan-innis Dec 5, 2020
6dde7d6
Reduce scneario testing
jonathan-innis Dec 7, 2020
47ab31e
Merge branch 'master' of https://github.com/jonathan-innis/azure-cli-…
jonathan-innis Dec 29, 2020
4d6ed8f
Merge branch 'master' of github.com:Azure/azure-cli-extensions into m…
jonathan-innis Dec 29, 2020
9ec9f9d
Move validation of configuration name into creation command
jonathan-innis Dec 29, 2020
e361a52
Add table formatting for list and show
jonathan-innis Dec 30, 2020
393c2e2
Update version
jonathan-innis Dec 30, 2020
b26eded
Update the error message for validation failure
jonathan-innis Dec 30, 2020
63cf182
Update the test cases for the new error messages
jonathan-innis Dec 30, 2020
4d09d53
Change error message and regex check
jonathan-innis Jan 6, 2021
a246002
Add proper formatting to code files
jonathan-innis Jan 6, 2021
a2bebf4
Updated final formatting checks
jonathan-innis Jan 6, 2021
b6d4c36
Updated error messages
jonathan-innis Jan 6, 2021
abcad8f
Update error message and help text
jonathan-innis Jan 6, 2021
1006398
Final update to error messaging
jonathan-innis Jan 6, 2021
c302cc2
Merge branch 'master' of github.com:Azure/azure-cli-extensions into m…
jonathan-innis Jan 6, 2021
6e27f78
Merge branch 'master' of github.com:Azure/azure-cli-extensions into m…
jonathan-innis Jan 7, 2021
a66106b
Update test_validators.py
jonathan-innis Jan 11, 2021
d46ce16
Update based on PR comments
jonathan-innis Jan 13, 2021
4f35f64
Merge branch 'master' of https://github.com/Azure/azure-cli-extensions
jonathan-innis Jan 20, 2021
f82b372
Helm Chart Version Parameter Naming Change (#2)
jonathan-innis Feb 5, 2021
5f871ed
Update Python SDKs (#3)
jonathan-innis Feb 5, 2021
6d68a8e
Merge branch 'master' of https://github.com/Azure/azure-cli-extensions
jonathan-innis Feb 5, 2021
b299a44
Merge branch 'master' of github.com:jonathan-innis/azure-cli-extensions
jonathan-innis Feb 5, 2021
06e68b1
Update with latest SDKs
jonathan-innis Feb 5, 2021
6e4e2cc
Change command name from k8sconfiguration to k8s-configuration
jonathan-innis Feb 10, 2021
4cc1157
Merge branch 'master' of https://github.com/Azure/azure-cli-extensions
jonathan-innis Feb 10, 2021
7fcbd25
Adding back k8sconfiguration extension
jonathan-innis Feb 10, 2021
7f62b4a
Update package data location
jonathan-innis Feb 10, 2021
042b714
Removing the ability for users to update their SCCs
jonathan-innis Feb 13, 2021
5e48343
Pin cryptography version
jonathan-innis Feb 18, 2021
26fa17d
Merge branch 'master' of https://github.com/Azure/azure-cli-extensions
jonathan-innis Feb 18, 2021
c074934
Update extension metadata
jonathan-innis Feb 18, 2021
a638155
Remove unneeded dependencies and support from python2
jonathan-innis Feb 19, 2021
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@

/src/k8sconfiguration/ @NarayanThiru

/src/k8s-configuration/ @NarayanThiru

/src/log-analytics-solution/ @zhoxing-ms

/src/kusto/ @ilayr @orhasban @astauben
Expand Down
10 changes: 10 additions & 0 deletions src/k8s-configuration/HISTORY.rst
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
74 changes: 74 additions & 0 deletions src/k8s-configuration/README.rst
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.
32 changes: 32 additions & 0 deletions src/k8s-configuration/azext_k8s_configuration/__init__.py
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 src/k8s-configuration/azext_k8s_configuration/_client_factory.py
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
25 changes: 25 additions & 0 deletions src/k8s-configuration/azext_k8s_configuration/_format.py
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'])
])
70 changes: 70 additions & 0 deletions src/k8s-configuration/azext_k8s_configuration/_help.py
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'
"""
88 changes: 88 additions & 0 deletions src/k8s-configuration/azext_k8s_configuration/_params.py
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 src/k8s-configuration/azext_k8s_configuration/_validators.py
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))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"azext.minCliCoreVersion": "2.15.0"
}
Loading