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 diff does not use reuse-values #680

Closed
paulmayer opened this issue Feb 22, 2024 · 3 comments · Fixed by #683
Closed

Helm diff does not use reuse-values #680

paulmayer opened this issue Feb 22, 2024 · 3 comments · Fixed by #683
Assignees
Labels
jira topic/helm Issues relating to helm plugins

Comments

@paulmayer
Copy link

paulmayer commented Feb 22, 2024

SUMMARY

kubernetes.core.helm diff does not consider reuse-values to calculate the diff, resulting in inaccurate diffs.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

The helmdiff_check signature differs from upgrades using deploy. reuse_values, for example, is missing.

Recently merged changes (#670) do not fully align the behavior.

ANSIBLE VERSION
ansible [core 2.16.3]
  config file = None
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.11/site-packages/ansible
  ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.11.5 (main, Sep 22 2023, 15:34:29) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True
COLLECTION VERSION
# /home/ansible/.ansible/collections/ansible_collections
Collection      Version
--------------- -------
kubernetes.core 3.0.0  

# /usr/local/lib/python3.11/site-packages/ansible_collections
Collection      Version
--------------- -------
kubernetes.core 2.4.0
CONFIGURATION
CONFIG_FILE() = /home/ansible/playbooks/ansible.cfg
DEFAULT_MODULE_PATH(/home/ansible/playbooks/ansible.cfg) = ['/home/ansible/playbooks/library', '/home/ansible/playbooks/{{ ANSIBLE_HOME ~ "/plugins/modules', '/usr/share/ansible/plugins/modules" }}']
OS / ENVIRONMENT
STEPS TO REPRODUCE
  • Create a basic chart
helm create mychart
cd mychart
rm -rf templates
rm values.yaml
mkdir templates

add templates/configmap.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: cmap
data:
  myvalue: {{ .Values.myvalue }}
  myothervalue: {{ .Values.myothervalue }}

add values.yaml:

myvalue: foo
myothervalue: bar

create playbook helm-diff.yml

---
- name: Reproduce wrong diff output
  hosts: localhost
  connection: local
  gather_facts: false
  tasks:
    - name: Create KinD cluster
      ansible.builtin.command: >-
        kind create cluster
          --wait 300s
          --name helm-diff-reproduce
          --kubeconfig /tmp/kubeconfig
      changed_when: true
      check_mode: false

    - name: Create testing namespace
      kubernetes.core.k8s:
        state: present
        definition:
          apiVersion: v1
          kind: Namespace
          metadata:
            name: testing
            labels:
              name: testing
        kubeconfig: /tmp/kubeconfig
      check_mode: false

    - name: Create helm release
      kubernetes.core.helm:
        state: present
        chart_ref: /path/to/mychart
        release_name: myrelease
        release_namespace: testing
        release_values:
          myvalue: foo1
          myothervalue: bar1
        kubeconfig: /tmp/kubeconfig
        wait: true
      check_mode: false

    - name: Upgrade helm release
      kubernetes.core.helm:
        chart_ref: /path/to/mychart
        reset_values: false
        reuse_values: true
        release_name: myrelease
        release_namespace: testing
        values:
          myvalue: foo1
        kubeconfig: /tmp/kubeconfig

run ansible-playbook helm-diff.yml --check --diff and observe output:

TASK [Upgrade helm release] **************************************************************************************************************************************************************************************************************************************************************
testing, cmap, ConfigMap (v1) has changed:
  # Source: mychart/templates/configmap.yaml
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: cmap
  data:
    myvalue: foo1
-   myothervalue: bar1
+   myothervalue: bar
changed: [localhost]

(as opposed to no expected diff - see also empty output of helm diff upgrade myrelease /tmp/mychart --reuse-values -n testing --set myvalue=foo1 --kubeconfig /tmp/kubeconfig)

run ansible-playbook helm-diff.yml and check the configmap resource with kubectl get configmap cmap -n testing --kubeconfig /tmp/kubeconfig -o yaml:

apiVersion: v1
data:
  myothervalue: bar1
  myvalue: foo1
kind: ConfigMap
metadata:
  annotations:
    meta.helm.sh/release-name: myrelease
    meta.helm.sh/release-namespace: testing
  creationTimestamp: "2024-02-23T07:23:29Z"
  labels:
    app.kubernetes.io/managed-by: Helm
  name: cmap
  namespace: testing
  resourceVersion: "2323"
  uid: 2234d738-bc12-4f0f-b573-df9b2223deb0

Shows correct myothervalue reused.

EXPECTED RESULTS

The diff output matches what would otherwise be achieved with helm diff upgrade <...> --reuse-values <...>

ACTUAL RESULTS

Output as if running helm diff upgrade <...> without --reuse-values

@gravesm gravesm added jira topic/helm Issues relating to helm plugins labels Feb 22, 2024
@abikouo abikouo self-assigned this Feb 28, 2024
@abikouo
Copy link
Contributor

abikouo commented Feb 28, 2024

Hi @paulmayer thanks for reporting this issue.
I have submit a PR #683 to fix the idempotency issue. Could you please give a try ?

@paulmayer
Copy link
Author

Hi @abikouo :

I tested your branch against my small example and a more contrived real world one and everything looks good (I see that the test also checks whether the interaction between reuse_values and reset_values works as expected - something I haven't done). Thanks a lot for your work!

What I am not sure is whether there is a reason (design decision, convention, earlier issues,...) for the command composition (string concatenations with cmd in helm_diff and deploy_cmd in deploy) to use their own separate logic in either of the two functions (increasing the risk of such issues cropping up in the future).

Thanks again for the quick fix!

@abikouo
Copy link
Contributor

abikouo commented Feb 29, 2024

Hi @paulmayer thanks for your feedback

Hi @abikouo :

I tested your branch against my small example and a more contrived real world one and everything looks good (I see that the test also checks whether the interaction between reuse_values and reset_values works as expected - something I haven't done). Thanks a lot for your work!

What I am not sure is whether there is a reason (design decision, convention, earlier issues,...) for the command composition (string concatenations with cmd in helm_diff and deploy_cmd in deploy) to use their own separate logic in either of the two functions (increasing the risk of such issues cropping up in the future).

There is no design decision for having these 2 separated, this is how the module was originally written, this can be subjected to future refactoring to create a single function dealing with diff and deploy options

Thanks again for the quick fix!

softwarefactory-project-zuul bot pushed a commit that referenced this issue Mar 1, 2024
helm - Add reuse-values when running helm diff

SUMMARY

closes #680

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

helm

Reviewed-by: GomathiselviS
Reviewed-by: Alina Buzachis
patchback bot pushed a commit that referenced this issue Mar 1, 2024
helm - Add reuse-values when running helm diff

SUMMARY

closes #680

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

helm

Reviewed-by: GomathiselviS
Reviewed-by: Alina Buzachis
(cherry picked from commit 23e94b6)
abikouo added a commit that referenced this issue Mar 1, 2024
helm - Add reuse-values when running helm diff

SUMMARY

closes #680

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

helm

Reviewed-by: GomathiselviS
Reviewed-by: Alina Buzachis
(cherry picked from commit 23e94b6)

Co-authored-by: Bikouo Aubin <[email protected]>
sp3nx0r referenced this issue in sp3nx0r/homelab Jun 22, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[kubernetes.core](https://togithub.com/ansible-collections/kubernetes.core)
| galaxy-collection | major | `3.0.1` -> `5.0.0` |

---

### Release Notes

<details>
<summary>ansible-collections/kubernetes.core (kubernetes.core)</summary>

###
[`v5.0.0`](https://togithub.com/ansible-collections/kubernetes.core/blob/HEAD/CHANGELOG.rst#v500)

[Compare
Source](https://togithub.com/ansible-collections/kubernetes.core/compare/4.0.0...5.0.0)

\======

## Release Summary

This major release drops support for `ansible-core<2.15`.

## Minor Changes

- inventory/k8s.py - Defer removal of k8s inventory plugin to version
6.0.0
([https://github.com/ansible-collections/kubernetes.core/pull/734](https://togithub.com/ansible-collections/kubernetes.core/pull/734)).

## Breaking Changes / Porting Guide

- Remove support for `ansible-core<2.15`
([https://github.com/ansible-collections/kubernetes.core/pull/737](https://togithub.com/ansible-collections/kubernetes.core/pull/737)).

###
[`v4.0.0`](https://togithub.com/ansible-collections/kubernetes.core/blob/HEAD/CHANGELOG.rst#v400)

[Compare
Source](https://togithub.com/ansible-collections/kubernetes.core/compare/3.2.0...4.0.0)

\======

## Release Summary

This major release brings several bug fixes. We have also removed
support for `ansible-core<2.15` and deprecated functions and class from
`module_utils/common.py`.

## Minor Changes

- inventory/k8s.py - Defer removal of k8s inventory plugin to version
5.0
([https://github.com/ansible-collections/kubernetes.core/pull/723](https://togithub.com/ansible-collections/kubernetes.core/pull/723)).
- k8s - The module and K8sService were changed so warnings returned by
the K8S API are now displayed to the user.

## Removed Features (previously deprecated)

- k8s - Support for `merge_type=json` has been removed in version 4.0.0.
Please use `kubernetes.core.k8s_json_patch` instead
([https://github.com/ansible-collections/kubernetes.core/pull/722](https://togithub.com/ansible-collections/kubernetes.core/pull/722)).
- k8s_exec - the previously deprecated `result.return_code` return value
has been removed, consider using `result.rc` instead
([https://github.com/ansible-collections/kubernetes.core/pull/726](https://togithub.com/ansible-collections/kubernetes.core/pull/726)).
- module_utils/common.py - the previously deprecated `K8sAnsibleMixin`
class has been removed
([https://github.com/ansible-collections/kubernetes.core/pull/726](https://togithub.com/ansible-collections/kubernetes.core/pull/726)).
- module_utils/common.py - the previously deprecated
`configuration_digest()` function has been removed
([https://github.com/ansible-collections/kubernetes.core/pull/726](https://togithub.com/ansible-collections/kubernetes.core/pull/726)).
- module_utils/common.py - the previously deprecated `get_api_client()`
function has been removed
([https://github.com/ansible-collections/kubernetes.core/pull/726](https://togithub.com/ansible-collections/kubernetes.core/pull/726)).
- module_utils/common.py - the previously deprecated `unique_string()`
function has been removed
([https://github.com/ansible-collections/kubernetes.core/pull/726](https://togithub.com/ansible-collections/kubernetes.core/pull/726)).

## Bugfixes

- Resolve Collections util resource discovery fails when complex
subresources present
([https://github.com/ansible-collections/kubernetes.core/pull/676](https://togithub.com/ansible-collections/kubernetes.core/pull/676)).
- align `helmdiff_check()` function commandline rendering with the
`deploy()` function
([https://github.com/ansible-collections/kubernetes.core/pull/670](https://togithub.com/ansible-collections/kubernetes.core/pull/670)).
- avoid unsafe conditions in integration tests
([https://github.com/ansible-collections/kubernetes.core/pull/665](https://togithub.com/ansible-collections/kubernetes.core/pull/665)).
- helm - use `reuse-values` when running `helm diff` command
([https://github.com/ansible-collections/kubernetes.core/issues/680](https://togithub.com/ansible-collections/kubernetes.core/issues/680)).
- integrations test helm_kubeconfig - set helm version to v3.10.3 to
avoid incompatability with new bitnami charts
([https://github.com/ansible-collections/kubernetes.core/pull/670](https://togithub.com/ansible-collections/kubernetes.core/pull/670)).

###
[`v3.2.0`](https://togithub.com/ansible-collections/kubernetes.core/compare/3.1.0...3.2.0)

[Compare
Source](https://togithub.com/ansible-collections/kubernetes.core/compare/3.1.0...3.2.0)

###
[`v3.1.0`](https://togithub.com/ansible-collections/kubernetes.core/blob/HEAD/CHANGELOG.rst#v310)

[Compare
Source](https://togithub.com/ansible-collections/kubernetes.core/compare/3.0.1...3.1.0)

\======

## Release Summary

This release comes with some bugfixes and documentation updates. It also
adds new features to the kubectl connection plugin and the kustomize
lookup plugin.

## Minor Changes

- kubectl - added support of local enviroment variable that will be used
for kubectl and may be requried for establishing connections ifself
([https://github.com/ansible-collections/kubernetes.core/pull/702](https://togithub.com/ansible-collections/kubernetes.core/pull/702))
- kustomize - new parameter added to --enable-helm
([https://github.com/ansible-collections/kubernetes.core/issues/568](https://togithub.com/ansible-collections/kubernetes.core/issues/568))

## Bugfixes

- helm - expand kubeconfig path with user's home directory for
consistency with k8s
- k8s_json_patch - rename action symlink to ensure k8s action plugin is
used
([https://github.com/ansible-collections/kubernetes.core/pull/652](https://togithub.com/ansible-collections/kubernetes.core/pull/652)).

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on saturday" (UTC), Automerge - At
any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/sp3nx0r/homelab).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zOTMuMCIsInVwZGF0ZWRJblZlciI6IjM3LjM5My4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9hbnNpYmxlIiwidHlwZS9tYWpvciJdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira topic/helm Issues relating to helm plugins
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants