Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed az containerapp revision label swap --labels to --source-label, target-label. #123

Merged
merged 2 commits into from
Jun 6, 2022
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
4 changes: 2 additions & 2 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@
type: command
short-summary: Swap a revision label between two revisions with associated traffic weights.
examples:
- name: Swap a revision label between two revisions..
- name: Swap a revision label between two revisions.
text: |
az containerapp revision label swap -n MyContainerapp -g MyResourceGroup --labels myLabel1 myLabel2
az containerapp revision label swap -n MyContainerapp -g MyResourceGroup --source myLabel1 --target myLabel2
"""

# Environment Commands
Expand Down
3 changes: 2 additions & 1 deletion src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ def load_arguments(self, _):
c.argument('yes', options_list=['--yes', '-y'], help='Do not prompt for confirmation.')

with self.argument_context('containerapp revision label') as c:
c.argument('labels', nargs='*', help='Labels to be swapped.')
c.argument('source_label', options_list=['--source'], help='Source label to be swapped.')
c.argument('target_label', options_list=['--target'], help='Target label to be swapped to.')

with self.argument_context('containerapp ingress') as c:
c.argument('allow_insecure', help='Allow insecure connections for ingress traffic.')
Expand Down
39 changes: 18 additions & 21 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,13 +1445,10 @@ def add_revision_label(cmd, resource_group_name, revision, label, name=None, no_
handle_raw_exception(e)


def swap_revision_label(cmd, name, resource_group_name, labels, no_wait=False):
def swap_revision_label(cmd, name, resource_group_name, source_label, target_label, no_wait=False):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)

if not labels or len(labels) != 2:
raise ArgumentUsageError("Usage error: --labels requires two labels to be swapped.")

if labels[0] == labels[1]:
if source_label == target_label:
raise ArgumentUsageError("Label names to be swapped must be different.")

containerapp_def = None
Expand All @@ -1468,24 +1465,24 @@ def swap_revision_label(cmd, name, resource_group_name, labels, no_wait=False):

traffic_weight = containerapp_def['properties']['configuration']['ingress']['traffic'] if 'traffic' in containerapp_def['properties']['configuration']['ingress'] else {}

label1_found = False
label2_found = False
source_label_found = False
target_label_found = False
for weight in traffic_weight:
if "label" in weight:
if weight["label"].lower() == labels[0].lower():
if not label1_found:
label1_found = True
weight["label"] = labels[1]
elif weight["label"].lower() == labels[1].lower():
if not label2_found:
label2_found = True
weight["label"] = labels[0]
if not label1_found and not label2_found:
raise ArgumentUsageError(f"Could not find label '{labels[0]}' nor label '{labels[1]}' in traffic.")
if not label1_found:
raise ArgumentUsageError(f"Could not find label '{labels[0]}' in traffic.")
if not label2_found:
raise ArgumentUsageError(f"Could not find label '{labels[1]}' in traffic.")
if weight["label"].lower() == source_label.lower():
if not source_label_found:
source_label_found = True
weight["label"] = target_label
elif weight["label"].lower() == target_label.lower():
if not target_label_found:
target_label_found = True
weight["label"] = source_label
if not source_label_found and not target_label_found:
raise ArgumentUsageError(f"Could not find label '{source_label}' nor label '{target_label}' in traffic.")
if not source_label_found:
raise ArgumentUsageError(f"Could not find label '{source_label}' in traffic.")
if not target_label_found:
raise ArgumentUsageError(f"Could not find label '{target_label}' in traffic.")

containerapp_patch_def = {}
containerapp_patch_def['properties'] = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def test_containerapp_revision_label_e2e(self, resource_group):
else:
self.assertEqual(traffic["weight"], 50)

traffic_weight = self.cmd(f"containerapp revision label swap -g {resource_group} -n {ca_name} --labels {labels[0]} {labels[1]}").get_output_in_json()
traffic_weight = self.cmd(f"containerapp revision label swap -g {resource_group} -n {ca_name} --source {labels[0]} --target {labels[1]}").get_output_in_json()

for revision in revision_names:
traffic = [w for w in traffic_weight if "revisionName" in w and w["revisionName"] == revision][0]
Expand Down