forked from Azure/azure-cli-extensions
-
Notifications
You must be signed in to change notification settings - Fork 1
k8s-troubleshoot diagnose #4
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
Open
alphaWizard
wants to merge
19
commits into
master
Choose a base branch
from
tshoot
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d0447a9
Initial changes
954c3b5
Merge branch 'master' of https://github.com/Azure/azure-cli-extension…
a14b2ad
Adding tests
8230b4a
Merge branch 'master' of https://github.com/Azure/azure-cli-extension…
675ea86
Nit
81c24ff
fix
9d06f4b
fix2
2d13b5d
Create python-publish.yml
alphaWizard 8ee8bc7
add version
6418110
add version upd
6b9cdea
Added cert logs
a4d957f
Enhance pod condition log
59011f0
Enhancements
cee92d3
Fix help
9262e7f
add delete job stuck log
762ed58
Merge branch 'master' of https://github.com/Azure/azure-cli-extension…
3fc63ff
fix
489251c
Fixes and updates
e659f0c
Fix
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # This workflows will upload a Python Package using Twine when a release is created | ||
| # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries | ||
|
|
||
| name: Upload Python Package | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| # Trigger the workflow on push, | ||
| # but only for the main branch | ||
| push: | ||
| branches: | ||
| - master | ||
|
|
||
| jobs: | ||
| deploy: | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v2 | ||
| with: | ||
| python-version: '3.x' | ||
| - name: Install dependencies and build | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install setuptools wheel | ||
| cd src/k8s-troubleshoot | ||
| ls | ||
| printf "[bdist_wheel]\nuniversal=1\n" > setup.cfg | ||
| python setup.py sdist bdist_wheel | ||
| cd dist | ||
| ls | ||
| - name: publish .whl | ||
| uses: actions/upload-artifact@v2 | ||
| with: | ||
| name: k8s-troubleshoot-whl | ||
| path: src/k8s-troubleshoot/dist/k8s_troubleshoot-*.whl | ||
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,5 @@ | ||
| Microsoft Azure CLI 'k8s-troubleshoot' Extension | ||
| ========================================== | ||
|
|
||
| This package is for the 'k8s-troubleshoot' extension. | ||
| i.e. 'az k8s-troubleshoot' |
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,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_troubleshoot._help import helps # pylint: disable=unused-import | ||
|
|
||
|
|
||
| class K8s_troubleshootCommandsLoader(AzCommandsLoader): | ||
|
|
||
| def __init__(self, cli_ctx=None): | ||
| from azure.cli.core.commands import CliCommandType | ||
| from azext_k8s_troubleshoot._client_factory import cf_connectedk8s | ||
| k8s_troubleshoot_custom = CliCommandType( | ||
| operations_tmpl='azext_k8s_troubleshoot.custom#{}', | ||
| client_factory=cf_connectedk8s) | ||
| super(K8s_troubleshootCommandsLoader, self).__init__(cli_ctx=cli_ctx, | ||
| custom_command_type=k8s_troubleshoot_custom) | ||
|
|
||
| def load_command_table(self, args): | ||
| from azext_k8s_troubleshoot.commands import load_command_table | ||
| load_command_table(self, args) | ||
| return self.command_table | ||
|
|
||
| def load_arguments(self, command): | ||
| from azext_k8s_troubleshoot._params import load_arguments | ||
| load_arguments(self, command) | ||
|
|
||
|
|
||
| COMMAND_LOADER_CLS = K8s_troubleshootCommandsLoader |
36 changes: 36 additions & 0 deletions
36
src/k8s-troubleshoot/azext_k8s_troubleshoot/_client_factory.py
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,36 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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.common.client_factory import get_client_from_cli_profile | ||
|
|
||
|
|
||
| def cf_connectedk8s(cli_ctx, *_): | ||
| from azure.mgmt.hybridkubernetes import ConnectedKubernetesClient | ||
| return get_mgmt_service_client(cli_ctx, ConnectedKubernetesClient) | ||
|
|
||
|
|
||
| def cf_connected_cluster(cli_ctx, _): | ||
| return cf_connectedk8s(cli_ctx).connected_cluster | ||
|
|
||
|
|
||
| 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 _resource_providers_client(cli_ctx): | ||
| from azure.mgmt.resource import ResourceManagementClient | ||
| return get_mgmt_service_client(cli_ctx, ResourceManagementClient).providers | ||
|
|
||
| # Alternate: This should also work | ||
| # subscription_id = get_subscription_id(cli_ctx) | ||
| # return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id).providers | ||
|
|
||
|
|
||
| def get_subscription_client(): | ||
| from azure.mgmt.resource import SubscriptionClient | ||
| return get_client_from_cli_profile(SubscriptionClient).subscriptions |
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,22 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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 | ||
|
|
||
| Connected_Cluster_Provider_Namespace = 'Microsoft.Kubernetes' | ||
| Kubernetes_Configuration_Provider_Namespace = 'Microsoft.KubernetesConfiguration' | ||
| Custom_Locations_Provider_Namespace = 'Microsoft.ExtendedLocation' | ||
| Arc_Namespace = 'azure-arc' | ||
| DEFAULT_REQUEST_TIMEOUT = 10 # seconds | ||
| AZURE_IDENTITY_CERTIFICATE_SECRET = 'azure-identity-certificate' | ||
| ISO_861_Time_format = "%Y-%m-%dT%H:%M:%SZ" | ||
|
|
||
| # Custom fault types | ||
|
|
||
| Load_Kubeconfig_Fault_Type = "Error while loading kubeconfig" | ||
|
|
||
| # URL constants | ||
| Kubernetes_Github_Latest_Release_Uri = "https://api.github.com/repos/kubernetes/kubernetes/releases/latest" |
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,33 @@ | ||
| # 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-troubleshoot'] = """ | ||
| type: group | ||
| short-summary: Commands to troubleshoot azure-arc connected kubernetes cluster. | ||
| """ | ||
|
|
||
|
|
||
| helps['k8s-troubleshoot diagnose'] = """ | ||
| type: command | ||
| short-summary: Collects diagnose infomation and gets logs on the connected cluster. | ||
| parameters: | ||
| - name: --storage-account | ||
| type: string | ||
| short-summary: Name or ID of the storage account to save the diagnostic information. | ||
| - name: --sas-token | ||
| type: string | ||
| short-summary: The SAS token with writable permission for the storage account. | ||
| examples: | ||
| - name: using storage account name and a shared access signature token with write permission | ||
alphaWizard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| text: az k8s-troubleshoot diagnose -g MyResourceGroup -n ConnectedCluster --storage-account MyStorageAccount --sas-token "MySasToken" | ||
| - name: using the resource id of a storage account resource you own. | ||
| text: az k8s-troubleshoot diagnose -g MyResourceGroup -n ConnectedCluster --storage-account "MyStoreageAccountResourceId" | ||
| - name: using the storage account in diagnostics settings for your connected cluster. | ||
| text: az k8s-troubleshoot diagnose -g MyResourceGroup -n ConnectedCluster | ||
| """ | ||
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,21 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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 | ||
|
|
||
| import os.path | ||
| from azure.cli.core.commands.parameters import get_location_type, file_type | ||
| from azure.cli.core.commands.validators import get_default_location_from_resource_group | ||
|
|
||
|
|
||
| def load_arguments(self, _): | ||
|
|
||
| with self.argument_context('k8s-troubleshoot diagnose') as c: | ||
| c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group) | ||
| 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.') | ||
| c.argument('storage_account', options_list=['--storage-account'], help='Name or ID of the storage account to save the diagnostic information') | ||
| c.argument('sas_token', options_list=['--sas-token'], help='The SAS token with writable permission for the storage account.') | ||
| c.argument('output_file', options_list=['--output-file'], type=file_type, default=os.path.join(os.path.expanduser('~'), '.azure', 'az_k8s_troubleshoot_output.tar.gz'), help="Output zipped file path for the logs collected during troubleshoot.") |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary testing pipeline