Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helm: has_plugin fails when helm is outputting multiline description #11

Closed
kiwo opened this issue Mar 29, 2021 · 7 comments · Fixed by #64
Closed

helm: has_plugin fails when helm is outputting multiline description #11

kiwo opened this issue Mar 29, 2021 · 7 comments · Fixed by #64
Assignees

Comments

@kiwo
Copy link

kiwo commented Mar 29, 2021

SUMMARY

We get an Exception in has_plugin in
community.kubernetes/blob/main/plugins/modules/helm.py 421
When testing for helm plugins this is our helm Output:

bash-5.1# helm plugin list
NAME            VERSION DESCRIPTION
registry        0.7.0   This plugin provides app-registry client to Helm.
                        usage:
                          $ helm reg...

The failing output line is "usage:". This results in ValueError: not enough values to unpack (expected 2, got 1) because everything around it gets trimmed.

As a workaround i just ignored every line with single result:

def has_plugin(command, plugin):
    """
    Check if helm plugin is installed.
    """

    cmd = command + " plugin list"
    rc, out, err = run_helm(module, cmd)
    for line in out.splitlines():
        if line.startswith("NAME"):
            continue
        try:
            name, _rest = line.split(None, 1)
        except ValueError:
            continue
        if name == plugin:
            return True
    return False

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.kubernetes/blob/main/plugins/modules/helm.py 421

ANSIBLE VERSION
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.8 (default, Mar 15 2021, 13:10:14) [GCC 10.2.1 20201203]


helm version
version.BuildInfo{Version:"v3.2.4", GitCommit:"0ad800ef43d3b826f31a5ad8dfbb4fe05d143688", GitTreeState:"clean", GoVersion:"go1.13.12"}
CONFIGURATION

OS / ENVIRONMENT
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS
TASK [Deploying Helm Charts] ***************************************************
skipping: [controller] => (item={'repo': 'dev', 'name': 'ads-manager', 'releaseSuffix': '', 'version': '0.1.2'}) 
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: not enough values to unpack (expected 2, got 1)
failed: [controller] (item={'repo': 'dev', 'name': '****-env', 'releaseSuffix': '-pr-41', 'version': '38.6.0-pr-41-14'}) => {"ansible_loop_var": "item", "changed": false, "item": {"name": "****-env", "releaseSuffix": "-pr-41", "repo": "dev", "version": "38.6.0-pr-41-14"}, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1617001631.0870662-124-53740490907834/AnsiballZ_helm.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1617001631.0870662-124-53740490907834/AnsiballZ_helm.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1617001631.0870662-124-53740490907834/AnsiballZ_helm.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.kubernetes.plugins.modules.helm', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.kubernetes.helm_payload_viqlvhh3/ansible_community.kubernetes.helm_payload.zip/ansible_collections/community/kubernetes/plugins/modules/helm.py\", line 641, in <module>\n  File \"/tmp/ansible_community.kubernetes.helm_payload_viqlvhh3/ansible_community.kubernetes.helm_payload.zip/ansible_collections/community/kubernetes/plugins/modules/helm.py\", line 587, in main\n  File \"/tmp/ansible_community.kubernetes.helm_payload_viqlvhh3/ansible_community.kubernetes.helm_payload.zip/ansible_collections/community/kubernetes/plugins/modules/helm.py\", line 421, in has_plugin\nValueError: not enough values to unpack (expected 2, got 1)\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
skipping: [controller] => (item={'repo': 'dev', 'name': 'spring-boot-demo', 'releaseSuffix': '', 'version': '0.1.0'}) 
skipping: [controller] => (item={'repo': 'dev', 'name': 'kickstarter-ui', 'releaseSuffix': '', 'version': '2.9.3'}) 
@Akasurde
Copy link
Member

@kiwo Thanks for reporting this issue. What is the version of helm binary used?

helm version
version.BuildInfo{Version:"v3.2.1", GitCommit:"fe51cd1e31e6a202cba7dead9552a6d418ded79a", GitTreeState:"clean", GoVersion:"go1.13.10"}

I see there is extra usage line in your helm plugin list which is not available in my helm plugin list output =

helm plugin list
NAME   	VERSION	DESCRIPTION
secrets	2.0.2  	This plugin provides secrets values encryption for Helm charts secure storing

@kiwo
Copy link
Author

kiwo commented Mar 29, 2021

Hi @Akasurde

helm version
version.BuildInfo{Version:"v3.2.4", GitCommit:"0ad800ef43d3b826f31a5ad8dfbb4fe05d143688", GitTreeState:"clean", GoVersion:"go1.13.12"}

@kiwo
Copy link
Author

kiwo commented Mar 29, 2021

The Plugin which is making this multiline output

name: "registry"
version: "0.7.0"
usage: "app-registry client to Helm"
description: |-
  This plugin provides app-registry client to Helm.
  usage:
    $ helm registry install quay.io/charts/gitlab-ce --namespace ci
    $ helm registry upgrade quay.io/charts/jenkins --set imageTag=latest
ignoreFlags: false
useTunnel: false
command: "$HELM_PLUGIN_DIR/cnr.sh"

I dont know where the sources are from, I am guessing https://github.com/app-registry/appr-helm-plugin. Our build references no src here :(

@Akasurde
Copy link
Member

@kiwo ok. This is an issue with parsing logic and will need fixing.

@Akasurde Akasurde changed the title community.kubernetes/blob/main/plugins/modules/helm.py has_plugin fails when helm is outputting multiline description helm: has_plugin fails when helm is outputting multiline description Mar 29, 2021
@Akasurde
Copy link
Member

resolved_by_pr ansible-collections/community.kubernetes#400

@Akasurde
Copy link
Member

@kiwo Could you please check if ansible-collections/community.kubernetes#400 works for you and let me know? Thanks.

@kiwo
Copy link
Author

kiwo commented Mar 29, 2021

Hi @Akasurde

I switched both packages to your branch (there seems to be some transition from community.kubernetes to kubernetes).
Ansible helm calls are now working. 👍

thank you for this quick fix =)

Akasurde referenced this issue in Akasurde/community.kubernetes Mar 29, 2021
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]>
Akasurde referenced this issue in Akasurde/community.kubernetes Mar 29, 2021
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]>
@gravesm gravesm transferred this issue from ansible-collections/community.kubernetes Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants