Skip to content

Commit 59cb086

Browse files
authored
{AKS} Vendor new SDK and bump API version to 2026-01-01 (#32955)
1 parent 16a7972 commit 59cb086

File tree

227 files changed

+2266
-2268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+2266
-2268
lines changed

src/azure-cli/azure/cli/command_modules/acs/_help.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,13 @@
12121212
helps["aks delete"] = """
12131213
type: command
12141214
short-summary: Delete a managed Kubernetes cluster.
1215+
parameters:
1216+
- name: --if-match
1217+
type: string
1218+
short-summary: The value provided will be compared to the ETag of the managed cluster, if it matches the operation will proceed. If it does not match, the request will be rejected to prevent accidental overwrites.
1219+
- name: --if-none-match
1220+
type: string
1221+
short-summary: Set to '*' to allow deleting a cluster only if it exists. Other values will be ignored.
12151222
examples:
12161223
- name: Delete a managed Kubernetes cluster. (autogenerated)
12171224
text: az aks delete --name MyManagedCluster --resource-group MyResourceGroup

src/azure-cli/azure/cli/command_modules/acs/_helpers.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import random
88
import re
99
import semver
10-
from typing import Any, List, TypeVar
10+
from typing import Any, Dict, List, TypeVar
1111

1212
from azure.cli.command_modules.acs._client_factory import get_snapshots_client, get_msi_client
1313
from azure.cli.core.azclierror import (
@@ -66,6 +66,22 @@ def safe_lower(obj: Any) -> Any:
6666
return obj
6767

6868

69+
def build_etag_kwargs(if_match=None, if_none_match=None) -> Dict[str, Any]:
70+
"""Convert if_match/if_none_match to etag/match_condition kwargs for SDK v41+."""
71+
from azure.core import MatchConditions
72+
kwargs: Dict[str, Any] = {}
73+
if if_match is not None:
74+
kwargs["etag"] = if_match
75+
kwargs["match_condition"] = MatchConditions.IfNotModified
76+
elif if_none_match is not None:
77+
if if_none_match == "*":
78+
kwargs["match_condition"] = MatchConditions.IfMissing
79+
else:
80+
kwargs["etag"] = if_none_match
81+
kwargs["match_condition"] = MatchConditions.IfModified
82+
return kwargs
83+
84+
6985
def get_property_from_dict_or_object(obj, property_name) -> Any:
7086
"""Get the value corresponding to the property name from a dictionary or object.
7187
@@ -103,15 +119,10 @@ def check_is_private_cluster(mc: ManagedCluster) -> bool:
103119
def check_is_apiserver_vnet_integration_cluster(mc: ManagedCluster) -> bool:
104120
"""Check `mc` object to determine whether apiserver vnet integration is enabled.
105121
106-
Note: enableVnetIntegration is still in preview api so we use additional_properties here
107-
108122
:return: bool
109123
"""
110124
if mc and mc.api_server_access_profile:
111-
additional_properties = mc.api_server_access_profile.additional_properties
112-
if 'enableVnetIntegration' in additional_properties:
113-
return additional_properties['enableVnetIntegration']
114-
return False
125+
return bool(mc.api_server_access_profile.enable_vnet_integration)
115126
return False
116127

117128

src/azure-cli/azure/cli/command_modules/acs/_params.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,10 @@ def load_arguments(self, _):
842842
'by that action.'
843843
)
844844
)
845+
with self.argument_context('aks delete') as c:
846+
c.argument("if_match")
847+
c.argument("if_none_match")
848+
845849
with self.argument_context('aks disable-addons', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
846850
c.argument('addons', options_list=['--addons', '-a'])
847851

src/azure-cli/azure/cli/command_modules/acs/agentpool_decorator.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
DecoratorEarlyExitException,
3333
DecoratorMode,
3434
)
35-
from azure.cli.command_modules.acs._helpers import get_snapshot_by_snapshot_id, safe_list_get, process_dns_overrides
35+
from azure.cli.command_modules.acs._helpers import (
36+
get_snapshot_by_snapshot_id, safe_list_get, process_dns_overrides, build_etag_kwargs
37+
)
3638
from azure.cli.command_modules.acs._validators import extract_comma_separated_string
3739
from azure.cli.command_modules.acs.base_decorator import BaseAKSContext, BaseAKSModels, BaseAKSParamDict
3840
from azure.cli.core import AzCommandsLoader
@@ -1249,8 +1251,9 @@ def get_vm_set_type(self) -> str:
12491251
if self.agentpool and self.agentpool.type is not None:
12501252
vm_set_type = self.agentpool.type
12511253
else:
1252-
if self.agentpool and self.agentpool.type_properties_type is not None:
1253-
vm_set_type = self.agentpool.type_properties_type
1254+
if (self.agentpool and self.agentpool.properties and
1255+
self.agentpool.properties.type_properties_type is not None):
1256+
vm_set_type = self.agentpool.properties.type_properties_type
12541257

