Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
chang(render): overriden vars split to not break values with = signal
Browse files Browse the repository at this point in the history
  • Loading branch information
guidiego committed Oct 16, 2020
1 parent a888a6c commit d7ef888
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion kuberender/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def render(filename):

def parse_overriden_vars(overriden_vars):
def parse_statement(override_statement):
key, value = override_statement.split('=')
equal_idx = override_statement.index('=')
key = override_statement[:equal_idx]
value = override_statement[equal_idx + 1:]
obj = {}
dpath.util.new(obj, key, value, separator='.')
return obj
Expand Down
19 changes: 18 additions & 1 deletion tests/test_kuberender.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,30 @@ def test_overriding_vars(self):

manifest = self._load_template_manifest(self._partial_render()(
context_files=['base.yaml'],
overriden_vars=['image.tag=3.0.7', 'image.repository=bitnami/redis']
overriden_vars=['image.tag=3.0.7', 'image.repository=bitnami/redis', 'other.key=test=']
))

# Image and tag were overriden but pullPolicy (which is a sibling) wasn't modified
assert 'bitnami/redis:3.0.7' == get_value(manifest, 'spec/template/spec/containers/0/image')
assert 'Always' == get_value(manifest, 'spec/template/spec/containers/0/imagePullPolicy')

def test_overriding_vars_with_eq(self):
manifest = self._load_template_manifest(self._partial_render()(
context_files=['base.yaml'],
overriden_vars=[]
))
assert 'redis:latest' == get_value(manifest, 'spec/template/spec/containers/0/image')
assert 'Always' == get_value(manifest, 'spec/template/spec/containers/0/imagePullPolicy')

manifest = self._load_template_manifest(self._partial_render()(
context_files=['base.yaml'],
overriden_vars=['image.tag=3.0.7', 'image.repository=bitnami/redis', 'image.pullPolicy=test=']
))

# Image and tag were overriden but pullPolicy (which is a sibling) wasn't modified
assert 'bitnami/redis:3.0.7' == get_value(manifest, 'spec/template/spec/containers/0/image')
assert 'test=' == get_value(manifest, 'spec/template/spec/containers/0/imagePullPolicy')


if __name__ == '__main__':
unittest.main()

0 comments on commit d7ef888

Please sign in to comment.