diff --git a/python3-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/lifecycle/lifecycle_openstack.py b/python3-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/lifecycle/lifecycle_openstack.py index 7094aa71..7665d69e 100644 --- a/python3-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/lifecycle/lifecycle_openstack.py +++ b/python3-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/lifecycle/lifecycle_openstack.py @@ -86,10 +86,12 @@ class OpenstackAppLifecycleOperator(base.AppLifecycleOperator): hook_info.operation == constants.APP_APPLY_OP and \ hook_info.relative_timing == constants.APP_LIFECYCLE_TIMING_PRE: return self._pre_manual_apply_check(conductor_obj, app, hook_info) - elif hook_info.mode == constants.APP_LIFECYCLE_MODE_MANUAL and \ - hook_info.operation == constants.APP_UPDATE_OP and \ - hook_info.relative_timing == constants.APP_LIFECYCLE_TIMING_PRE: - return self._pre_update_cleanup_actions(hook_info) + + # Manifest + elif hook_info.lifecycle_type == constants.APP_LIFECYCLE_TYPE_MANIFEST: + if hook_info.operation == constants.APP_APPLY_OP and \ + hook_info.relative_timing == constants.APP_LIFECYCLE_TIMING_PRE: + return self._pre_update_cleanup_actions() # Default behavior super(OpenstackAppLifecycleOperator, self).app_lifecycle_actions(context, conductor_obj, app_op, app, @@ -413,11 +415,18 @@ class OpenstackAppLifecycleOperator(base.AppLifecycleOperator): if group_exists: ldap.delete_group(app_constants.CLIENTS_WORKING_DIR_GROUP) - def _pre_update_cleanup_actions(self, hook_info): + def _pre_update_cleanup_actions(self): """Perform pre update cleanup actions.""" # TODO: Remove in the future. This code is only necessary when # updating from stx-10 to stx-11 STX-O release. + release = 'ingress' + patch = {"spec": {"suspend": True}} + + # Update helmrelease to not reconcile during update + app_utils.update_helmrelease(release, patch) + + # Uninstall helm release. status = helm_utils.delete_helm_release( release='osh-openstack-ingress', namespace=app_constants.HELM_NS_OPENSTACK) LOG.info(status) diff --git a/python3-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/utils.py b/python3-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/utils.py index 2771f07d..c858403a 100644 --- a/python3-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/utils.py +++ b/python3-k8sapp-openstack/k8sapp_openstack/k8sapp_openstack/utils.py @@ -5,6 +5,7 @@ # from grp import getgrnam +import json import os from pathlib import Path from pwd import getpwnam @@ -572,3 +573,36 @@ def is_openvswitch_enabled(hosts, labels_by_hostid) -> bool: LOG.debug(f"Openvswitch label not found for host {host.id}") LOG.info("Openvswitch is not enabled on any of the hosts.") return False + + +def update_helmrelease(release, patch): + """ + Update the Helmrelease of a Helm chart. + + Args: + release (str): The name of the Helmrelease to update. + patch (dict): Patch to apply to the Helmrelease. + """ + + cmd = [ + "kubectl", "--kubeconfig", kubernetes.KUBERNETES_ADMIN_CONF, + "patch", "helmrelease", release, + "-n", app_constants.HELM_NS_OPENSTACK, + "--type", "merge", + "-p", json.dumps(patch) + ] + + try: + process = subprocess.run( + args=cmd, + capture_output=True, + text=True, + shell=False) + + LOG.info(f"Stdout: {process.stdout}") + LOG.info(f"Stderr: {process.stderr}") + process.check_returncode() + except KubeApiException as e: + LOG.error(f"Failed to update helmrelease: {release}, with error: {e}") + except Exception as e: + LOG.error(f"Unexpected error while updating helmrelease: {e}")