diff --git a/changelogs/fragments/399-helm_multiline.yml b/changelogs/fragments/399-helm_multiline.yml new file mode 100644 index 00000000..c4b8b4d0 --- /dev/null +++ b/changelogs/fragments/399-helm_multiline.yml @@ -0,0 +1,2 @@ +bugfixes: +- helm - handle multiline output of ``helm plugin list`` command (https://github.com/ansible-collections/community.kubernetes/issues/399). diff --git a/molecule/default/roles/helm/files/sample_plugin/plugin.yaml b/molecule/default/roles/helm/files/sample_plugin/plugin.yaml new file mode 100644 index 00000000..8703bc29 --- /dev/null +++ b/molecule/default/roles/helm/files/sample_plugin/plugin.yaml @@ -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" diff --git a/molecule/default/roles/helm/tasks/tests_helm_plugin.yml b/molecule/default/roles/helm/tasks/tests_helm_plugin.yml index 3582dcc4..ec96859f 100644 --- a/molecule/default/roles/helm/tasks/tests_helm_plugin.yml +++ b/molecule/default/roles/helm/tasks/tests_helm_plugin.yml @@ -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" diff --git a/plugins/modules/helm.py b/plugins/modules/helm.py index 2a93a2ed..f1af1b99 100644 --- a/plugins/modules/helm.py +++ b/plugins/modules/helm.py @@ -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 diff --git a/plugins/modules/helm_plugin.py b/plugins/modules/helm_plugin.py index d13f039b..f4b25f8a 100644 --- a/plugins/modules/helm_plugin.py +++ b/plugins/modules/helm_plugin.py @@ -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 diff --git a/plugins/modules/helm_plugin_info.py b/plugins/modules/helm_plugin_info.py index 8b551838..a2574a61 100644 --- a/plugins/modules/helm_plugin_info.py +++ b/plugins/modules/helm_plugin_info.py @@ -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,