12551258
# normalize
12561259
if vm_set_type.lower() == CONST_VIRTUAL_MACHINE_SCALE_SETS.lower():
@@ -2350,8 +2353,7 @@ def add_agentpool(self, agentpool: AgentPool) -> AgentPool:
23502353
# validated in "init_agentpool", skip to avoid duplicate api calls
23512354
self.context._get_nodepool_name(enable_validation=False),
23522355
agentpool,
2353-
if_match=self.context.get_if_match(),
2354-
if_none_match=self.context.get_if_none_match(),
2356+
**build_etag_kwargs(self.context.get_if_match(), self.context.get_if_none_match()),
23552357
headers=self.context.get_aks_custom_headers(),
23562358
)
23572359

@@ -2697,8 +2699,7 @@ def update_agentpool(self, agentpool: AgentPool) -> AgentPool:
26972699
self.context.get_cluster_name(),
26982700
self.context.get_nodepool_name(),
26992701
agentpool,
2700-
if_match=self.context.get_if_match(),
2701-
if_none_match=self.context.get_if_none_match(),
2702+
**build_etag_kwargs(self.context.get_if_match(), self.context.get_if_none_match()),
27022703
headers=self.context.get_aks_custom_headers(),
27032704
)
27042705

src/azure-cli/azure/cli/command_modules/acs/commands.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ def load_command_table(self, _):
3939

4040
managed_clusters_sdk = CliCommandType(
4141
operations_tmpl='azure.mgmt.containerservice.operations.'
42-
'_managed_clusters_operations#ManagedClustersOperations.{}',
42+
'_operations#ManagedClustersOperations.{}',
4343
operation_group='managed_clusters',
4444
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
4545
client_factory=cf_managed_clusters
4646
)
4747

4848
agent_pools_sdk = CliCommandType(
4949
operations_tmpl='azure.mgmt.containerservice.operations.'
50-
'_agent_pools_operations#AgentPoolsOperations.{}',
50+
'_operations#AgentPoolsOperations.{}',
5151
operation_group='agent_pools',
5252
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
5353
client_factory=cf_managed_clusters
@@ -60,40 +60,40 @@ def load_command_table(self, _):
6060
)
6161

6262
maintenance_configuration_sdk = CliCommandType(
63-
operations_tmpl='aazure.mgmt.containerservice.operations.'
64-
'_maintenance_configurations_operations#MaintenanceConfigurationsOperations.{}',
63+
operations_tmpl='azure.mgmt.containerservice.operations.'
64+
'_operations#MaintenanceConfigurationsOperations.{}',
6565
operation_group='maintenance_configurations',
6666
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
6767
client_factory=cf_maintenance_configurations
6868
)
6969

7070
managed_namespaces_sdk = CliCommandType(
7171
operations_tmpl='azure.mgmt.containerservice.operations.'
72-
'_managed_namespaces_operations#ManagedNamespacesOperations.{}',
72+
'_operations#ManagedNamespacesOperations.{}',
7373
operation_group='managed_namespaces',
7474
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
7575
client_factory=cf_managed_namespaces,
7676
)
7777

7878
snapshot_sdk = CliCommandType(
7979
operations_tmpl='azure.mgmt.containerservice.operations.'
80-
'_snapshots_operations#SnapshotsOperations.{}',
80+
'_operations#SnapshotsOperations.{}',
8181
operation_group='snapshots',
8282
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
8383
client_factory=cf_snapshots
8484
)
8585

8686
trustedaccess_role_sdk = CliCommandType(
8787
operations_tmpl='azure.mgmt.containerservice.operations.'
88-
'_trusted_access_roles_operations#TrustedAccessRolesOperations.{}',
88+
'_operations#TrustedAccessRolesOperations.{}',
8989
operation_group='trustedaccess_role',
9090
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
9191
client_factory=cf_trustedaccess_role
9292
)
9393

