kubernetes.core icon indicating copy to clipboard operation
kubernetes.core copied to clipboard

kubernetes.core.helm can't update/install if `chart_repo_url` is defined

Open xSuiteHaroonButt opened this issue 3 years ago • 2 comments

SUMMARY
ISSUE TYPE
  • Bug Report
COMPONENT NAME
ANSIBLE VERSION
ansible [core 2.12.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/butt/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/butt/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]
  jinja version = 2.10.1
  libyaml = True

COLLECTION VERSION
# /usr/share/ansible/collections/ansible_collections
Collection           Version
-------------------- -------
amazon.aws           3.1.1
ansible.netcommon    2.0.1
ansible.posix        1.3.0
ansible.utils        2.0.2
cloud.common         2.1.0
community.aws        3.1.0
community.crypto     1.7.1
community.docker     2.2.1
community.general    4.6.1
community.grafana    1.3.3
community.kubernetes 2.0.1
community.postgresql 2.1.2
community.vmware     1.0.0
google.cloud         1.0.2
kubernetes.core      2.3.0

CONFIGURATION

CALLBACKS_ENABLED(/etc/ansible/ansible.cfg) = ['profile_tasks']
DEFAULT_JINJA2_NATIVE(/etc/ansible/ansible.cfg) = True
DEFAULT_LOG_PATH(/etc/ansible/ansible.cfg) = /var/log/ansible.log
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False

OS / ENVIRONMENT

target os is ubuntu 20.04

STEPS TO REPRODUCE

You can repoduce this with the following steps:

  • add a repository
  • wait until a new chart is released
  • use the kubernetes.core.helm module to update the repo and install the release in one step

    - name: update mongodb - mongodb 4.4.13
      kubernetes.core.helm:
        atomic: yes
        release_state: present
        binary_path: /snap/bin/helm
        chart_ref: bitnami/mongodb
        release_name: mongodb-rs0
        release_namespace: mongodb
        wait: yes
        update_repo_cache: yes
        chart_version: 11.1.1
        chart_repo_url: https://charts.bitnami.com/bitnami
        release_values:
          image:
            tag: "4.4.13-debian-10-r19"
          arbiter:
            enabled: true

EXPECTED RESULTS

I expected the module to update install/update the repo before the install attempt, as stated in the documentation of the module Run helm repo update before the operation. Can be run as part of the package installation or as a separate step.

As you can see here the chart does exist https://artifacthub.io/packages/helm/bitnami/mongodb

ACTUAL RESULTS
fatal: [devops-m1]: FAILED! => {
    "changed": false,
    "command": "/snap/bin/helm --version=11.1.1 --repo=https://charts.bitnami.com/bitnami show chart bitnami/mongodb",
    "invocation": {
        "module_args": {
            "api_key": null,
            "atomic": true,
            "binary_path": "/snap/bin/helm",
            "ca_cert": null,
            "chart_ref": "bitnami/mongodb",
            "chart_repo_url": "https://charts.bitnami.com/bitnami",
            "chart_version": "11.1.1",
            "context": null,
            "create_namespace": false,
            "disable_hook": false,
            "force": false,
            "history_max": null,
            "host": null,
            "kubeconfig": null,
            "purge": true,
            "release_name": "mongodb-rs0",
            "release_namespace": "mongodb",
            "release_state": "present",
            "release_values": {
                "arbiter": {
                    "enabled": true
                },
                "image": {
                    "tag": "4.4.13-debian-10-r19"
                }
            },
            "replace": false,
            "skip_crds": false,
            "timeout": null,
            "update_repo_cache": true,
            "validate_certs": true,
            "values_files": [
                "/tmp/mongovalues.yaml"
            ],
            "wait": true,
            "wait_timeout": null
        }
    },
    "msg": "Failure when executing Helm command. Exited 1.\nstdout: \nstderr: Error: chart \"bitnami/mongodb\" version \"11.1.1\" not found in https://charts.bitnami.com/bitnami repository\n",
    "stderr": "Error: chart \"bitnami/mongodb\" version \"11.1.1\" not found in https://charts.bitnami.com/bitnami repository\n",
    "stderr_lines": [
        "Error: chart \"bitnami/mongodb\" version \"11.1.1\" not found in https://charts.bitnami.com/bitnami repository"
    ],
    "stdout": "",
    "stdout_lines": []
}

xSuiteHaroonButt avatar Mar 23 '22 14:03 xSuiteHaroonButt

I looked further into the issue and I was able to resolve it, by removing the chart_repo_url: https://charts.bitnami.com/bitnami from the task. I don't know, if this intended behavior or a bug, please close this if this is intended.

The updated task looks like

    - name: update mongodb - mongodb 4.4.13
      kubernetes.core.helm:
        atomic: yes
        release_state: present
        binary_path: /snap/bin/helm
        chart_ref: bitnami/mongodb
        release_name: mongodb-rs0
        release_namespace: mongodb
        wait: yes
        update_repo_cache: yes
        chart_version: "11.1.1"
        values_files:
          - /tmp/mongovalues.yaml
        release_values:
          image:
            tag: "4.4.13-debian-10-r19"
          arbiter:
            enabled: true

xSuiteHaroonButt avatar Mar 24 '22 08:03 xSuiteHaroonButt

@haroonb The problem is because you are using a repository name in your chart ref along with the repo url. When you specify a repo url you are specifically bypassing your local repository cache. You are asking it to look for a chart literally named bitnami/mongodb, but the chart is named mongodb. You would run into the same problem using helm directly, as you can see here:

$ helm --repo=https://charts.bitnami.com/bitnami show chart bitnami/mongodb
Error: chart "bitnami/mongodb" not found in https://charts.bitnami.com/bitnami repository

$ helm --repo=https://charts.bitnami.com/bitnami show chart mongodb
annotations:
  category: Database
apiVersion: v2
appVersion: 4.4.13
dependencies:
- name: common
  repository: https://charts.bitnami.com/bitnami
  tags:
  - bitnami-common
  version: 1.x.x
description: MongoDB(R) is a relational open source NoSQL database. Easy to use, it
  stores data in JSON-like documents. Automated scalability and high-performance.
  Ideal for developing cloud native applications.
home: https://github.com/bitnami/charts/tree/master/bitnami/mongodb
icon: https://bitnami.com/assets/stacks/mongodb/img/mongodb-stack-220x234.png
keywords:
- mongodb
- database
- nosql
- cluster
- replicaset
- replication
maintainers:
- email: [email protected]
  name: Bitnami
name: mongodb
sources:
- https://github.com/bitnami/bitnami-docker-mongodb
- https://mongodb.org
version: 11.1.1

I don't think we would want to change the behavior of the module to account for this, but I could see trying to add some more helpful error messages or documentation. I could maybe see making update_repo_cache and chart_repo_url mutually exclusive since they don't make any sense together. That wouldn't specifically address the confusion here, but it might help create a more consistent module interface.

gravesm avatar Mar 24 '22 12:03 gravesm