Skip to content

Commit 13fd369

Browse files
authored
{AKS} az aks get-versions: get-versions using newer backend api (#26702)
1 parent d4b27cb commit 13fd369

128 files changed

Lines changed: 71475 additions & 63103 deletions

File tree

Some content is hidden

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ def get_k8s_versions_completion_list(cmd, prefix, namespace, **kwargs): # pylin
3131

3232
def get_k8s_versions(cli_ctx, location):
3333
"""Return a list of Kubernetes versions available for a new cluster."""
34-
from azure.cli.command_modules.acs._client_factory import cf_container_services
34+
from azure.cli.command_modules.acs._client_factory import cf_managed_clusters
3535
from jmespath import search
3636

37-
results = cf_container_services(cli_ctx).list_orchestrators(location, resource_type='managedClusters').as_dict()
37+
results = cf_managed_clusters(cli_ctx).list_kubernetes_versions(location).as_dict()
3838
# Flatten all the "orchestrator_version" fields into one array
39-
return search('orchestrators[*].orchestrator_version', results)
39+
return search("values[*].patchVersions.keys(@)[]", results)
4040

4141

4242
@Completer

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,17 @@ def find_preview_versions(versions_bag):
100100
def aks_versions_table_format(result):
101101
"""Format get-versions results as a summary for display with "-o table"."""
102102

103-
preview = {}
104-
105-
def find_preview_versions():
106-
for orchestrator in result.get('orchestrators', []):
107-
if orchestrator.get('isPreview', False):
108-
preview[orchestrator['orchestratorVersion']] = True
109-
find_preview_versions()
103+
version_table = flatten_version_table(result.get("values", []))
110104

111-
parsed = compile_jmes("""orchestrators[].{
112-
kubernetesVersion: orchestratorVersion | set_preview(@),
113-
upgrades: upgrades[].orchestratorVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @)
105+
parsed = compile_jmes("""[].{
106+
kubernetesVersion: version,
107+
isPreview: isPreview,
108+
upgrades: upgrades || [`None available`] | sort_versions(@) | join(`, `, @)
114109
}""")
115-
116110
# use ordered dicts so headers are predictable
117-
results = parsed.search(result, Options(
118-
dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))
119-
return sorted(results, key=lambda x: version_to_tuple(x.get('kubernetesVersion')), reverse=True)
111+
results = parsed.search(version_table, Options(
112+
dict_cls=OrderedDict, custom_functions=_custom_functions({})))
113+
return sorted(results, key=lambda x: version_to_tuple(x.get("kubernetesVersion")), reverse=True)
120114

121115

122116
def aks_list_nodepool_snapshot_table_format(results):
@@ -150,6 +144,17 @@ def version_to_tuple(version):
150144
return tuple(map(int, (version.split('.'))))
151145

152146

147+
def flatten_version_table(release_info):
148+
"""Flattens version table"""
149+
flattened = []
150+
for release in release_info:
151+
isPreview = release.get("isPreview", False)
152+
for k, v in release.get("patchVersions", {}).items():
153+
item = {"version": k, "upgrades": v.get("upgrades", []), "isPreview": isPreview}
154+
flattened.append(item)
155+
return flattened
156+
157+
153158
def _custom_functions(preview_versions):
154159
class CustomFunctions(functions.Functions): # pylint: disable=too-few-public-methods
155160

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from azure.cli.command_modules.acs._client_factory import (
77
cf_agent_pools,
8-
cf_container_services,
98
cf_managed_clusters,
109
cf_snapshots,
1110
)
@@ -27,14 +26,6 @@
2726
# pylint: disable=too-many-statements
2827
def load_command_table(self, _):
2928

30-
container_services_sdk = CliCommandType(
31-
operations_tmpl='azure.mgmt.containerservice.operations.'
32-
'_container_services_operations#ContainerServicesOperations.{}',
33-
operation_group='container_services',
34-
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
35-
client_factory=cf_container_services
36-
)
37-
3829
managed_clusters_sdk = CliCommandType(
3930
operations_tmpl='azure.mgmt.containerservice.operations.'
4031
'_managed_clusters_operations#ManagedClustersOperations.{}',
@@ -86,8 +77,6 @@ def load_command_table(self, _):
8677
g.custom_command('use-dev-spaces', 'aks_use_dev_spaces', deprecate_info=g.deprecate())
8778
g.custom_command('remove-dev-spaces', 'aks_remove_dev_spaces', deprecate_info=g.deprecate())
8879
g.custom_command('operation-abort', 'aks_operation_abort', supports_no_wait=True)
89-
90-
with self.command_group('aks', container_services_sdk, client_factory=cf_container_services) as g:
9180
g.custom_command('get-versions', 'aks_get_versions',
9281
table_transformer=aks_versions_table_format)
9382

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,7 @@ def aks_rotate_certs(cmd, client, resource_group_name, name, no_wait=True):
17681768

17691769

17701770
def aks_get_versions(cmd, client, location):
1771-
return client.list_orchestrators(location, resource_type='managedClusters')
1771+
return client.list_kubernetes_versions(location)
17721772

17731773

17741774
def aks_runcommand(cmd, client, resource_group_name, name, command_string="", command_files=None, no_wait=False):

src/azure-cli/azure/cli/command_modules/acs/tests/hybrid_2020_09_01/test_aks_commands.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def test_aks_create_default_setting(self, resource_group, resource_group_locatio
173173
'dns_name_prefix': self.create_random_name('cliaksdns', 16),
174174
'ssh_key_value': self.generate_ssh_keys().replace('\\', '\\\\'),
175175
'location': resource_group_location,
176-
'service_principal': _process_sp_name(sp_name),
176+
'service_principal': sp_name,
177177
'client_secret': sp_password,
178178
'resource_type': 'Microsoft.ContainerService/ManagedClusters'
179179
})
@@ -266,7 +266,7 @@ def test_aks_nodepool_create_scale_delete(self, resource_group, resource_group_l
266266
'dns_name_prefix': self.create_random_name('cliaksdns', 16),
267267
'ssh_key_value': self.generate_ssh_keys().replace('\\', '\\\\'),
268268
'location': resource_group_location,
269-
'service_principal': _process_sp_name(sp_name),
269+
'service_principal': sp_name,
270270
'client_secret': sp_password,
271271
'resource_type': 'Microsoft.ContainerService/ManagedClusters',
272272
'tags': tags,
@@ -477,7 +477,7 @@ def generate_ppg_id(self, resource_group, location):
477477
def _get_versions(self, location):
478478
"""Return the previous and current Kubernetes minor release versions, such as ("1.11.6", "1.12.4")."""
479479
versions = self.cmd(
480-
"az aks get-versions -l westus2 --query 'orchestrators[].orchestratorVersion'").get_output_in_json()
480+
"az aks get-versions -l westus2 --query 'values[*].patchVersions.keys(@)[]'").get_output_in_json()
481481
# sort by semantic version, from newest to oldest
482482
versions = sorted(versions, key=version_to_tuple, reverse=True)
483483
upgrade_version = versions[0]

0 commit comments

Comments
 (0)