Skip to content

Commit 764556b

Browse files
sophsoph321Sophie Zhaomatthchr
authored
Quality improvements for az aks extension and az aks extension type command groups (Azure#8794)
* add troubleshoot command under connectedk8s * resolve check issues * fix final new line * add back troubleshoot params * implement helm version and permission checks * add aks extension and aks extension type cli groups * fix pylint * POC for extensions * fix formatting * add test and revert connectedk8s changes * remove newline from readme * fix linter issue * fix faulty examples * fix linting issues * fix parse issue * fix * fix help.py * fix more pylint issues * fix params * fix parameter issue * fix the over indent * fix pylint issue * resolve pylinter issue * remove location * remove location * add extension type * remove unrecognized parameter * add comma * fix invalid naming convensitons * fix pylinter issue * remove duplicate functions from k8sextension * add check for allowed extensions * revise tests * fix indentation issue * fix trailing whitespace * cmmit * add params * change * fix format.py * remove aks group * fix format.py * add library func for params * add const * remove libraries * update format.py * remove libraries from format.py * add check for allow list of extensions * add history.rst * fix unit test * fix style in help.py * fix extension type test * add cassete file * add modified tests * add cmd for patching the k8s extension * fix cassette file * add update * fix PR comments in format, help.py * fix style * fix action.py * fix style * add newline in params.py * update extension type command * fix pylint indentation * fix cli examples * add resource group name as param * add resource group param * add autoupgrade as description * fix autoupgrade param * add abreviation * fix option list * add autoupgrade * change autoupgrade order * add description for config settings * specify additional parameters * add examples for aks extension API * rerun pylinter * rerun pipeline * fix style and pylint issue * add location param in help.py * add region as param * run new command with style and linter * add command group * make parameters optional * use custom show command * rerun style check * fix style * fix unexpected spaces * remove extra show extension type commands * fix params in extension types api * add show version command * fix style * fix extension list version command * fix style and linting issue * fix aks test cases * print allowed list of extensions * fix help.py description * fix pylinting issue * fix style issue * fix style issue * add new cassette files * commit action.py * add backup scenario * add extension type version API commands * fix help.py examples * fix help.py * fix version summary * remove print statement * add version show * add custom helper function * fix new line issue * remove show-version and list-versions * fix style issue * fix style issue * fix style issue * location of extension * fix pylinting issue * fix location flag * Update src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py Co-authored-by: Matthew Christopher <matthchr@users.noreply.github.com> * Update src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py Co-authored-by: Matthew Christopher <matthchr@users.noreply.github.com> * add extension type filtering for core extensions * remove 3 properties * fix style * add missing custom functions * upload cassette files * change pending version * modify casette files * add k8s extension firewall * add latest cassette files * remove secrets from test case * register extension types feature * add a wait period for the feature to register * update version in setup.py * fix cassette files * update history.rst * commit * add validation * update cassette files * update history.rst * fix style issue in helpers.py * change api version * update casset files with correct API verisons * address PR comments * update setup.py * remove extra test files * update casette files * make tests live only * fix style issue * fix setup.py * fix history.rst * fix style * fix failed test case * fix syntax error * update failed test * fix * fix recording * revert yaml changes * fix put call API * update api verisons * update api version --------- Co-authored-by: Sophie Zhao <sophiezhao@microsoft.com> Co-authored-by: Matthew Christopher <matthchr@users.noreply.github.com>
1 parent 5950b48 commit 764556b

File tree

11 files changed

+125096
-1002
lines changed

11 files changed

+125096
-1002
lines changed

src/aks-preview/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ To release a new version, please select a new version number (usually plus 1 to
1212
Pending
1313
+++++++
1414

15+
18.0.0b6
16+
+++++++
17+
* Quality improvements for `az aks extension` and `az aks extension type` command groups
18+
1519
18.0.0b5
1620
+++++++
1721
* Add option `Ubuntu2204` and `Ubuntu2404` to `--os-sku` for `az aks nodepool add` and `az aks nodepool update`.

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,17 +3432,17 @@
34323432
short-summary: JSON file path for configuration-protected-settings
34333433
long-summary: JSON file path for configuration-protected-settings. If not specified, default value is None
34343434
examples:
3435-
- name: Install K8s extension on AKS cluster with required parameters
3435+
- name: Install Cluster extension on AKS cluster with required parameters
34363436
text: az aks extension create --resource-group my-resource-group \
34373437
--cluster-name mycluster --name myextension --extension-type microsoft.flux
3438-
- name: Install K8s extension with optional parameter configuration settings
3438+
- name: Install Cluster extension with optional parameter configuration settings
34393439
text: az aks extension create --resource-group abc --cluster-name test --name flux \
34403440
--extension-type microsoft.flux --config useKubeletIdentity=true
34413441
"""
34423442

34433443
helps['aks extension delete'] = """
34443444
type: command
3445-
short-summary: Delete a Kubernetes Extension.
3445+
short-summary: Delete a Cluster Extension.
34463446
parameters:
34473447
- name: --resource-group -g
34483448
type: string
@@ -3463,18 +3463,18 @@
34633463
long-summary: Specify whether to force delete the extension from the cluster \
34643464
If not specified, default value is false
34653465
examples:
3466-
- name: Delete an existing Kubernetes extension on AKS cluster
3466+
- name: Delete an existing Cluster extension on AKS cluster
34673467
text: az aks extension delete --resource-group resource-group --cluster-name cluster --name ext
3468-
- name: Delete an existing Kubernetes extension on AKS cluster with optional parameters
3468+
- name: Delete an existing Cluster extension on AKS cluster with optional parameters
34693469
text: az aks extension delete --resource-group resource-group --cluster-name cluster --name ext \
34703470
--yes --force
34713471
"""
34723472

34733473
helps['aks extension update'] = """
34743474
type: command
3475-
short-summary: Update mutable properties of a Kubernetes Extension.
3475+
short-summary: Update mutable properties of a Cluster Extension.
34763476
long-summary: For update to ConfigSettings and ConfigProtectedSettings, please \
3477-
refer to documentation of the cluster extension service to check update to these \
3477+
refer to documentation of the Cluster extension service to check update to these \
34783478
properties is supported before updating these properties. \
34793479
The output includes secrets that you must protect. Be sure that you do not include these secrets in your \
34803480
source control. Also verify that no secrets are present in the logs of your command or script. \
@@ -3512,10 +3512,10 @@
35123512
short-summary: Ignores confirmation prompt.
35133513
long-summary: Ignores confirmation prompt. If not specified, default value is false
35143514
examples:
3515-
- name: Update K8s extension on AKS cluster
3515+
- name: Update Cluster extension on AKS cluster
35163516
text: az aks extension update --resource-group my-resource-group \
35173517
--cluster-name mycluster --name myextension
3518-
- name: Update K8s extension on AKS cluster with optional parameters included
3518+
- name: Update Cluster extension on AKS cluster with optional parameters included
35193519
text: az aks extension update --resource-group my-resource-group \
35203520
--cluster-name mycluster --name myextension \
35213521
--configuration-settings settings-key=settings-value \
@@ -3526,8 +3526,8 @@
35263526

35273527
helps['aks extension list'] = """
35283528
type: command
3529-
short-summary: List Kubernetes Extensions
3530-
long-summary: List all Kubernetes Extensions in a cluster, including their properties. \
3529+
short-summary: List Cluster Extensions
3530+
long-summary: List all Cluster Extensions in a cluster, including their properties. \
35313531
The output includes secrets that you must protect. Be sure that you do not include these secrets in your \
35323532
source control. Also verify that no secrets are present in the logs of your command or script. \
35333533
For additional information, see http://aka.ms/clisecrets.
@@ -3539,14 +3539,14 @@
35393539
type: string
35403540
short-summary: Name of the AKS cluster
35413541
examples:
3542-
- name: List all Kubernetes Extensions on a cluster
3542+
- name: List all Cluster Extensions on a cluster
35433543
text: az aks extension list --resource-group <group> --cluster-name <name>
35443544
"""
35453545

35463546
helps['aks extension show'] = """
35473547
type: command
3548-
short-summary: Show a Kubernetes Extension
3549-
long-summary: Show a Kubernetes Extension including its properties. \
3548+
short-summary: Show a Cluster Extension
3549+
long-summary: Show a Cluster Extension including its properties. \
35503550
The output includes secrets that you must protect. Be sure that you do not include these secrets in your \
35513551
source control. Also verify that no secrets are present in the logs of your command or script. \
35523552
For additional information, see http://aka.ms/clisecrets.
@@ -3561,7 +3561,7 @@
35613561
type: string
35623562
short-summary: Name of the extension instance
35633563
examples:
3564-
- name: Show details of a Kubernetes Extension
3564+
- name: Show details of a Cluster Extension
35653565
text: az aks extension show --resource-group my-resource-group \
35663566
--cluster-name mycluster --name myextension
35673567
"""
@@ -3574,7 +3574,7 @@
35743574

35753575
helps['aks extension type show'] = """
35763576
type: command
3577-
short-summary: Show properties for a K8s Extension Type. The properties used for filtering include kubernetes version, location of the cluster.
3577+
short-summary: Show properties for a Cluster Extension Type. The properties used for filtering include kubernetes version, location of the cluster.
35783578
parameters:
35793579
- name: --extension-type -t
35803580
type: string
@@ -3593,16 +3593,16 @@
35933593
long-summary: Location of where we want to retrieve the extension type. If not specified, default value is None
35943594
35953595
examples:
3596-
- name: Show properties for a K8s Extension Type for an existing cluster by cluster
3596+
- name: Show properties for a Cluster Extension Type for an existing cluster by cluster
35973597
text: az aks extension type show --resource-group my-resource-group\
35983598
--cluster-name mycluster --extension-type <type>
3599-
- name: Show properties for a K8s Extension Type in a location
3599+
- name: Show properties for a Cluster Extension Type in a location
36003600
text: az aks extension type show --location eastus --extension-type type
36013601
"""
36023602

36033603
helps['aks extension type list'] = """
36043604
type: command
3605-
short-summary: List available K8s Extension Types. The properties used for filtering include kubernetes version, location of the cluster.
3605+
short-summary: List available Cluster Extension Types. The properties used for filtering include kubernetes version, location of the cluster.
36063606
parameters:
36073607
- name: --resource-group -g
36083608
type: string
@@ -3620,10 +3620,10 @@
36203620
type: string
36213621
short-summary: Specify the release train for the K8s extension type
36223622
examples:
3623-
- name: List available K8s Extension Types for an existing cluster
3623+
- name: List available Cluster Extension Types for an existing cluster
36243624
text: az aks extension type list --resource-group my-resource-group \
36253625
--cluster-name mycluster
3626-
- name: List available K8s Extension Types in a region
3626+
- name: List available Cluster Extension Types in a region
36273627
text: az aks extension type list --location eastus
36283628
"""
36293629

@@ -3635,7 +3635,7 @@
36353635

36363636
helps['aks extension type version show'] = """
36373637
type: command
3638-
short-summary: Show properties associated with a K8s Extension Type version. The properties used for filtering include kubernetes version, location of the cluster.
3638+
short-summary: Show properties associated with a Cluster Extension Type version. The properties used for filtering include kubernetes version, location of the cluster.
36393639
parameters:
36403640
- name: --resource-group -g
36413641
type: string
@@ -3656,16 +3656,16 @@
36563656
short-summary: Location of where we want to retrieve the extension type
36573657
long-summary: Location of where we want to retrieve the extension type. If not specified, default value is None
36583658
examples:
3659-
- name: Show properties for a K8s Extension Type version for an existing cluster
3659+
- name: Show properties for a Cluster Extension Type version for an existing cluster
36603660
text: az aks extension type version show --resource-group my-resource-group \
36613661
--cluster-name mycluster --extension-type type --version 1.0.0
3662-
- name: Show properties for a K8s Extension Type version for a location
3662+
- name: Show properties for a Cluster Extension Type version for a location
36633663
text: az aks extension type version show --location eastus --extension-type <type> --version 1.0.0
36643664
"""
36653665

36663666
helps['aks extension type version list'] = """
36673667
type: command
3668-
short-summary: List available K8s Extension Type versions. The properties used for filtering include kubernetes version, location of the cluster.
3668+
short-summary: List available Cluster Extension Type versions. The properties used for filtering include kubernetes version, location of the cluster.
36693669
parameters:
36703670
- name: --resource-group -g
36713671
type: string
@@ -3683,10 +3683,10 @@
36833683
short-summary: Location of where we want to retrieve the extension type
36843684
long-summary: Location of where we want to retrieve the extension type. If not specified, default value is None
36853685
examples:
3686-
- name: List available K8s Extension Types for an existing cluster
3686+
- name: List available Cluster Extension Types for an existing cluster
36873687
text: az aks extension type version list --resource-group my-resource-group \
36883688
--cluster-name mycluster --extension-type <type>
3689-
- name: List available K8s Extension Types in a region
3689+
- name: List available Cluster Extension Types in a region
36903690
text: az aks extension type version list --location eastus --extension-type <type>
36913691
"""
36923692

src/aks-preview/azext_aks_preview/_helpers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ def _check_if_extension_type_is_in_allow_list(extension_type_name):
403403

404404
def raise_validation_error_if_extension_type_not_in_allow_list(extension_type_name):
405405
if not _check_if_extension_type_is_in_allow_list(extension_type_name):
406-
raise ValidationError(f"Failed to get extension type version by cluster for {extension_type_name.lower()} " +
407-
f"as it is not in allowed list of extension types {allowed_extensions}")
406+
raise ValidationError(f"Operation failed as extension type {extension_type_name.lower()} " +
407+
f"is not in allowed list of extension types {allowed_extensions}")
408408

409409

410410
def filter_hard_taints(node_initialization_taints: List[str]) -> List[str]:
@@ -442,3 +442,9 @@ def get_all_extensions_in_allow_list(result):
442442
if _check_if_extension_type_is_in_allow_list(obj.extension_type.lower()):
443443
output.append(obj)
444444
return output
445+
446+
447+
def get_extension_in_allow_list(result):
448+
if _check_if_extension_type_is_in_allow_list(result.extension_type.lower()):
449+
return result
450+
return None

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@
215215
validate_bootstrap_container_registry_resource_id,
216216
validate_gateway_prefix_size,
217217
validate_max_unavailable,
218-
validate_location_cluster_name_resource_group_mutually_exclusive,
219218
validate_resource_group_parameter,
219+
validate_location_resource_group_cluster_parameters,
220220
)
221221
from azext_aks_preview.azurecontainerstorage._consts import (
222222
CONST_ACSTOR_ALL,
@@ -2491,14 +2491,14 @@ def load_arguments(self, _):
24912491
help='Name of resource group.')
24922492
c.argument('cluster_name',
24932493
options_list=['--cluster-name', '-c'],
2494-
validator=validate_location_cluster_name_resource_group_mutually_exclusive,
2494+
validator=validate_location_resource_group_cluster_parameters,
24952495
help='Name of the Kubernetes cluster')
24962496
c.argument('extension_type',
24972497
options_list=['--extension-type', '-t'],
24982498
help='Name of the extension type.')
24992499
c.argument('location',
25002500
options_list=['--location', '-l'],
2501-
validator=validate_location_cluster_name_resource_group_mutually_exclusive,
2501+
validator=validate_location_resource_group_cluster_parameters,
25022502
help='Name of the location. Values from: `az account list-locations`')
25032503

25042504
# Reference: https://learn.microsoft.com/en-us/cli/azure/k8s-extension/extension-types?view=azure-cli-latest
@@ -2509,14 +2509,14 @@ def load_arguments(self, _):
25092509
help='Name of resource group.')
25102510
c.argument('cluster_name',
25112511
options_list=['--cluster-name', '-c'],
2512-
validator=validate_location_cluster_name_resource_group_mutually_exclusive,
2512+
validator=validate_location_resource_group_cluster_parameters,
25132513
help='Name of the Kubernetes cluster')
25142514
c.argument('extension_type',
25152515
options_list=['--extension-type', '-t'],
25162516
help='Name of the extension type.')
25172517
c.argument('location',
25182518
options_list=['--location', '-l'],
2519-
validator=validate_location_cluster_name_resource_group_mutually_exclusive,
2519+
validator=validate_location_resource_group_cluster_parameters,
25202520
help='Name of the location. Values from: `az account list-locations`')
25212521
c.argument('version',
25222522
help='Version for the extension type.')

src/aks-preview/azext_aks_preview/_validators.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -935,19 +935,25 @@ def validate_gateway_prefix_size(namespace):
935935
raise CLIError("--gateway-prefix-size must be in the range [28, 31]")
936936

937937

938-
def validate_location_cluster_name_resource_group_mutually_exclusive(namespace):
939-
"""Validates that location, cluster name, and resource group name are not specified at the same time"""
938+
def validate_resource_group_parameter(namespace):
939+
"""Validates that if the user specified the cluster name, resource group name is also specified and vice versa"""
940+
if namespace.resource_group_name and not namespace.cluster_name:
941+
raise RequiredArgumentMissingError("Please specify --cluster")
942+
if not namespace.resource_group_name and namespace.cluster_name:
943+
raise RequiredArgumentMissingError("Please specify --resource-group")
944+
945+
946+
def validate_location_resource_group_cluster_parameters(namespace):
947+
"""Validates location or cluster details are specified and not mutually exclusive"""
940948
location = namespace.location
941949
resource_group_name = namespace.resource_group_name
942950
cluster_name = namespace.cluster_name
951+
if location and (resource_group_name or cluster_name):
952+
raise RequiredArgumentMissingError(
953+
"You must specify --location or --resource-group and --cluster."
954+
)
955+
943956
if location and resource_group_name and cluster_name:
944957
raise MutuallyExclusiveArgumentError(
945958
"Cannot specify --location and --resource-group and --cluster at the same time."
946959
)
947-
948-
949-
def validate_resource_group_parameter(namespace):
950-
if namespace.resource_group_name and not namespace.cluster_name:
951-
raise RequiredArgumentMissingError("Please specify --cluster")
952-
if not namespace.resource_group_name and namespace.cluster_name:
953-
raise RequiredArgumentMissingError("Please specify --resource-group")

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
get_all_extension_types_in_allow_list,
7272
get_all_extensions_in_allow_list,
7373
raise_validation_error_if_extension_type_not_in_allow_list,
74+
get_extension_in_allow_list,
7475
)
7576
from azext_aks_preview._podidentity import (
7677
_ensure_managed_identity_operator_permission,
@@ -3987,7 +3988,7 @@ def show_k8s_extension(cmd, client, resource_group_name, cluster_name, name):
39873988
name,
39883989
"managedClusters",
39893990
)
3990-
return result
3991+
return get_extension_in_allow_list(result)
39913992
except Exception as ex:
39923993
logger.error("Failed to get K8s extension.\nError: %s", ex)
39933994

0 commit comments

Comments
 (0)