Skip to content

Commit

Permalink
[AKS] az aks mesh get-upgrades: Fix command failure with a tracebac…
Browse files Browse the repository at this point in the history
…k if ASM addon is disabled (#28507)
  • Loading branch information
deveshdama authored Mar 7, 2024
1 parent 144101c commit c0e82c8
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2833,23 +2833,32 @@ def aks_mesh_get_revisions(
return None


def check_iterator(iterator):
import itertools
try:
first = next(iterator)
except StopIteration: # iterator is empty
return True, iterator
except TypeError: # iterator is not iterable, e.g. None
return True, iterator
return False, itertools.chain([first], iterator)


def aks_mesh_get_upgrades(
cmd,
client,
resource_group_name,
name
):
upgradeProfiles = client.list_mesh_upgrade_profiles(resource_group_name, name)
# 'upgradeProfiles' is an ItemPaged object
upgrades = []
# Iterate over items within pages
for page in upgradeProfiles.by_page():
for item in page:
upgrades.append(item)

if upgrades:
return upgrades[0].properties

is_empty, upgradeProfiles = check_iterator(upgradeProfiles)
if is_empty:
logger.warning("No mesh upgrade profiles found for the cluster '%s' " +
"in the resource group '%s'.", name, resource_group_name)
return None
upgrade = next(upgradeProfiles, None)
if upgrade:
return upgrade.properties
return None


Expand Down

0 comments on commit c0e82c8

Please sign in to comment.