-
Notifications
You must be signed in to change notification settings - Fork 1.6k
cli extension for connected kubernetes RP #1570
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
Merged
Merged
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
5090698
Vanilla CLI Code for Connected Cluster
fda117d
saved location data CLI changes after 0.1.2
e781176
Added the 0.1.2 version CLI code in master
969a45f
Removed a print statement
d60bd23
Fixed container status check
45e2db7
Updated pod status check
678c2b7
Merge pull request #1 from akashkeshari/akash/agent_monitor_fix
akashkeshari 85aa7d9
Added 2020 version models and operations
d345685
Updated with key pair generation
4e90290
review of public private key pair
836e6fc
updated models with latest changes in swagger
a1bea49
Update CLI to support SPN less onboarding
6522421
Removed location data changes
dec8fab
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari 9bd5580
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari 854b36f
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari 576704d
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari b26a0eb
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari 6d445c3
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari 9df8269
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari 031639b
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari 47ca292
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari b237d9c
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari 6249ea7
Updated error messages
5223949
resolved a conflict
c1ecbf8
updated wrt style checks
f43ebfb
Added a recorded test
d237667
Updated forked master with original master
32c5089
Updated with latest master changes
a97f36e
Updated imports
025522c
removed python 2.x from setup.py
1967b02
Updated format.py
df87f51
Updated readme file
b747e92
Updated test file
9d9c954
updated setup.py
2db8c30
updated knack version in setup.py
bd26f72
updated knack version to 0.7.0rc4 in setup.py
9dbfa0b
Updated test file to pass kubeconfig
c45a3a6
Updated test file to pass kubeconfig
f27610a
Added async support for delete
9852a51
Added helm charts to test data folder
ddad5b7
Updated helm chart pull method
6e6cd75
corrected import order
eb723fb
Ran connectedk8s test
a5407c1
Updated some print statements
3b8f930
ran test with helm upgrade --install
9f72a47
Updated print to warning
5515568
Updated error message
fac6740
Updated exceptions to be generic
e0f5022
Added aks creation in tests
c9d1071
updated warning statements
3b78ee8
updated test to create aks cluster with ssh keys
96a2cbe
added spn calls in recorded tests
2c7b8b3
Updated api-version in recorded tests
b9fdd1e
removed mc delete as CI test needs it to be persistant
cfb21ab
switched to livescenariotest
005e414
updated params.py
ba268a1
corrected databricks change
0ff1943
updated pod monitoring
d77e433
updated identation
44f4547
updated print statement to warnings
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,8 @@ | ||
| .. :changelog: | ||
|
|
||
| Release History | ||
| =============== | ||
|
|
||
| 0.1.0 | ||
| ++++++ | ||
| * Initial release. |
This file contains hidden or 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,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 | ||
| ``` |
This file contains hidden or 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,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 |
This file contains hidden or 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,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 |
This file contains hidden or 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,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)) |
This file contains hidden or 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,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 | ||
|
|
||
| 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 | ||
| """ | ||
This file contains hidden or 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,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.
|
||
This file contains hidden or 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,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 | ||
| ) |
This file contains hidden or 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,4 @@ | ||
| { | ||
| "azext.isPreview": true, | ||
| "azext.minCliCoreVersion": "2.0.67" | ||
| } |
This file contains hidden or 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,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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.