Skip to content

Commit 1a52982

Browse files
committed
Add k8s-extension troubleshoot.
Work item: https://msazure.visualstudio.com/One/_workitems/edit/34260596
1 parent 94bb278 commit 1a52982

10 files changed

Lines changed: 821 additions & 11 deletions

File tree

src/k8s-extension/azext_k8s_extension/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
from azure.cli.core import AzCommandsLoader
77
from . import consts
8+
from typing import Union
89

910
from ._help import helps # pylint: disable=unused-import
1011

12+
from knack.commands import CLICommand
13+
1114

1215
class K8sExtensionCommandsLoader(AzCommandsLoader):
1316

@@ -20,7 +23,7 @@ def __init__(self, cli_ctx=None):
2023
super().__init__(cli_ctx=cli_ctx,
2124
custom_command_type=k8s_extension_custom)
2225

23-
def load_command_table(self, args):
26+
def load_command_table(self, args: Union[list[str], None]) -> dict[str, CLICommand]:
2427
from .commands import load_command_table
2528
from azure.cli.core.aaz import load_aaz_command_table
2629
try:
@@ -34,9 +37,10 @@ def load_command_table(self, args):
3437
args=args
3538
)
3639
load_command_table(self, args)
37-
return self.command_table
40+
command_table: dict[str, CLICommand] = self.command_table
41+
return command_table
3842

39-
def load_arguments(self, command):
43+
def load_arguments(self, command: CLICommand):
4044
from ._params import load_arguments
4145
load_arguments(self, command)
4246

src/k8s-extension/azext_k8s_extension/_help.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@
9494
--config-protected-file=protected-settings-file
9595
"""
9696

97+
helps[f'{consts.EXTENSION_NAME} troubleshoot'] = f"""
98+
type: command
99+
short-summary: Perform diagnostic checks on a Kubernetes Extension.
100+
long-summary: This command is used to troubleshoot a Kubernetes Extension. It \
101+
collects logs and other information that can be used to diagnose issues with the extension.
102+
examples:
103+
- name: Troubleshoot a Kubernetes Extension
104+
text: |-
105+
az {consts.EXTENSION_NAME} troubleshoot --name extension-name \
106+
--namespace-list "namespace1,namespace2"
107+
"""
108+
97109
helps[f'{consts.EXTENSION_NAME} extension-types'] = """
98110
type: group
99111
short-summary: Commands to discover Kubernetes Extension Types.

src/k8s-extension/azext_k8s_extension/_params.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
AddConfigurationProtectedSettings,
1616
)
1717

18+
from knack.commands import CLICommand
1819

19-
def load_arguments(self, _):
20+
21+
def load_arguments(self, _: CLICommand) -> None:
2022
with self.argument_context(consts.EXTENSION_NAME) as c:
2123
c.argument('location',
2224
validator=get_default_location_from_resource_group)
@@ -131,3 +133,20 @@ def load_arguments(self, _):
131133
c.argument('show_latest',
132134
arg_type=get_three_state_flag(),
133135
help='Filter results by only the latest version. For example, if this flag is used the latest version of the extensionType will be shown.')
136+
137+
with self.argument_context(f"{consts.EXTENSION_NAME} troubleshoot") as c:
138+
c.argument('name',
139+
options_list=['--name', '-n'],
140+
help='Name of the Kubernetes extension')
141+
c.argument('namespace_list',
142+
options_list=['--namespace-list'],
143+
help='Comma-separated list of namespaces to troubleshoot')
144+
c.argument('kube_config',
145+
options_list=['--kube-config'],
146+
help='Path to the kube config file. If not specified, the default kube config file will be used.')
147+
c.argument('kube_context',
148+
options_list=['--kube-context'],
149+
help='Kubeconfig context from current machine. If not specified, the current context from kube config file will be used.')
150+
c.argument('skip_ssl_verification',
151+
action="store_true",
152+
help='Skip SSL verification for any cluster connection.')

src/k8s-extension/azext_k8s_extension/commands.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def load_command_table(self, _):
2323
g.custom_command('list', 'list_k8s_extension', table_transformer=k8s_extension_list_table_format)
2424
g.custom_show_command('show', 'show_k8s_extension', table_transformer=k8s_extension_show_table_format)
2525
g.custom_command('update', 'update_k8s_extension', supports_no_wait=True)
26+
g.custom_command('troubleshoot', 'troubleshoot_extension', is_preview=True)
2627

2728
# Subgroup - k8s-extension extension-types
2829
k8s_cluster_extension_type_sdk = CliCommandType(

src/k8s-extension/azext_k8s_extension/consts.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,39 @@
2626
HYBRIDCONTAINERSERVICE_API_VERSION = "2022-05-01-preview"
2727

2828
EXTENSION_TYPE_API_VERSION = "2023-05-01-preview"
29+
30+
# Diagnostic check result constants.
31+
# Used to indicate the outcome of a diagnostic check performed on the cluster or extension.
32+
DIAGNOSTIC_CHECK_PASSED = "Passed" # The diagnostic check completed successfully.
33+
DIAGNOSTIC_CHECK_FAILED = "Failed" # The diagnostic check failed.
34+
DIAGNOSTIC_CHECK_INCOMPLETE = "Incomplete" # The diagnostic check did not complete.
35+
36+
# Diagnostic check name constants.
37+
# Used to identify specific diagnostic checks performed during troubleshooting.
38+
RETRIEVE_NAMESPACE_LOGS = "retrieved_namespace_logs" # Check for retrieving logs from a namespace.
39+
RETRIEVE_POD_STATUS = "retrieved_pod_status" # Check for retrieving pod status information.
40+
RETRIEVE_CONFIGMAP = "retrieved_config_map" # Check for retrieving ConfigMap data.
41+
42+
# Fault type constants for error categorization.
43+
# Used to classify different types of faults encountered during diagnostics.
44+
LOAD_KUBECONFIG_FAULT_TYPE = "kubeconfig-load-error" # Error loading kubeconfig file.
45+
46+
# Warning messages for diagnostic failures.
47+
KUBECONFIG_LOAD_FAILED_WARNING = """Unable to load the kubeconfig file.
48+
Please check
49+
https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/diagnose-connection-issues#is-kubeconfig-pointing-to-the-right-cluster"""
50+
51+
EXTRACT_HELMEXE_FAULT_TYPE = "helm-client-extract-error" # Error extracting Helm client executable.
52+
53+
HELM_VERSION = "v3.12.2"
54+
55+
DOWNLOAD_AND_INSTALL_KUBECTL_FAULT_TYPE = "Failed to download and install kubectl" # Error downloading/installing kubectl.
56+
57+
KUBEAPI_CONNECTIVITY_FAILED_WARNING = """Unable to verify connectivity to the Kubernetes cluster.
58+
Please check https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/diagnose-connection-issues"""
59+
60+
KUBERNETES_CONNECTIVITY_FAULT_TYPE = "kubernetes-cluster-connection-error" # Error connecting to Kubernetes cluster.
61+
62+
# Diagnostic log file path constant.
63+
# Used to specify the name of the file where extension diagnostic logs are stored.
64+
ARC_EXT_DIAGNOSTIC_LOGS = "arc_ext_diagnostic_logs"

0 commit comments

Comments
 (0)