Skip to content

Commit

Permalink
helm: handle multiline output
Browse files Browse the repository at this point in the history
We parse ``helm plugin list`` output. Parsing logic fails if
plugin provides multiline description.

* added fix for parsing plugin multiline description
* test added for this change

Fixes: #399

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde committed Mar 29, 2021
1 parent c9157ce commit 14c891c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/399-helm_multiline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- helm - handle multiline output of ``helm plugin list`` command (https://github.com/ansible-collections/community.kubernetes/issues/399).
11 changes: 11 additions & 0 deletions molecule/default/roles/helm/files/sample_plugin/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "sample_plugin"
version: "0.0.1"
usage: "Sample Helm Plugin"
description: |-
This plugin provides sample plugin to Helm.
usage:
This is new line
This is another line
ignoreFlags: false
useTunnel: false
command: "$HELM_PLUGIN_DIR/main.sh"
27 changes: 27 additions & 0 deletions molecule/default/roles/helm/tasks/tests_helm_plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,30 @@
- assert:
that:
- not uninstall_env.changed

- name: Install sample_plugin from the directory
helm_plugin:
binary_path: "{{ helm_binary }}"
state: present
plugin_path: "files/sample_plugin"
register: sample_plugin_output

- name: Assert that sample_plugin is installed or not
assert:
that:
- sample_plugin_output.changed

- name: Gather Helm plugin info
helm_plugin_info:
register: r

- name: Set sample_plugin version
set_fact:
plugin_version: "{{ ( r.plugin_list | selectattr('name', 'equalto', plugin_name) | list )[0].version }}"
vars:
plugin_name: "sample_plugin"

- name: Assert if sample_plugin with multiline comment is installed
assert:
that:
- plugin_version == "0.0.1"
5 changes: 4 additions & 1 deletion plugins/modules/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ def has_plugin(command, plugin):
for line in out.splitlines():
if line.startswith("NAME"):
continue
name, _rest = line.split(None, 1)
try:
name, _rest = line.split(None, 1)
except ValueError:
continue
if name == plugin:
return True
return False
Expand Down
2 changes: 2 additions & 0 deletions plugins/modules/helm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def main():
continue
name, dummy, dummy = line.split('\t', 3)
name = name.strip()
if name == "":
continue
if name == plugin_name:
found = True
break
Expand Down
2 changes: 2 additions & 0 deletions plugins/modules/helm_plugin_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ def main():
name = name.strip()
version = version.strip()
description = description.strip()
if name == "":
continue
if plugin_name is None:
plugin_list.append({
'name': name,
Expand Down

0 comments on commit 14c891c

Please sign in to comment.