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

[KubernetesConfiguration] Add extension CLI #1550

Merged
merged 23 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@

/src/datashare/ @fengzhou-msft

/src/k8sconfiguration/ @NarayanThiru

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

/src/kusto/ @ilayr @orhasban @astauben
8 changes: 8 additions & 0 deletions src/k8sconfiguration/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:

Release History
===============

0.1.7
++++++
* Initial release (for Public Preview)
74 changes: 74 additions & 0 deletions src/k8sconfiguration/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
Microsoft Azure CLI 'k8sconfiguration' Extension
==========================================

This package is for the 'k8sconfiguration' extension.
i.e. 'az k8sconfiguration'

### How to use ###
Install this extension using the below CLI command
```
az extension add --name k8sconfiguration
```

### Included Features
#### Kubernetes Configuration:
Kubernetes SourceControl Configuration: [more info](https://docs.microsoft.com/en-us/azure/kubernetessconfiguration/)\
*Examples:*

##### Create a KubernetesConfiguration
```
az k8sconfiguration create \
NarayanThiru marked this conversation as resolved.
Show resolved Hide resolved
--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 k8sconfiguration show \
--resource-group groupName \
--cluster-name clusterName \
--cluster-type clusterType \
--name configurationName
```

##### Delete a KubernetesConfiguration
```
az k8sconfiguration delete \
--resource-group groupName \
--cluster-name clusterName \
--cluster-type clusterType \
--name configurationName
```

##### Update a KubernetesConfiguration
```
az k8sconfiguration 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 k8sconfiguration 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/k8sconfiguration/azext_k8sconfiguration/__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_k8sconfiguration._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_k8sconfiguration._client_factory import cf_k8sconfiguration
k8sconfiguration_custom = CliCommandType(
operations_tmpl='azext_k8sconfiguration.custom#{}',
client_factory=cf_k8sconfiguration)
super(K8sconfigurationCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=k8sconfiguration_custom)

def load_command_table(self, args):
from azext_k8sconfiguration.commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_k8sconfiguration._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = K8sconfigurationCommandsLoader
15 changes: 15 additions & 0 deletions src/k8sconfiguration/azext_k8sconfiguration/_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_k8sconfiguration(cli_ctx, *_):

from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azext_k8sconfiguration.vendored_sdks import SourceControlConfigurationClient
return get_mgmt_service_client(cli_ctx, SourceControlConfigurationClient)


def cf_k8sconfiguration_operation(cli_ctx, _):
return cf_k8sconfiguration(cli_ctx).source_control_configurations
68 changes: 68 additions & 0 deletions src/k8sconfiguration/azext_k8sconfiguration/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# 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['k8sconfiguration'] = """
NarayanThiru marked this conversation as resolved.
Show resolved Hide resolved
type: group
short-summary: Commands to manage Kubernetes configuration.
"""

helps['k8sconfiguration create'] = """
type: command
short-summary: Create a Kubernetes configuration.
examples:
- name: Create a Kubernetes configuration
text: |-
az k8sconfiguration create --resource-group MyResourceGroup --cluster-name MyClusterName \\
--cluster-type connectedClusters --name MyConfigurationName --operator-instance-name OperatorInst01 \\
--operator-namespace OperatorNamespace01 --repository-url git://github.com/fluxHowTo/flux-get-started \\
--operator-params "'--git-readonly'" --enable-helm-operator --helm-operator-version 0.6.0 \\
--scope namespace --helm-operator-params '--set helm.versions=v3'
"""

helps['k8sconfiguration list'] = """
type: command
short-summary: List Kubernetes configurations.
examples:
- name: List all Kubernetes configurations of a cluster
text: |-
az k8sconfiguration list --resource-group MyResourceGroup --cluster-name MyClusterName \\
--cluster-type connectedClusters
"""

helps['k8sconfiguration delete'] = """
type: command
short-summary: Delete a Kubernetes configuration.
examples:
- name: Delete a Kubernetes configuration
text: |-
az k8sconfiguration delete --resource-group MyResourceGroup --cluster-name MyClusterName \\
--cluster-type connectedClusters --name MyConfigurationName
"""

helps['k8sconfiguration show'] = """
type: command
short-summary: Show details of a Kubernetes configuration.
examples:
- name: Show a Kubernetes configuration
text: |-
az k8sconfiguration show --resource-group MyResourceGroup --cluster-name MyClusterName \\
--cluster-type connectedClusters --name MyConfigurationName
"""

helps['k8sconfiguration update'] = """
type: command
short-summary: Update a Kubernetes configuration.
examples:
- name: Update an existing Kubernetes configuration
text: |-
az k8sconfiguration 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-version 0.6.0 --helm-operator-params '--set helm.versions=v3'
"""
52 changes: 52 additions & 0 deletions src/k8sconfiguration/azext_k8sconfiguration/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# --------------------------------------------------------------------------------------------
# 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


def load_arguments(self, _):
NarayanThiru marked this conversation as resolved.
Show resolved Hide resolved
sourcecontrolconfiguration_type = CLIArgumentType(help='Name of the Kubernetes Configuration')

with self.argument_context('k8sconfiguration') 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('enable_helm_operator', arg_type=get_three_state_flag(),
help='Enable support for Helm chart deployments')
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('helm_operator_params',
help='Chart values for the Helm Operator (if enabled)')
c.argument('helm_operator_version',
help='Chart version of the Helm Operator (if enabled)')
c.argument('operator_params',
help='Parameters for the Operator')
c.argument('operator_instance_name',
help='Instance name of the Operator')
c.argument('operator_namespace',
help='Namespace in which to install the Operator')
c.argument('operator_type',
help='''Type of the operator. Valid value is 'flux' ''')

with self.argument_context('k8sconfiguration list') as c:
c.argument('sourcecontrolconfiguration', sourcecontrolconfiguration_type, id_part=None)
11 changes: 11 additions & 0 deletions src/k8sconfiguration/azext_k8sconfiguration/_validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.util import CLIError


def validate_configuration_type(configuration_type):
if configuration_type.lower() != 'sourcecontrolconfiguration':
raise CLIError('Invalid configuration-type. Valid value is "sourceControlConfiguration"')
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.0.67"
}
NarayanThiru marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions src/k8sconfiguration/azext_k8sconfiguration/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# --------------------------------------------------------------------------------------------
# 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 azure.cli.core.commands import CliCommandType
from azext_k8sconfiguration._client_factory import (cf_k8sconfiguration, cf_k8sconfiguration_operation)


def load_command_table(self, _):

k8sconfiguration_sdk = CliCommandType(
operations_tmpl='azext_k8sconfiguration.vendored_sdks.operations#SourceControlConfigurationsOperations.{}',
client_factory=cf_k8sconfiguration)

with self.command_group('k8sconfiguration', k8sconfiguration_sdk, client_factory=cf_k8sconfiguration_operation,
is_preview=True) \
as g:
g.custom_command('create', 'create_k8sconfiguration')
g.custom_command('update', 'update_k8sconfiguration')
g.custom_command('delete', 'delete_k8sconfiguration', confirmation=True)
g.custom_command('list', 'list_k8sconfiguration')
g.custom_show_command('show', 'show_k8sconfiguration')
Loading