From b5c1f62088778287e4b50aeac1f17d166a7a177a Mon Sep 17 00:00:00 2001 From: Dan Voiculeasa Date: Wed, 3 Feb 2021 16:00:47 +0200 Subject: [PATCH] Introduce metadata for app behavior control Keep existing behavior when evaluating app reapplies. Story: 2007960 Task: 41755 Signed-off-by: Dan Voiculeasa Change-Id: Ie02743cdf056dda3feb66911c74f9dabe69d98dd --- .../lifecycle/lifecycle_openstack.py | 55 +++++++++++++++++++ .../stx-openstack-helm/files/metadata.yaml | 15 +++++ 2 files changed, 70 insertions(+) diff --git a/python-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/lifecycle/lifecycle_openstack.py b/python-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/lifecycle/lifecycle_openstack.py index 4772ecef..09e879e4 100644 --- a/python-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/lifecycle/lifecycle_openstack.py +++ b/python-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/lifecycle/lifecycle_openstack.py @@ -73,6 +73,12 @@ class OpenstackAppLifecycleOperator(base.AppLifecycleOperator): hook_info.relative_timing == constants.APP_LIFECYCLE_TIMING_POST: return lifecycle_utils.delete_rbd_provisioner_secrets(app_op, app, hook_info) + # Semantic checks + elif hook_info.lifecycle_type == constants.APP_LIFECYCLE_TYPE_SEMANTIC_CHECK: + if hook_info.mode == constants.APP_LIFECYCLE_MODE_AUTO and \ + hook_info.operation == constants.APP_EVALUATE_REAPPLY_OP: + return self._semantic_check_evaluate_app_reapply(app_op, app, hook_info) + # Default behavior super(OpenstackAppLifecycleOperator, self).app_lifecycle_actions(context, conductor_obj, app_op, app, hook_info) @@ -225,3 +231,52 @@ class OpenstackAppLifecycleOperator(base.AppLifecycleOperator): except Exception as e: LOG.error(e) raise + + def _semantic_check_evaluate_app_reapply(self, app_op, app, hook_info): + """Semantic check for evaluating app reapply + + This is an example of how to use the evaluate reapply semantic check. + The same behavior could have been achieved by placing a filter in the metadata + based on LifecycleConstants.TRIGGER_CONFIGURE_REQUIRED + + Example of equivalent behavior by adding filters to triggers in metadata: + --- + behavior: + evaluate_reapply: + triggers: + - type: unlock + filters: # This line was added + - configure_required: True # This line was added + - type: force-unlock + filters: # This line was added + - configure_required: True # This line was added + + :param app_op: AppOperator object + :param app: AppOperator.Application object + :param hook_info: LifecycleHookInfo object + + """ + if LifecycleConstants.EVALUATE_REAPPLY_TRIGGER not in hook_info[LifecycleConstants.EXTRA]: + raise exception.LifecycleMissingInfo( + "Missing {}".format(LifecycleConstants.EVALUATE_REAPPLY_TRIGGER)) + trigger = hook_info[LifecycleConstants.EXTRA][LifecycleConstants.EVALUATE_REAPPLY_TRIGGER] + + if LifecycleConstants.TRIGGER_TYPE not in trigger: + raise exception.LifecycleMissingInfo( + "Missing {} {}".format(LifecycleConstants.EVALUATE_REAPPLY_TRIGGER, + LifecycleConstants.TRIGGER_TYPE)) + + # At the moment of writing this focus is on keeping backwards compatibility + # The logic was extracted and kept as it was + if trigger[LifecycleConstants.TRIGGER_TYPE] in [constants.UNLOCK_ACTION, constants.FORCE_UNLOCK_ACTION]: + if LifecycleConstants.TRIGGER_CONFIGURE_REQUIRED not in trigger: + raise exception.LifecycleMissingInfo( + "Missing {} {}".format(LifecycleConstants.EVALUATE_REAPPLY_TRIGGER, + LifecycleConstants.TRIGGER_CONFIGURE_REQUIRED)) + + # For an unlock, the logic had 'configure_required' set to True + if not trigger[LifecycleConstants.TRIGGER_CONFIGURE_REQUIRED]: + raise exception.LifecycleSemanticCheckException( + "Trigger type {} expects {} to be true".format( + trigger[LifecycleConstants.TRIGGER_TYPE], + LifecycleConstants.TRIGGER_CONFIGURE_REQUIRED)) diff --git a/stx-openstack-helm/stx-openstack-helm/files/metadata.yaml b/stx-openstack-helm/stx-openstack-helm/files/metadata.yaml index 28bcc294..08366240 100644 --- a/stx-openstack-helm/stx-openstack-helm/files/metadata.yaml +++ b/stx-openstack-helm/stx-openstack-helm/files/metadata.yaml @@ -6,3 +6,18 @@ disabled_charts: - gnocchi - ironic - panko +behavior: + platform_managed_app: yes + evaluate_reapply: + after: + - platform-integ-apps + triggers: + - type: unlock + - type: force-unlock + - type: runtime-apply-puppet + - type: host-availability-updated + filters: + - availability: services-enabled + - type: host-delete + filters: + - openstack_worker: True