Skip to content

Commit

Permalink
Merge pull request #104 from reactiveops/refactor-helm-args
Browse files Browse the repository at this point in the history
WIP Refactored the helm arguments to implement spaces
  • Loading branch information
Nick Huanca committed May 29, 2019
2 parents e951e40 + 8726c49 commit 1f1461a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,10 @@ jobs:
reckoner plot --only nginx-ingress end_to_end_testing/basic.yml
helm list --output json | jq -e '.Releases[]|select(.Name == "nginx-ingress")|.Status == "DEPLOYED"'
reckoner plot --only nginx-ingress --only redis-env end_to_end_testing/basic.yml
test_environ_var=somevalue reckoner plot --only nginx-ingress --only redis-env end_to_end_testing/basic.yml
helm list --output json | jq -e '.Releases[]|select(.Name == "nginx-ingress")|.Status == "DEPLOYED"'
helm list --output json | jq -e '.Releases[]|select(.Name == "redis-env")|.Status == "DEPLOYED"'
helm get values redis-env --output json | jq -e '.test_environ_var == "somevalue"'
publish-binaries:
executor: python-3-7
steps:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [1.2.0]
- Support helm wrapper plugins such as [Helm Secrets](https://github.com/futuresimple/helm-secrets)
- POTENTIAL BREAKING CHANGE: Refactored all helm commands to use `--arg value` instead of `--arg=value`. (This helps with poor param support with how helm plugin wrappers work)

## [1.1.6]
- Skipped versions to kickstart pipelines
Expand Down
28 changes: 17 additions & 11 deletions reckoner/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,31 +268,37 @@ def install(self, namespace=None, context=None):
if self._deprecation_messages:
[logging.warning(msg) for msg in self._deprecation_messages]

def _append_arg(self, arg_string):
for item in arg_string.split(" ", 1):
self.args.append(item)

def build_helm_arguments_for_chart(self):
"""
This method builds all the arguments we'll pass along to the helm
client once we need to run the install
"""

# always start off with empty args list
self.args = []

# Set Default args (release name and chart path)
self.args = [
'{}'.format(self._release_name),
self.repository.chart_path,
]
self._append_arg('{}'.format(self._release_name))
self._append_arg(self.repository.chart_path)

# Add namespace to args
self.args.append('--namespace={}'.format(self.namespace))
self._append_arg('--namespace {}'.format(self.namespace))

# Add kubecfg context
if self.context is not None:
self.args.append('--kube-context={}'.format(self.context))
self._append_arg('--kube-context {}'.format(self.context))

# Add debug arguments
self.args.extend(self.debug_args)
for debug_arg in self.debug_args:
self._append_arg(debug_arg)

# Add the version arguments
if self.version:
self.args.append('--version={}'.format(self.version))
self._append_arg('--version {}'.format(self.version))

# HACK: This is in place until we can fully deprecate the usage of set
# in place of values. Currently values: gets translated into
Expand Down Expand Up @@ -335,7 +341,7 @@ def build_files_list(self):
files specified in the course.yml
"""
for values_file in self.files:
self.args.append("-f={}".format(values_file))
self._append_arg("-f {}".format(values_file))

def build_set_string_arguments(self):
"""
Expand All @@ -347,7 +353,7 @@ def build_set_string_arguments(self):
"""
for key, value in self.values_strings.items():
for k, v in self._format_set(key, value):
self.args.append("--set-string={}={}".format(k, v))
self._append_arg("--set-string {}={}".format(k, v))

def build_set_arguments(self):
"""
Expand All @@ -359,7 +365,7 @@ def build_set_arguments(self):
"""
for key, value in self.set_values.items():
for k, v in self._format_set(key, value):
self.args.append("--set={}={}".format(k, v))
self._append_arg("--set {}={}".format(k, v))

def _format_set(self, key, value):
"""
Expand Down
4 changes: 2 additions & 2 deletions reckoner/tests/test_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_chart_install(self, repositoryMock):
chart.install()
helm_client_mock.upgrade.assert_called_once()
upgrade_call = helm_client_mock.upgrade.call_args
self.assertEqual(upgrade_call[0][0], ['nameofchart', '', '--namespace=fakenamespace'])
self.assertEqual(upgrade_call[0][0], ['nameofchart', '', '--namespace', 'fakenamespace'])

@mock.patch('reckoner.chart.Repository')
def test_chart_install_with_plugin(self, repositoryMock):
Expand All @@ -246,5 +246,5 @@ def test_chart_install_with_plugin(self, repositoryMock):
chart.install()
helm_client_mock.upgrade.assert_called_once()
upgrade_call = helm_client_mock.upgrade.call_args
self.assertEqual(upgrade_call[0][0], ['nameofchart', '', '--namespace=fakenamespace'])
self.assertEqual(upgrade_call[0][0], ['nameofchart', '', '--namespace', 'fakenamespace'])
self.assertEqual(upgrade_call[1], {'plugin': 'someplugin'})
22 changes: 14 additions & 8 deletions tests/test_reckoner.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ def test_chart_install(self):
'upgrade',
'--recreate-pods',
'--install',
# '--namespace={}'.format(chart.namespace),
chart.release_name,
chart.repository.chart_path,
]
Expand All @@ -413,8 +412,10 @@ def test_chart_install(self):
'--install',
chart.release_name,
chart.repository.chart_path,
'--namespace={}'.format(chart.namespace),
'--set={}={}'.format(test_environ_var_name, test_environ_var)]
'--namespace',
'{}'.format(chart.namespace),
'--set',
'{}={}'.format(test_environ_var_name, test_environ_var)]
)
if chart.release_name == test_values_strings_chart:
self.assertEqual(
Expand All @@ -426,11 +427,16 @@ def test_chart_install(self):
'--install',
chart.release_name,
chart.repository.chart_path,
'--namespace={}'.format(chart.namespace),
'--version=0.1.0',
'--set-string=string=string',
'--set-string=integer=10',
'--set-string=boolean=True'
'--namespace',
'{}'.format(chart.namespace),
'--version',
'0.1.0',
'--set-string',
'string=string',
'--set-string',
'integer=10',
'--set-string',
'boolean=True'
]
)

Expand Down

0 comments on commit 1f1461a

Please sign in to comment.