Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions .github/workflows/python-publish.yml
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
Copy link
Owner Author

@alphaWizard alphaWizard May 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary testing pipeline

# 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
8 changes: 8 additions & 0 deletions src/k8s-troubleshoot/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:

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

0.1.0
++++++
* Initial release.
5 changes: 5 additions & 0 deletions src/k8s-troubleshoot/README.rst
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'
32 changes: 32 additions & 0 deletions src/k8s-troubleshoot/azext_k8s_troubleshoot/__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_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 src/k8s-troubleshoot/azext_k8s_troubleshoot/_client_factory.py
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
22 changes: 22 additions & 0 deletions src/k8s-troubleshoot/azext_k8s_troubleshoot/_constants.py
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"
33 changes: 33 additions & 0 deletions src/k8s-troubleshoot/azext_k8s_troubleshoot/_help.py
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
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
"""
21 changes: 21 additions & 0 deletions src/k8s-troubleshoot/azext_k8s_troubleshoot/_params.py
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.")
Loading