Skip to content

Commit 40c0147

Browse files
bavneetsingh16Bavneet Singhbragi92wanlonghenryandborja
authored
[k8s-extension] Update extension CLI to v1.7.0 (Azure#9126)
* add pester tests for k8s-extension * fix testcases for nodepool image issues (#5) * update readme and version release notes (#6) * fix: simplify logic and enable correct recording rule groups for managed prom extension (#7) * update readme and version release notes (#6) * fix: simplify logic and enable correct recording rule groups for managed prom extension (#7) * Extend ContainerInsights Extension for high log scale mode support (#9) * update python version to 3.13 (#10) * update readme and version release notes (#6) * fix: simplify logic and enable correct recording rule groups for managed prom extension (#7) * update readme and version release notes (#6) * fix: simplify logic and enable correct recording rule groups for managed prom extension (#7) * Add k8s-extension troubleshoot phase 1: Infrastructure setup. (#11) * [k8s-extension] Update extension CLI to v1.7.0 (#13) * remove redundant test files --------- Co-authored-by: Bavneet Singh <[email protected]> Co-authored-by: bragi92 <[email protected]> Co-authored-by: Long Wan <[email protected]> Co-authored-by: Andres Borja <[email protected]>
1 parent d4ef1af commit 40c0147

File tree

9 files changed

+744
-10
lines changed

9 files changed

+744
-10
lines changed

src/k8s-extension/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Release History
44
===============
55

6+
1.7.0
7+
+++++++++++++++++++
8+
* Added the `az k8s-extension troubleshoot` command to simplify log collection and diagnostics for extensions.
9+
610
1.6.7
711
+++++++++++++++++++
812
* microsoft.azuremonitor.containers: Extend ContainerInsights Extension for high log scale mode support.

src/k8s-extension/azext_k8s_extension/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
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
1113

1214
class K8sExtensionCommandsLoader(AzCommandsLoader):
1315

@@ -20,7 +22,7 @@ def __init__(self, cli_ctx=None):
2022
super().__init__(cli_ctx=cli_ctx,
2123
custom_command_type=k8s_extension_custom)
2224

23-
def load_command_table(self, args):
25+
def load_command_table(self, args: Union[list[str], None]) -> dict[str, CLICommand]:
2426
from .commands import load_command_table
2527
from azure.cli.core.aaz import load_aaz_command_table
2628
try:
@@ -34,9 +36,10 @@ def load_command_table(self, args):
3436
args=args
3537
)
3638
load_command_table(self, args)
37-
return self.command_table
39+
command_table: dict[str, CLICommand] = self.command_table
40+
return command_table
3841

39-
def load_arguments(self, command):
42+
def load_arguments(self, command: CLICommand):
4043
from ._params import load_arguments
4144
load_arguments(self, command)
4245

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: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
AddConfigurationProtectedSettings,
1616
)
1717

18+
from knack.commands import CLICommand
1819

19-
def load_arguments(self, _):
20+
def load_arguments(self, _: CLICommand) -> None:
2021
with self.argument_context(consts.EXTENSION_NAME) as c:
2122
c.argument('location',
2223
validator=get_default_location_from_resource_group)
@@ -131,3 +132,20 @@ def load_arguments(self, _):
131132
c.argument('show_latest',
132133
arg_type=get_three_state_flag(),
133134
help='Filter results by only the latest version. For example, if this flag is used the latest version of the extensionType will be shown.')
135+
136+
with self.argument_context(f"{consts.EXTENSION_NAME} troubleshoot") as c:
137+
c.argument('name',
138+
options_list=['--name', '-n'],
139+
help='Name of the Kubernetes extension')
140+
c.argument('namespace_list',
141+
options_list=['--namespace-list'],
142+
help='Comma-separated list of namespaces to troubleshoot')
143+
c.argument('kube_config',
144+
options_list=['--kube-config'],
145+
help='Path to the kube config file. If not specified, the default kube config file will be used.')
146+
c.argument('kube_context',
147+
options_list=['--kube-context'],
148+
help='Kubeconfig context from current machine. If not specified, the current context from kube config file will be used.')
149+
c.argument('skip_ssl_verification',
150+
action="store_true",
151+
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,27 @@
2626
HYBRIDCONTAINERSERVICE_API_VERSION = "2022-05-01-preview"
2727

2828
EXTENSION_TYPE_API_VERSION = "2023-05-01-preview"
29+
30+
# Fault type constants for error categorization.
31+
# Used to classify different types of faults encountered during diagnostics.
32+
LOAD_KUBECONFIG_FAULT_TYPE = "kubeconfig-load-error" # Error loading kubeconfig file.
33+
34+
# Warning messages for diagnostic failures.
35+
KUBECONFIG_LOAD_FAILED_WARNING = """Unable to load the kubeconfig file.
36+
Please check
37+
https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/diagnose-connection-issues#is-kubeconfig-pointing-to-the-right-cluster"""
38+
39+
EXTRACT_HELMEXE_FAULT_TYPE = "helm-client-extract-error" # Error extracting Helm client executable.
40+
41+
HELM_VERSION = "v3.12.2"
42+
43+
DOWNLOAD_AND_INSTALL_KUBECTL_FAULT_TYPE = "Failed to download and install kubectl" # Error downloading/installing kubectl.
44+
45+
KUBEAPI_CONNECTIVITY_FAILED_WARNING = """Unable to verify connectivity to the Kubernetes cluster.
46+
Please check https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/diagnose-connection-issues"""
47+
48+
KUBERNETES_CONNECTIVITY_FAULT_TYPE = "kubernetes-cluster-connection-error" # Error connecting to Kubernetes cluster.
49+
50+
# Diagnostic log file path constant.
51+
# Used to specify the name of the file where extension diagnostic logs are stored.
52+
ARC_EXT_DIAGNOSTIC_LOGS = "arc_ext_diagnostic_logs"

0 commit comments

Comments
 (0)