Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/azure-cli/azure/cli/command_modules/acs/_completers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def get_k8s_versions_completion_list(cmd, prefix, namespace, **kwargs): # pylin

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask if this modification will change the output logic and cause a breaking change to customers?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a breaking change. Customers will not experience any interruptions.



@Completer
Expand Down
33 changes: 19 additions & 14 deletions src/azure-cli/azure/cli/command_modules/acs/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,17 @@ def find_preview_versions(versions_bag):
def aks_versions_table_format(result):
"""Format get-versions results as a summary for display with "-o table"."""

preview = {}

def find_preview_versions():
for orchestrator in result.get('orchestrators', []):
if orchestrator.get('isPreview', False):
preview[orchestrator['orchestratorVersion']] = True
find_preview_versions()
version_table = flatten_version_table(result.get("values", []))

parsed = compile_jmes("""orchestrators[].{
kubernetesVersion: orchestratorVersion | set_preview(@),
upgrades: upgrades[].orchestratorVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @)
parsed = compile_jmes("""[].{
kubernetesVersion: version,
isPreview: isPreview,
upgrades: upgrades || [`None available`] | sort_versions(@) | join(`, `, @)
}""")

# use ordered dicts so headers are predictable
results = parsed.search(result, Options(
dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))
return sorted(results, key=lambda x: version_to_tuple(x.get('kubernetesVersion')), reverse=True)
results = parsed.search(version_table, Options(
dict_cls=OrderedDict, custom_functions=_custom_functions({})))
return sorted(results, key=lambda x: version_to_tuple(x.get("kubernetesVersion")), reverse=True)


def aks_list_nodepool_snapshot_table_format(results):
Expand Down Expand Up @@ -150,6 +144,17 @@ def version_to_tuple(version):
return tuple(map(int, (version.split('.'))))


def flatten_version_table(release_info):
"""Flattens version table"""
flattened = []
for release in release_info:
isPreview = release.get("isPreview", False)
for k, v in release.get("patchVersions", {}).items():
item = {"version": k, "upgrades": v.get("upgrades", []), "isPreview": isPreview}
flattened.append(item)
return flattened


def _custom_functions(preview_versions):
class CustomFunctions(functions.Functions): # pylint: disable=too-few-public-methods

Expand Down
11 changes: 0 additions & 11 deletions src/azure-cli/azure/cli/command_modules/acs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from azure.cli.command_modules.acs._client_factory import (
cf_agent_pools,
cf_container_services,
cf_managed_clusters,
cf_snapshots,
)
Expand All @@ -27,14 +26,6 @@
# pylint: disable=too-many-statements
def load_command_table(self, _):

container_services_sdk = CliCommandType(
operations_tmpl='azure.mgmt.containerservice.operations.'
'_container_services_operations#ContainerServicesOperations.{}',
operation_group='container_services',
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
client_factory=cf_container_services
)

managed_clusters_sdk = CliCommandType(
operations_tmpl='azure.mgmt.containerservice.operations.'
'_managed_clusters_operations#ManagedClustersOperations.{}',
Expand Down Expand Up @@ -86,8 +77,6 @@ def load_command_table(self, _):
g.custom_command('use-dev-spaces', 'aks_use_dev_spaces', deprecate_info=g.deprecate())
g.custom_command('remove-dev-spaces', 'aks_remove_dev_spaces', deprecate_info=g.deprecate())
g.custom_command('operation-abort', 'aks_operation_abort', supports_no_wait=True)

with self.command_group('aks', container_services_sdk, client_factory=cf_container_services) as g:
g.custom_command('get-versions', 'aks_get_versions',
table_transformer=aks_versions_table_format)

Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ def aks_rotate_certs(cmd, client, resource_group_name, name, no_wait=True):


def aks_get_versions(cmd, client, location):
return client.list_orchestrators(location, resource_type='managedClusters')
return client.list_kubernetes_versions(location)


def aks_runcommand(cmd, client, resource_group_name, name, command_string="", command_files=None, no_wait=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_aks_create_default_setting(self, resource_group, resource_group_locatio
'dns_name_prefix': self.create_random_name('cliaksdns', 16),
'ssh_key_value': self.generate_ssh_keys().replace('\\', '\\\\'),
'location': resource_group_location,
'service_principal': _process_sp_name(sp_name),
'service_principal': sp_name,
'client_secret': sp_password,
'resource_type': 'Microsoft.ContainerService/ManagedClusters'
})
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_aks_nodepool_create_scale_delete(self, resource_group, resource_group_l
'dns_name_prefix': self.create_random_name('cliaksdns', 16),
'ssh_key_value': self.generate_ssh_keys().replace('\\', '\\\\'),
'location': resource_group_location,
'service_principal': _process_sp_name(sp_name),
'service_principal': sp_name,
'client_secret': sp_password,
'resource_type': 'Microsoft.ContainerService/ManagedClusters',
'tags': tags,
Expand Down Expand Up @@ -477,7 +477,7 @@ def generate_ppg_id(self, resource_group, location):
def _get_versions(self, location):
"""Return the previous and current Kubernetes minor release versions, such as ("1.11.6", "1.12.4")."""
versions = self.cmd(
"az aks get-versions -l westus2 --query 'orchestrators[].orchestratorVersion'").get_output_in_json()
"az aks get-versions -l westus2 --query 'values[*].patchVersions.keys(@)[]'").get_output_in_json()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary? To me, the recording file is not changed, so I guess without the change, the test could pass.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit test that has _get_versions is test_aks_create_service_no_wait which is live_only.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haitch can you confirm?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FumingZhang , I think I just did a search of "get-versions", and update here.

And, I am expecting this need to be updated as well, unless the hybrid test is something different.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, as the recording file for the hybrid version is not updated, I thought we may keep the test case unchanged. But CI has passed, shouldn't block the change.

# sort by semantic version, from newest to oldest
versions = sorted(versions, key=version_to_tuple, reverse=True)
upgrade_version = versions[0]
Expand Down
Loading