From 80472b3cf33f07bdf9401ad37babe0fa6fa633cc Mon Sep 17 00:00:00 2001 From: Lucas Cavalcante Date: Tue, 7 Jun 2022 11:31:42 -0300 Subject: [PATCH] Enable FluxCD controllers over platform upgrade This runs the ansible playbook that installs FluxCD controllers, needed to run FluxCD apps during activate step of platform upgrade TEST PLAN: PASS: Run 62-run-fluxcd-ansible.py with fluxcd-helm namespace deleted. PASS: FluxCD controllers are installed during platform upgrade Story: 2009138 Task: 45377 Signed-off-by: Lucas Cavalcante Change-Id: If8caa87637c636e0deff723c791965f0e4cb8fb1 Depends-on: https://review.opendev.org/c/starlingx/ansible-playbooks/+/844510 --- .../62-enable-fluxcd-controllers.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 controllerconfig/controllerconfig/upgrade-scripts/62-enable-fluxcd-controllers.py diff --git a/controllerconfig/controllerconfig/upgrade-scripts/62-enable-fluxcd-controllers.py b/controllerconfig/controllerconfig/upgrade-scripts/62-enable-fluxcd-controllers.py new file mode 100644 index 0000000000..636da34446 --- /dev/null +++ b/controllerconfig/controllerconfig/upgrade-scripts/62-enable-fluxcd-controllers.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# Copyright (c) 2022 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +# This script install fluxcd controllers in the fluxcd-helm namespace +# in kubernetes +# +# This script can be removed in the release that follows stx7 +import subprocess +import sys +from controllerconfig.common import log +LOG = log.get_logger(__name__) + + +def main(): + action = None + from_release = None + to_release = None + arg = 1 + while arg < len(sys.argv): + if arg == 1: + from_release = sys.argv[arg] + elif arg == 2: + to_release = sys.argv[arg] + elif arg == 3: + action = sys.argv[arg] + else: + print("Invalid option %s." % sys.argv[arg]) + return 1 + arg += 1 + log.configure() + + if action == 'activate' and from_release == '21.12': + LOG.info("%s invoked with from_release = %s to_release = %s " + "action = %s" + % (sys.argv[0], from_release, to_release, action)) + enable_fluxcd_controllers() + + +def enable_fluxcd_controllers(): + """Run fluxcd_controllers ansible playbook to enable fluxcd controllers + + """ + + playbooks_root = '/usr/share/ansible/stx-ansible/playbooks' + upgrade_script = 'upgrade-fluxcd-controllers.yml' + cmd = 'ansible-playbook {}/{}'.format(playbooks_root, upgrade_script) + sub = subprocess.Popen(cmd, shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = sub.communicate() + if sub.returncode != 0: + LOG.error('Command failed:\n %s\n. %s\n%s' % (cmd, stdout, stderr)) + raise Exception('Cannot install fluxcd controllers') + LOG.info('FluxCD controllers enabled') + + +if __name__ == "__main__": + sys.exit(main())