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

cli extension for connected kubernetes RP #1570

Merged
merged 62 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
68800b6
Added spn and resource group creation in connectedk8s create
Nov 12, 2019
5090698
Vanilla CLI Code for Connected Cluster
Nov 22, 2019
fda117d
saved location data CLI changes after 0.1.2
Mar 11, 2020
e781176
Added the 0.1.2 version CLI code in master
Mar 11, 2020
969a45f
Removed a print statement
Mar 11, 2020
d60bd23
Fixed container status check
Mar 12, 2020
45e2db7
Updated pod status check
Mar 13, 2020
678c2b7
Merge pull request #1 from akashkeshari/akash/agent_monitor_fix
akashkeshari Mar 16, 2020
85aa7d9
Added 2020 version models and operations
Mar 24, 2020
d345685
Updated with key pair generation
Mar 29, 2020
4e90290
review of public private key pair
Apr 1, 2020
836e6fc
updated models with latest changes in swagger
Apr 4, 2020
a1bea49
Update CLI to support SPN less onboarding
Apr 7, 2020
6522421
Removed location data changes
Apr 13, 2020
dec8fab
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
9bd5580
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
854b36f
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
576704d
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
b26a0eb
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
6d445c3
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
9df8269
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
031639b
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
47ca292
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
b237d9c
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
6249ea7
Updated error messages
Apr 21, 2020
5223949
resolved a conflict
Apr 21, 2020
c1ecbf8
updated wrt style checks
Apr 21, 2020
f43ebfb
Added a recorded test
Apr 21, 2020
d237667
Updated forked master with original master
Apr 21, 2020
32c5089
Updated with latest master changes
Apr 21, 2020
a97f36e
Updated imports
Apr 21, 2020
025522c
removed python 2.x from setup.py
Apr 21, 2020
1967b02
Updated format.py
Apr 21, 2020
df87f51
Updated readme file
Apr 22, 2020
b747e92
Updated test file
Apr 22, 2020
9d9c954
updated setup.py
Apr 22, 2020
2db8c30
updated knack version in setup.py
Apr 22, 2020
bd26f72
updated knack version to 0.7.0rc4 in setup.py
Apr 22, 2020
9dbfa0b
Updated test file to pass kubeconfig
Apr 23, 2020
c45a3a6
Updated test file to pass kubeconfig
Apr 23, 2020
f27610a
Added async support for delete
Apr 24, 2020
9852a51
Added helm charts to test data folder
Apr 27, 2020
ddad5b7
Updated helm chart pull method
Apr 27, 2020
6e6cd75
corrected import order
Apr 27, 2020
eb723fb
Ran connectedk8s test
Apr 27, 2020
a5407c1
Updated some print statements
Apr 27, 2020
3b8f930
ran test with helm upgrade --install
Apr 27, 2020
9f72a47
Updated print to warning
Apr 27, 2020
5515568
Updated error message
Apr 27, 2020
fac6740
Updated exceptions to be generic
Apr 28, 2020
e0f5022
Added aks creation in tests
Apr 29, 2020
c9d1071
updated warning statements
Apr 29, 2020
3b78ee8
updated test to create aks cluster with ssh keys
Apr 29, 2020
96a2cbe
added spn calls in recorded tests
Apr 29, 2020
2c7b8b3
Updated api-version in recorded tests
Apr 29, 2020
b9fdd1e
removed mc delete as CI test needs it to be persistant
Apr 29, 2020
cfb21ab
switched to livescenariotest
Apr 29, 2020
005e414
updated params.py
Apr 30, 2020
ba268a1
corrected databricks change
Apr 30, 2020
0ff1943
updated pod monitoring
Apr 30, 2020
d77e433
updated identation
Apr 30, 2020
44f4547
updated print statement to warnings
Apr 30, 2020
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 @@ -70,6 +70,8 @@

/src/ip-group/ @haroldrandom

/src/connectedk8s/ @akashkeshari

/src/storagesync/ @jsntcy

/src/maintenance/ @gautamd-ms
Expand Down
8 changes: 8 additions & 0 deletions src/connectedk8s/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:

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

0.1.0
++++++
* Initial release.
54 changes: 54 additions & 0 deletions src/connectedk8s/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Azure CLI Connected Kubernetes Extension #
This package is for the 'connectedk8s' extension, i.e. 'az connectedk8s'.

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

### Included Features
#### Connected Kubernetes Management:
*Examples:*

##### Create a connected kubernetes cluster
```
az connectedk8s connect \
--subscription subscription_id \
--resource-group my-rg \
--name my-cluster \
--location eastus
```

##### Show connected kubernetes cluster
```
az connectedk8s show \
--subscription subscription_id \
--resource-group my-rg \
--name my-cluster \
```
or
```
az connectedk8s show \
--ids "/subscriptions/subscription_id/resourceGroups/my-rg/providers/Microsoft.Kubernetes/connectedClusters/my-cluster" \
```

##### List connected kubernetes cluster in resource group
```
az connectedk8s list \
--resource-group my-rg
```

##### Delete connected kubernetes cluster
```
az connectedk8s delete \
--subscription subscription_id \
--resource-group my-rg \
--name my-cluster \
```
or
```
az connectedk8s delete \
--ids "/subscriptions/subscription_id/resourceGroups/my-rg/providers/Microsoft.Kubernetes/connectedClusters/my-cluster" \
-y
```
31 changes: 31 additions & 0 deletions src/connectedk8s/azext_connectedk8s/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# --------------------------------------------------------------------------------------------
# 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_connectedk8s._help import helps # pylint: disable=unused-import


class Connectedk8sCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from azext_connectedk8s._client_factory import cf_connectedk8s
connectedk8s_custom = CliCommandType(
operations_tmpl='azext_connectedk8s.custom#{}',
client_factory=cf_connectedk8s)
super(Connectedk8sCommandsLoader, self).__init__(cli_ctx=cli_ctx, custom_command_type=connectedk8s_custom)

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

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


COMMAND_LOADER_CLS = Connectedk8sCommandsLoader
37 changes: 37 additions & 0 deletions src/connectedk8s/azext_connectedk8s/_client_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# --------------------------------------------------------------------------------------------
# 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.commands.client_factory import get_mgmt_service_client
from azure.cli.core.profiles import ResourceType
from azure.cli.core._profile import Profile
from azure.cli.core.commands.client_factory import configure_common_settings
from azure.graphrbac import GraphRbacManagementClient


def cf_connectedk8s(cli_ctx, *_):
from azext_connectedk8s.vendored_sdks import KubernetesConnectRPClient
return get_mgmt_service_client(cli_ctx, KubernetesConnectRPClient)


def cf_connected_cluster(cli_ctx, _):
return cf_connectedk8s(cli_ctx).connected_cluster


def cf_resource_groups(cli_ctx, subscription_id=None):
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES,
subscription_id=subscription_id).resource_groups


def _resource_client_factory(cli_ctx, subscription_id=None):
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id)


def _graph_client_factory(cli_ctx, **_):
profile = Profile(cli_ctx=cli_ctx)
cred, _, tenant_id = profile.get_login_credentials(
resource=cli_ctx.cloud.endpoints.active_directory_graph_resource_id)
client = GraphRbacManagementClient(cred, tenant_id,
base_url=cli_ctx.cloud.endpoints.active_directory_graph_resource_id)
configure_common_settings(cli_ctx, client)
return client
37 changes: 37 additions & 0 deletions src/connectedk8s/azext_connectedk8s/_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# --------------------------------------------------------------------------------------------
# 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
from jmespath import compile as compile_jmes, Options # pylint: disable=import-error


def connectedk8s_show_table_format(result):
"""Format a connected cluster as summary results for display with "-o table"."""
return [_connectedk8s_table_format(result)]


def connectedk8s_list_table_format(results):
"""Format an connected cluster list for display with "-o table"."""
return [_connectedk8s_list_table_format(r) for r in results]


def _connectedk8s_table_format(result):
parsed = compile_jmes("""{
name: name,
location: location,
resourceGroup: resourceGroup
}""")
# use ordered dicts so headers are predictable
return parsed.search(result, Options(dict_cls=OrderedDict))


def _connectedk8s_list_table_format(result):
parsed = compile_jmes("""{
name: name,
location: location,
resourceGroup: resourceGroup
}""")
# use ordered dicts so headers are predictable
return parsed.search(result, Options(dict_cls=OrderedDict))
67 changes: 67 additions & 0 deletions src/connectedk8s/azext_connectedk8s/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 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['connectedk8s'] = """
type: group
short-summary: Commands to manage connected kubernetes clusters.
"""

helps['connectedk8s connect'] = """
type: command
short-summary: Onboard a connected kubernetes cluster to azure.
parameters:
- name: --kube-config
type: string
short-summary: Path to the kube config file
- name: --kube-context
type: string
short-summary: Kubconfig context from current machine
akashkeshari marked this conversation as resolved.
Show resolved Hide resolved

examples:
- name: Onboard a connected kubernetes cluster with default kube config and kube context.
text: az connectedk8s connect -g resourceGroupName -n connectedClusterName
- name: Onboard a connected kubernetes cluster by specifying the kubeconfig and kubecontext.
text: az connectedk8s connect -g resourceGroupName -n connectedClusterName --kube-config /path/to/kubeconfig --kube-context kubeContextName
"""

helps['connectedk8s list'] = """
type: command
short-summary: List connected kubernetes clusters.
examples:
- name: List all connected kubernetes clusters in a resource group.
text: az connectedk8s list -g resourceGroupName --subscription subscriptionName
- name: List all connected kubernetes clusters in a subscription.
text: az connectedk8s list --subscription subscriptionName

"""

helps['connectedk8s delete'] = """
type: command
short-summary: Delete a connected kubernetes cluster along with connected cluster agents.
parameters:
- name: --kube-config
type: string
short-summary: Path to the kube config file
- name: --kube-context
type: string
short-summary: Kubconfig context from current machine
examples:
- name: Delete a connected kubernetes cluster and connected cluster agents with default kubeconfig and kubecontext.
text: az connectedk8s delete -g resourceGroupName -n connectedClusterName
- name: Delete a connected kubernetes cluster by specifying the kubeconfig and kubecontext for connected cluster agents deletion.
text: az connectedk8s delete -g resourceGroupName -n connectedClusterName --kube-config /path/to/kubeconfig --kube-context kubeContextName
"""

helps['connectedk8s show'] = """
type: command
short-summary: Show details of a connected kubernetes cluster.
examples:
- name: Show the details for a connected kubernetes cluster
text: az connectedk8s show -g resourceGroupName -n connectedClusterName
"""
27 changes: 27 additions & 0 deletions src/connectedk8s/azext_connectedk8s/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# --------------------------------------------------------------------------------------------
# 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


def load_arguments(self, _):

from azure.cli.core.commands.parameters import tags_type

with self.argument_context('connectedk8s connect') as c:
c.argument('tags', tags_type)
c.argument('cluster_name', options_list=['--name', '-n'], help='The name of the connected cluster.')
c.argument('kube_config', options_list=['--kube-config'], help='Path to the kube config file.')
c.argument('kube_context', options_list=['--kube-context'], help='Kubconfig context from current machine.')

with self.argument_context('connectedk8s list') as c:
pass

with self.argument_context('connectedk8s show') as c:
c.argument('cluster_name', options_list=['--name', '-n'], help='The name of the connected cluster.')

with self.argument_context('connectedk8s delete') as c:
c.argument('cluster_name', options_list=['--name', '-n'], help='The name of the connected cluster.')
c.argument('kube_config', options_list=['--kube-config'], help='Path to the kube config file.')
c.argument('kube_context', options_list=['--kube-context'], help='Kubconfig context from current machine.')
akashkeshari marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions src/connectedk8s/azext_connectedk8s/_validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


def example_name_or_id_validator(cmd, namespace):
# Example of a storage account name or ID validator.
from azure.cli.core.commands.client_factory import get_subscription_id
from msrestazure.tools import is_valid_resource_id, resource_id
if namespace.storage_account:
if not is_valid_resource_id(namespace.RESOURCE):
namespace.storage_account = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Storage',
type='storageAccounts',
name=namespace.storage_account
)
4 changes: 4 additions & 0 deletions src/connectedk8s/azext_connectedk8s/azext_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.0.67"
}
27 changes: 27 additions & 0 deletions src/connectedk8s/azext_connectedk8s/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# --------------------------------------------------------------------------------------------
# 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_connectedk8s._client_factory import (cf_connectedk8s, cf_connected_cluster)
from ._format import connectedk8s_show_table_format
from ._format import connectedk8s_list_table_format


def load_command_table(self, _):

connectedk8s_sdk = CliCommandType(
operations_tmpl='azext_connectedk8s.vendored_sdks.operations#ConnectedClusterOperations.{}',
client_factory=cf_connectedk8s
)

with self.command_group('connectedk8s', connectedk8s_sdk, client_factory=cf_connected_cluster) as g:
g.custom_command('connect', 'create_connectedk8s', supports_no_wait=True)
g.custom_command('delete', 'delete_connectedk8s', confirmation=True, supports_no_wait=True)
g.custom_command('list', 'list_connectedk8s', table_transformer=connectedk8s_list_table_format)
g.custom_show_command('show', 'get_connectedk8s', table_transformer=connectedk8s_show_table_format)

with self.command_group('connectedk8s', is_preview=True):
pass
Loading