Add helmrelease patch action for app update

It was found that during the update process, after the
helmrelease is uninstalled, the FluxCD would automatically
redeploy the helmrelease that was uninstalled because of
the reconcile function of FluxCD.

To prevent this, this review adds a step to patch the helmrelease
and inform FluxCD that the Helm release is not to be reconciled.

Also, it was changed the moment where the cleanup function is called.
Before, it was being called as soon as the application apply began.
Now it will begin after the process of downloading the docker images
is finished. This will dimish the downtime and if the download failed
the application would not be down at any time.

Test Plan:
PASS - Build python3-k8sapp-openstack package
PASS - Build STX-Openstack tarball
PASS - Run system application-update
PASS - Application updated to 25.03

Story: 2011262
Task: 51657

Change-Id: I8fa90c7167f856df47d10a9fb55fcea08cb18ab6
Signed-off-by: Daniel Caires <DanielMarques.Caires@windriver.com>
This commit is contained in:
Daniel Caires 2025-02-20 13:23:51 -03:00 committed by Daniel Marques Caires
parent 4da08389e8
commit f205fa6d3e
2 changed files with 48 additions and 5 deletions

View File

@ -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)

View File

@ -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}")