From 74bb9d3bc17d556b7567d7aece1ee45ea8fb9eae Mon Sep 17 00:00:00 2001 From: Erickson Silva de Oliveira Date: Tue, 23 May 2023 19:38:10 +0000 Subject: [PATCH] Create lifecycle hook on application recovery There was no lifecycle hook during recovery. Thus, in platform-integ-apps it was not possible to identify when this happened. To solve this, a new operation constant was created and the lifecycle hook was triggered inside _perform_app_recover(). Test Plan: PASS: When forcing recovery, it was possible to observe the lifecycle with the "recover" operation (SX/DX/Storage) Story: 2010688 Task: 48081 Change-Id: I44447ca2246a8461d98f8ea64e2e16c127c357a6 Signed-off-by: Erickson Silva de Oliveira --- .../sysinv/sysinv/sysinv/common/constants.py | 1 + .../sysinv/sysinv/conductor/kube_app.py | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/sysinv/sysinv/sysinv/sysinv/common/constants.py b/sysinv/sysinv/sysinv/sysinv/common/constants.py index 4fe5836933..eb1fb86c8f 100644 --- a/sysinv/sysinv/sysinv/sysinv/common/constants.py +++ b/sysinv/sysinv/sysinv/sysinv/common/constants.py @@ -1824,6 +1824,7 @@ APP_APPLY_OP = 'apply' APP_REMOVE_OP = 'remove' APP_DELETE_OP = 'delete' APP_UPDATE_OP = 'update' +APP_RECOVER_OP = 'recover' APP_ROLLBACK_OP = 'rollback' APP_ABORT_OP = 'abort' APP_EVALUATE_REAPPLY_OP = 'evaluate-reapply' diff --git a/sysinv/sysinv/sysinv/sysinv/conductor/kube_app.py b/sysinv/sysinv/sysinv/sysinv/conductor/kube_app.py index bb9ac87cca..b7f1b6017c 100644 --- a/sysinv/sysinv/sysinv/sysinv/conductor/kube_app.py +++ b/sysinv/sysinv/sysinv/sysinv/conductor/kube_app.py @@ -1692,7 +1692,9 @@ class AppOperator(object): with self._lock: from_app.update_app_metadata(new_metadata) - def _perform_app_recover(self, old_app, new_app, fluxcd_process_required=True): + def _perform_app_recover(self, rpc_app, old_app, new_app, + lifecycle_hook_info_app, + fluxcd_process_required=True): """Perform application recover This recover method is triggered when application update failed, it cleans @@ -1703,8 +1705,10 @@ class AppOperator(object): The app status will be populated to "apply-failed" if recover fails so that the user can re-apply app. + :param rpc_app: application object in the RPC request :param old_app: the application object that application recovering to :param new_app: the application object that application recovering from + :param lifecycle_hook_info_app: LifecycleHookInfo object :param fluxcd_process_required: boolean, whether fluxcd operation is needed """ @@ -1733,6 +1737,15 @@ class AppOperator(object): version=new_app.version, inactive=True) + lifecycle_hook_info_app_recover = copy.deepcopy(lifecycle_hook_info_app) + lifecycle_hook_info_app_recover.operation = constants.APP_RECOVER_OP + + lifecycle_hook_info_app_recover.lifecycle_type = constants.APP_LIFECYCLE_TYPE_RBD + self.app_lifecycle_actions(None, None, rpc_app, lifecycle_hook_info_app_recover) + + lifecycle_hook_info_app_recover.lifecycle_type = constants.APP_LIFECYCLE_TYPE_RESOURCE + self.app_lifecycle_actions(None, None, rpc_app, lifecycle_hook_info_app_recover) + LOG.info("Recovering helm charts for Application %s (%s)..." % (old_app.name, old_app.version)) self._update_app_status(old_app, @@ -2660,14 +2673,14 @@ class AppOperator(object): except exception.LifecycleSemanticCheckException as e: LOG.info("App {} rejected operation {} for reason: {}" "".format(to_app.name, constants.APP_UPDATE_OP, str(e))) - # lifecycle hooks not used in perform_app_recover - return self._perform_app_recover(from_app, to_app, + return self._perform_app_recover(to_rpc_app, from_app, to_app, + lifecycle_hook_info_app_update, fluxcd_process_required=False) except Exception as e: LOG.error("App {} operation {} semantic check error: {}" "".format(to_app.name, constants.APP_UPDATE_OP, str(e))) - # lifecycle hooks not used in perform_app_recover - return self._perform_app_recover(from_app, to_app, + return self._perform_app_recover(to_rpc_app, from_app, to_app, + lifecycle_hook_info_app_update, fluxcd_process_required=False) self.load_application_metadata_from_file(to_rpc_app) @@ -2736,9 +2749,8 @@ class AppOperator(object): if do_recovery: LOG.error("Application %s update from version %s to version " "%s aborted." % (to_app.name, from_app.version, to_app.version)) - - # lifecycle hooks not used in perform_app_recover - return self._perform_app_recover(from_app, to_app) + return self._perform_app_recover(to_rpc_app, from_app, to_app, + lifecycle_hook_info_app_update) self._update_app_status(to_app, constants.APP_UPDATE_IN_PROGRESS, "cleanup application version {}".format(from_app.version)) @@ -2799,8 +2811,8 @@ class AppOperator(object): # ie.images download/k8s resource creation failure # Start recovering without trigger fluxcd process LOG.exception(e) - # lifecycle hooks not used in perform_app_recover - return self._perform_app_recover(from_app, to_app, + return self._perform_app_recover(to_rpc_app, from_app, to_app, + lifecycle_hook_info_app_update, fluxcd_process_required=False) except Exception as e: # Application update successfully(fluxcd apply/rollback)