Skip to content

Commit

Permalink
#498 Fix unused DBs props not cleaned from values.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
aranega committed Sep 19, 2022
1 parent 27ae0fe commit 97987a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tools/cloudharness_utilities/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,11 @@ def __finish_helm_values(self, values):
harness[KEY_SERVICE]['name'] = app_name
if not harness[KEY_DEPLOYMENT].get('name', None):
harness[KEY_DEPLOYMENT]['name'] = app_name
if not harness[KEY_DATABASE].get('name', None):

if harness[KEY_DATABASE] and not harness[KEY_DATABASE].get('name', None):
harness[KEY_DATABASE]['name'] = app_name.strip() + '-db'

self.__clear_unused_db_configuration(harness)
values_set_legacy(v)

if self.include:
Expand All @@ -371,6 +373,18 @@ def __finish_helm_values(self, values):
create_env_variables(values)
return values, self.include

def __clear_unused_db_configuration(self, harness_config):
database_config = harness_config[KEY_DATABASE]
database_type = database_config.get('type', None)
if database_type is None:
del harness_config[KEY_DATABASE]
return
db_specific_keys = [k for k, v in database_config.items()
if isinstance(v, dict) and 'image' in v and 'ports' in v]
for db in db_specific_keys:
if database_type != db:
del database_config[db]


def get_included_with_dependencies(values, include):
app_values = values['apps'].values()
Expand Down Expand Up @@ -481,7 +495,8 @@ def collect_helm_values(deployment_root, env=()):
return values


def init_app_values(deployment_root, exclude, values={}):
def init_app_values(deployment_root, exclude, values=None):
values = values if values is not None else {}
app_base_path = os.path.join(deployment_root, APPS_PATH)
overridden_template_path = os.path.join(
deployment_root, DEPLOYMENT_CONFIGURATION_PATH, 'value-template.yaml')
Expand Down
3 changes: 3 additions & 0 deletions tools/cloudharness_utilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ def dict_merge(dct, merge_dct, add_keys=True):
dict: updated dict
"""
dct = dct.copy()
if merge_dct is None:
return dct

if not add_keys:
merge_dct = {
k: merge_dct[k]
Expand Down

0 comments on commit 97987a4

Please sign in to comment.