From 025a8cc03cace42a8bef89870b08fb6ae0453b62 Mon Sep 17 00:00:00 2001 From: Tee Ngo Date: Tue, 4 Dec 2018 15:23:22 -0500 Subject: [PATCH] Fix helm overrides merge issues This commit addresses the issues related to merging system and user overrides. It removes the user overrides restriction (to openstack) as well as the need to scope the overrides in values yaml file and/or set strings. Tests conducted: Stx-openstack application overrides regeneration verified with the following user overrides: system helm-override-update ingress kube-system \ --set endpoints.ingress.port.http.default=8008 \ --set pod.replicas.error_page=2 system helm-override-update ingress openstack \ --set pod.replicas.ingress=2 system helm-override-update keystone openstack \ --set conf.keystone.DEFAULT.debug=True Story: 2003909 Task: 28246 Task: 28248 Change-Id: Ie2ada9e84721b23c8394c6e472560696a4c72fc7 Signed-off-by: Tee Ngo --- sysinv/sysinv/sysinv/sysinv/helm/helm.py | 43 ++++++++++++++++-------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/sysinv/sysinv/sysinv/sysinv/helm/helm.py b/sysinv/sysinv/sysinv/sysinv/helm/helm.py index 4d1aa0286b..825f5428a8 100644 --- a/sysinv/sysinv/sysinv/sysinv/helm/helm.py +++ b/sysinv/sysinv/sysinv/sysinv/helm/helm.py @@ -8,7 +8,6 @@ from __future__ import absolute_import -import copy import eventlet import os import subprocess @@ -366,19 +365,35 @@ class HelmOperator(object): cnamespace) for (chart_name, overrides) in iteritems(app_overrides): if combined: - try: - db_chart = self.dbapi.helm_override_get( - chart_name, 'openstack') - user_overrides = db_chart.user_overrides - if user_overrides: - system_overrides = yaml.dump(overrides) - file_overrides = [system_overrides, user_overrides] - combined_overrides = self.merge_overrides( - file_overrides=file_overrides) - combined_overrides = yaml.load(combined_overrides) - overrides = copy.deepcopy(combined_overrides) - except exception.HelmOverrideNotFound: - pass + # The overrides at this point is the system overrides. For charts + # with multiple namespaces, the overrides would contain multiple keys, + # one for each namespace. + # + # Retrieve the user overrides of each namespace from the database + # and merge this list of user overrides if exists with the + # system overrides. Both system and user overrides contents + # are then merged based on the namespace, prepended with required + # header and written to corresponding files (-.yaml). + file_overrides = [] + for chart_namespace in overrides.keys(): + try: + db_chart = self.dbapi.helm_override_get( + chart_name, chart_namespace) + db_user_overrides = db_chart.user_overrides + if db_user_overrides: + file_overrides.append(yaml.dump( + {chart_namespace: yaml.load(db_user_overrides)})) + except exception.HelmOverrideNotFound: + pass + + if file_overrides: + # Use dump() instead of safe_dump() as the latter is + # not agreeable with password regex in some overrides + system_overrides = yaml.dump(overrides) + file_overrides.insert(0, system_overrides) + combined_overrides = self.merge_overrides( + file_overrides=file_overrides) + overrides = yaml.load(combined_overrides) # If armada formatting is wanted, we need to change the # structure of the yaml file somewhat