From 7f0341759ad2a20bf4c99cfa81ed7c53ae1795bb Mon Sep 17 00:00:00 2001 From: Igor Soares Date: Fri, 18 Aug 2023 16:50:17 -0300 Subject: [PATCH] Drop helmv2 database after Armada removal This change adds a function to the Armada removal script that runs during platform upgrades giving it the ability to remove the helmv2 database if no Armada apps are present. Helm v2 is not supported anymore so its database should be dropped alongside the removal of Armada as no other platform components will make use of it. Test Plan: PASS: build-pkgs && build-image PASS: SX upgrade from stx-8 to master Check if helmv2 database was removed Story: 48480 Task: 2010560 Change-Id: I3c6489643bcf608893b8715f4d3c4a45c72e03ec Signed-off-by: Igor Soares --- .../76-remove-armada-if-unused.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/controllerconfig/controllerconfig/upgrade-scripts/76-remove-armada-if-unused.py b/controllerconfig/controllerconfig/upgrade-scripts/76-remove-armada-if-unused.py index e9e1c2e0e0..e9bbe91653 100644 --- a/controllerconfig/controllerconfig/upgrade-scripts/76-remove-armada-if-unused.py +++ b/controllerconfig/controllerconfig/upgrade-scripts/76-remove-armada-if-unused.py @@ -336,6 +336,39 @@ def remove_docker_images(): return True +def drop_helm_v2_database(): + """ + Drop Helm v2 PostgreSQL database since it is not needed + after Armada removal. + """ + + env = os.environ.copy() + drop_database = subprocess.Popen( + ['sudo', '-u', 'postgres', + 'psql', '-c', + 'DROP DATABASE IF EXISTS helmv2'], + env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + universal_newlines=True) + timer = threading.Timer(20, kill_process_and_descendants, [drop_database]) + + try: + timer.start() + _, err = drop_database.communicate() + if drop_database.returncode != 0 and err: + LOG.exception(err) + return False + elif drop_database.returncode != 0: + LOG.error("Unknown error while dropping helmv2 database") + return False + except Exception as e: + LOG.exception("Failed to drop helmv2 database: %s" % e) + return False + finally: + timer.cancel() + + return True + + def main(): if len(sys.argv) != 4: @@ -367,6 +400,9 @@ def main(): if not remove_docker_images(): return 1 + if not drop_helm_v2_database(): + return 1 + LOG.info("Armada removed.") except Exception as e: print(e)