Skip to content

Commit

Permalink
Pass more context to apps when doing app operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Qubad786 committed Jul 29, 2024
1 parent f886f3a commit 07eb1e4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/middlewared/middlewared/plugins/apps/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def do_create(self, job, data):
app_version_details = self.middleware.call_sync(
'catalog.app_version_details', get_installed_app_version_path(app_name, version)
)
new_values = add_context_to_values(app_name, new_values, install=True)
new_values = add_context_to_values(app_name, new_values, app_version_details['app_metadata'], install=True)
update_app_config(app_name, version, new_values)
update_app_metadata(app_name, app_version_details)

Expand Down Expand Up @@ -239,7 +239,7 @@ def update_internal(self, job, app, data, progress_keyword='Update'):

job.set_progress(25, 'Initial Validation completed')

new_values = add_context_to_values(app_name, new_values, update=True)
new_values = add_context_to_values(app_name, new_values, app['metadata'], update=True)
update_app_config(app_name, app['version'], new_values)
update_app_metadata_for_portals(app_name, app['version'])
job.set_progress(60, 'Configuration updated, updating docker resources')
Expand Down
6 changes: 4 additions & 2 deletions src/middlewared/middlewared/plugins/apps/ix_apps/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ def get_action_context(app_name: str) -> dict[str, typing.Any]:
'is_upgrade': False,
'upgrade_metadata': {},
'app_name': app_name,
'app_metadata': {},
})


def add_context_to_values(
app_name: str, values: dict[str, typing.Any], *, install: bool = False, update: bool = False, upgrade: bool = False,
upgrade_metadata: dict[str, typing.Any] = None, rollback: bool = False,
app_name: str, values: dict[str, typing.Any], app_metadata: dict, *, install: bool = False, update: bool = False,
upgrade: bool = False, upgrade_metadata: dict[str, typing.Any] = None, rollback: bool = False,
) -> dict[str, typing.Any]:
assert install or update or upgrade or rollback, 'At least one of install, update, rollback or upgrade must be True'
assert sum([install, rollback, update, upgrade]) <= 1, 'Only one of install, update, or upgrade can be True.'
Expand All @@ -77,6 +78,7 @@ def add_context_to_values(
for operation, _ in filter(lambda i: i[1], operation_map.items()):
action_context.update({
'operation': operation,
'app_metadata': app_metadata,
f'is_{operation.lower()}': True,
**({'upgrade_metadata': upgrade_metadata} if operation == 'UPGRADE' else {})
})
Expand Down
2 changes: 1 addition & 1 deletion src/middlewared/middlewared/plugins/apps/rollback.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def rollback(self, job, app_name, options):
'app.schema.normalize_and_validate_values', rollback_version, config, False,
get_installed_app_path(app_name), app,
)
new_values = add_context_to_values(app_name, new_values, rollback=True)
new_values = add_context_to_values(app_name, new_values, rollback_version['app_metadata'], rollback=True)
update_app_config(app_name, options['app_version'], new_values)

job.set_progress(
Expand Down
12 changes: 8 additions & 4 deletions src/middlewared/middlewared/plugins/apps/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ def upgrade(self, job, app_name, options):
# 5) Docker should be notified to recreate resources and to let upgrade to commence
# 6) Update collective metadata config to reflect new version
# 7) Finally create ix-volumes snapshot for rollback
with upgrade_config(app_name, upgrade_version) as version_path:
with upgrade_config(app_name, upgrade_version):
config = get_current_app_config(app_name, app['version'])
config.update(options['values'])
app_version_details = self.middleware.call_sync('catalog.app_version_details', version_path)
new_values = self.middleware.call_sync(
'app.schema.normalize_and_validate_values', app_version_details, config, False,
'app.schema.normalize_and_validate_values', upgrade_version, config, False,
get_installed_app_path(app_name), app,
)
new_values = add_context_to_values(app_name, new_values, upgrade=True, upgrade_metadata={})
new_values = add_context_to_values(
app_name, new_values, upgrade_version['app_metadata'], upgrade=True, upgrade_metadata={
'old_version_metadata': app['metadata'],
'new_version_metadata': upgrade_version['app_metadata'],
}
)
update_app_config(app_name, upgrade_version['version'], new_values)

job.set_progress(40, f'Configuration updated for {app_name!r}, upgrading app')
Expand Down

0 comments on commit 07eb1e4

Please sign in to comment.