From 270beec7fa4397ef990c8fe11ed441b4c9da7eec Mon Sep 17 00:00:00 2001 From: Erik Sundell <erik.i.sundell@gmail.com> Date: Wed, 20 Jan 2021 09:20:56 +0100 Subject: [PATCH] refactor: improve docstring and bypass temp variable for readability --- chartpress.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/chartpress.py b/chartpress.py index 5f64ac1..db2321f 100755 --- a/chartpress.py +++ b/chartpress.py @@ -512,7 +512,21 @@ def build_images(prefix, images, tag=None, push=False, force_push=False, force_b def _update_values_file_with_modifications(name, modifications): """ - Update <name>/values.yaml file with a dictionary of modifications. + Update <name>/values.yaml file with a dictionary of modifications with its + root level keys representing a path within the values.yaml file. + + Example of a modifications dictionary: + + { + "server.image": { + "repository": "my-docker-org/server", + "tag": "v1.0.0", + }, + "server.initContainers.0.image": { + "repository": "my-docker-org/server-init", + "tag": "v1.0.0", + } + } """ values_file = os.path.join(name, 'values.yaml') @@ -522,9 +536,9 @@ def _update_values_file_with_modifications(name, modifications): for path_key, path_value in modifications.items(): if not isinstance(path_value, dict) or set(path_value.keys()) != {'repository', 'tag'}: raise ValueError(f"I only understand image updates with 'repository', 'tag', not: {path_value!r}") - parts = path_key.split('.') + mod_obj = parent = values - for p in parts: + for p in path_key.split('.'): if p.isdigit(): # integers are indices in lists p = int(p)