config/controllerconfig/controllerconfig/upgrade-scripts/62-enable-fluxcd-controllers.py
Dan Voiculeasa 55b21d7438 Allow FluxCD to be upgraded from N to N+1
With the introduction of [1] FluxCD needs to be updated.
Enhancing upgrade-fluxcd-controllers.yml to allow FluxCD
upgrades is done part of [2].

When upgrading from 22.06 we need the flux manifest to be reapplied
(and pods will be restarted part of the new deployment).
This is designed future proof, upgrading from generic N to N+1 would
work.

Tests on AIO-SX:
Using the load for [2], emulated upgrades call.
PASS: Observed no pod restart when emulating upgrade from 21.12 as there
should be no pod in the first place when coming from 21.12
/etc/upgrade.d/62-enable-fluxcd-controllers.py 21.12 22.12 activate
PASS: Observed pods restart picking the new manifests whe emulating
upgrade from 22.06
/etc/upgrade.d/62-enable-fluxcd-controllers.py 22.06 22.12 activate

[1]: https://review.opendev.org/c/starlingx/ansible-playbooks/+/866820
[2]: https://review.opendev.org/c/starlingx/ansible-playbooks/+/867032
Depends-On: https://review.opendev.org/c/starlingx/ansible-playbooks/+/867032
Partial-Bug: 1999032
Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com>
Change-Id: I14c7802ef405a2ea4665b2a2b64e5daaf0eef009
2022-12-08 19:11:14 +02:00

61 lines
1.8 KiB
Python

#!/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(from_release)
def enable_fluxcd_controllers(from_release):
"""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 {}/{} -e "upgrade_activate_from_release={}"'\
''.format(playbooks_root, upgrade_script, from_release)
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())