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

Fix problem with values that contains "=" in --set operation #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] IMHO this test case repeats too much from the one above. Consider adding an assertion to check other.key equals value-containing-equal-sign= there and removing this.



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