Skip to content

Commit b54a876

Browse files
committed
Avoid upgrade resource in app refresh if upstream has same res revision
Fixes #883
1 parent 7a70f97 commit b54a876

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

juju/application.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,22 @@ async def refresh(
740740
}
741741

742742
# Compute the difference btw resources needed and the existing resources
743-
resources_to_update = [
744-
resource for resource in charm_resources
745-
if resource.get('Name', resource.get('name')) not in existing_resources or
746-
existing_resources[resource.get('Name', resource.get('name'))].origin != 'upload'
747-
]
743+
resources_to_update = []
744+
for resource in charm_resources:
745+
# should upgrade resource?
746+
res_name = resource.get('Name', resource.get('name'))
747+
# no, if it's upload
748+
if existing_resources[res_name].origin == 'upload':
749+
continue
750+
751+
# no, if we already have it (and upstream doesn't have a newer res available)
752+
if res_name in existing_resources:
753+
available_rev = resource['revision']
754+
existing_rev = existing_resources[res_name].unknown_fields.get('revision', -1)
755+
if existing_rev >= available_rev:
756+
continue
757+
758+
resources_to_update.append(resource)
748759

749760
# Update the resources
750761
if resources_to_update:

0 commit comments

Comments
 (0)