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

helm: handle multiline output #400

Closed
wants to merge 1 commit into from
Closed
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
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"
33 changes: 33 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,36 @@
- assert:
that:
- not uninstall_env.changed

# https://github.com/ansible-collections/community.kubernetes/issues/399
- name: Copy required plugin files
copy:
src: "files/sample_plugin"
dest: "/tmp/helm_plugin_test/"

- name: Install sample_plugin from the directory
helm_plugin:
binary_path: "{{ helm_binary }}"
state: present
plugin_path: "/tmp/helm_plugin_test/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