9494
trustedaccess_role_binding_sdk = CliCommandType(
9595
operations_tmpl='azure.mgmt.containerservice.operations.'
96-
'_trusted_access_role_bindings_operations#TrustedAccessRoleBindingsOperations.{}',
96+
'_operations#TrustedAccessRoleBindingsOperations.{}',
9797
operation_group='trustedaccess_role_binding',
9898
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
9999
client_factory=cf_trustedaccess_role_binding
@@ -109,8 +109,8 @@ def load_command_table(self, _):
109109
table_transformer=aks_upgrades_table_format)
110110
g.custom_command('upgrade', 'aks_upgrade', supports_no_wait=True)
111111
g.custom_command('scale', 'aks_scale', supports_no_wait=True)
112-
g.command('delete', 'begin_delete',
113-
supports_no_wait=True, confirmation=True)
112+
g.custom_command('delete', 'aks_delete',
113+
supports_no_wait=True, confirmation=True)
114114
g.custom_show_command('show', 'aks_show',
115115
table_transformer=aks_show_table_format)
116116
g.custom_command('list', 'aks_list',

src/azure-cli/azure/cli/command_modules/acs/custom.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
CONST_VIRTUAL_MACHINES,
8181
)
8282
from azure.cli.command_modules.acs._polling import RunCommandLocationPolling
83-
from azure.cli.command_modules.acs._helpers import get_snapshot_by_snapshot_id, check_is_private_link_cluster
83+
from azure.cli.command_modules.acs._helpers import get_snapshot_by_snapshot_id, check_is_private_link_cluster, build_etag_kwargs
8484
from azure.cli.command_modules.acs._resourcegroup import get_rg_location
8585
from azure.cli.command_modules.acs.managednamespace import aks_managed_namespace_add, aks_managed_namespace_update
8686
from azure.cli.command_modules.acs._validators import extract_comma_separated_string
@@ -1357,7 +1357,7 @@ def aks_upgrade(cmd,
13571357
if active_cloud.profile != "latest":
13581358
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name, name, instance)
13591359

1360-
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name, name, instance, if_match=if_match, if_none_match=if_none_match)
1360+
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name, name, instance, **build_etag_kwargs(if_match, if_none_match))
13611361

13621362

