Skip to content

Commit a1eb101

Browse files
committed
Avoid upgrade resource in app refresh if upstream has same res revision
Fixes #883
1 parent 434a080 commit a1eb101

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
@@ -749,11 +749,22 @@ async def refresh(
749749
}
750750

751751
# Compute the difference btw resources needed and the existing resources
752-
resources_to_update = [
753-
resource for resource in charm_resources
754-
if resource.get('Name', resource.get('name')) not in existing_resources or
755-
existing_resources[resource.get('Name', resource.get('name'))].origin != 'upload'
756-
]
752+
resources_to_update = []
753+
for resource in charm_resources:
754+
# should upgrade resource?
755+
res_name = resource.get('Name', resource.get('name'))
756+
# no, if it's upload
757+
if existing_resources[res_name].origin == 'upload':
758+
continue
759+
760+
# no, if we already have it (and upstream doesn't have a newer res available)
761+
if res_name in existing_resources:
762+
available_rev = resource['revision']
763+
existing_rev = existing_resources[res_name].unknown_fields.get('revision', -1)
764+
if existing_rev >= available_rev:
765+
continue
766+
767+
resources_to_update.append(resource)
757768

758769
# Update the resources
759770
if resources_to_update:

0 commit comments

Comments
 (0)