13631363
def _update_upgrade_settings(cmd, instance,
@@ -1453,6 +1453,11 @@ def aks_scale(cmd, client, resource_group_name, name, node_count, nodepool_name=
14531453
raise CLIError('The nodepool "{}" was not found.'.format(nodepool_name))
14541454

14551455

1456+
def aks_delete(cmd, client, resource_group_name, name, no_wait=False, if_match=None, if_none_match=None):
1457+
return sdk_no_wait(no_wait, client.begin_delete, resource_group_name, name,
1458+
**build_etag_kwargs(if_match, if_none_match))
1459+
1460+
14561461
def aks_show(cmd, client, resource_group_name, name):
14571462
mc = client.get(resource_group_name, name)
14581463
return _remove_nulls([mc])[0]
@@ -1490,15 +1495,16 @@ def _remove_nulls(managed_clusters):
14901495
for managed_cluster in managed_clusters:
14911496
for attr in attrs:
14921497
if getattr(managed_cluster, attr, None) is None:
1493-
delattr(managed_cluster, attr)
1498+
managed_cluster.pop(attr, None)
14941499
if managed_cluster.agent_pool_profiles is not None:
14951500
for ap_profile in managed_cluster.agent_pool_profiles:
14961501
for attr in ap_attrs:
14971502
if getattr(ap_profile, attr, None) is None:
1498-
delattr(ap_profile, attr)
1499-
for attr in sp_attrs:
1500-
if getattr(managed_cluster.service_principal_profile, attr, None) is None:
1501-
delattr(managed_cluster.service_principal_profile, attr)
1503+
ap_profile.pop(attr, None)
1504+
if managed_cluster.service_principal_profile is not None:
1505+
for attr in sp_attrs:
1506+
if getattr(managed_cluster.service_principal_profile, attr, None) is None:
1507+
managed_cluster.service_principal_profile.pop(attr, None)
15021508
return managed_clusters
15031509

15041510

@@ -1835,14 +1841,14 @@ def aks_get_credentials(cmd, client, resource_group_name, name, admin=False,
18351841
if admin:
18361842
if cmd.cli_ctx.cloud.profile == "latest":
18371843
credentialResults = client.list_cluster_admin_credentials(
1838-
resource_group_name, name, serverType)
1844+
resource_group_name, name, server_fqdn=serverType)
18391845
else:
18401846
credentialResults = client.list_cluster_admin_credentials(
18411847
resource_group_name, name)
18421848
else:
18431849
if cmd.cli_ctx.cloud.profile == "latest":
18441850
credentialResults = client.list_cluster_user_credentials(
1845-
resource_group_name, name, serverType, credential_format)
1851+
resource_group_name, name, server_fqdn=serverType, format=credential_format)
18461852
else:
18471853
credentialResults = client.list_cluster_user_credentials(
18481854
resource_group_name, name)
@@ -3124,8 +3130,7 @@ def aks_agentpool_upgrade(cmd, client, resource_group_name, cluster_name,
31243130
nodepool_name,
31253131
instance,
31263132
headers=aks_custom_headers,
3127-
if_match=if_match,
3128-
if_none_match=if_none_match,
3133+
**build_etag_kwargs(if_match, if_none_match),
31293134
)
31303135

31313136

@@ -3140,7 +3145,7 @@ def aks_agentpool_scale(cmd, client, resource_group_name, cluster_name,
31403145
if new_node_count == instance.count:
31413146
raise CLIError(
31423147
"The new node count is the same as the current node count.")
3143-
if instance.type_properties_type == CONST_VIRTUAL_MACHINES:
3148+
if instance.properties.type_properties_type == CONST_VIRTUAL_MACHINES:
31443149
if len(instance.virtual_machines_profile.scale.manual) == 1:
31453150
instance.virtual_machines_profile.scale.manual[0].count = new_node_count
31463151
else:
@@ -3222,7 +3227,7 @@ def aks_agentpool_delete(cmd, client, resource_group_name, cluster_name,
32223227
if cmd.cli_ctx.cloud.profile != "latest":
32233228
return sdk_no_wait(no_wait, client.begin_delete, resource_group_name, cluster_name, nodepool_name)
32243229

3225-
return sdk_no_wait(no_wait, client.begin_delete, resource_group_name, cluster_name, nodepool_name, if_match=if_match, ignore_pod_disruption_budget=ignore_pdb)
3230+
return sdk_no_wait(no_wait, client.begin_delete, resource_group_name, cluster_name, nodepool_name, **build_etag_kwargs(if_match), ignore_pod_disruption_budget=ignore_pdb)
32263231

32273232

32283233
def aks_agentpool_operation_abort(cmd,
@@ -3324,7 +3329,7 @@ def aks_agentpool_manual_scale_add(cmd,
33243329
node_count,
33253330
no_wait=False):
33263331
instance = client.get(resource_group_name, cluster_name, nodepool_name)
3327-
if instance.type_properties_type != CONST_VIRTUAL_MACHINES:
3332+
if instance.properties.type_properties_type != CONST_VIRTUAL_MACHINES:
33283333
raise ClientRequestError("Cannot add manual to a non-virtualmachines node pool.")
33293334

33303335
ManualScaleProfile = cmd.get_models(
@@ -3361,7 +3366,7 @@ def aks_agentpool_manual_scale_update(cmd, # pylint: disable=unused-argument
33613366
raise RequiredArgumentMissingError("specify --vm-sizes or --node-count or both.")
33623367

33633368
instance = client.get(resource_group_name, cluster_name, nodepool_name)
3364-
if instance.type_properties_type != CONST_VIRTUAL_MACHINES:
3369+
if instance.properties.type_properties_type != CONST_VIRTUAL_MACHINES:
33653370
raise ClientRequestError("Cannot update manual in a non-virtualmachines node pool.")
33663371

33673372
_current_vm_sizes = [x.strip().lower() for x in current_vm_sizes.split(",")]
@@ -3402,7 +3407,7 @@ def aks_agentpool_manual_scale_delete(cmd, # pylint: disable=unused-argument
34023407
current_vm_sizes,
34033408
no_wait=False):
34043409
instance = client.get(resource_group_name, cluster_name, nodepool_name)
3405-
if instance.type_properties_type != CONST_VIRTUAL_MACHINES:
3410+
if instance.properties.type_properties_type != CONST_VIRTUAL_MACHINES:
34063411
raise CLIError("Cannot delete manual in a non-virtualmachines node pool.")
34073412

34083413
_current_vm_sizes = [x.strip().lower() for x in current_vm_sizes.split(",")]

0 commit comments

Comments
 (0)