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 output #395

Open
krisek opened this issue Mar 2, 2022 · 4 comments
Open

helm diff output #395

krisek opened this issue Mar 2, 2022 · 4 comments
Labels
topic/helm Issues relating to helm plugins type/enhancement New feature or request

Comments

@krisek
Copy link

krisek commented Mar 2, 2022

SUMMARY

The Kubernetes returns with --check --diff CLI parameters, the actual diff that would be applied on the cluster. It would be great if the helm module would do the same.

ISSUE TYPE
  • Feature
COMPONENT NAME

helm.py

ADDITIONAL INFORMATION

It would be a great enhancement for CI/CD pipelines.

ansible-playbook -i inventory.yaml  -e variable_host="play" --check --diff basic-service-deploy.yaml
  - name: install helm package
    kubernetes.core.helm:
      chart_ref: "{{ chart_ref }}"
      chart_version: "{{ version }}"
      create_namespace: y
      context: "{{ inventory_hostname }}"
      release_name: hello
      release_namespace: hello-world
      release_state: present
@abikouo
Copy link
Contributor

abikouo commented Mar 2, 2022

Hi @krisek

Thanks for taking the time to report this feature. helm module does not support the diff mode for now, but this is a feature we may need to address later.

@abikouo abikouo added topic/helm Issues relating to helm plugins type/enhancement New feature or request labels Mar 2, 2022
@gravesm
Copy link
Member

gravesm commented Mar 2, 2022

To clarify, a diff is currently returned if you are upgrading an existing release and you have the helm diff plugin installed. We do not generate a diff if you are installing a new release or if you do not have helm diff installed. I think we should be able to easily add the diff for installing new releases as this is supported by helm diff. I would not see us adding diff support without helm diff installed in the near future, though, as this would be a significant amount of effort.

@krisek
Copy link
Author

krisek commented Mar 2, 2022

Yes, without helm diff it is definitely a mission impossible. The background is that I'm working on a CI/CD pipeline that has a dry-run feature -- to help the operator to see what would happen if the pipeline were really ran.

@gravesm gravesm added the jira label Mar 2, 2022
@pauvos
Copy link
Contributor

pauvos commented Feb 18, 2023

@krisek , you can achieve something like this by comparing the current and future release with helm_template and fact_diff.

Pseudo code:

- name: "{{ release_name }} : fetch existing release info"
  kubernetes.core.helm_info:
    release_name: "{{ release_name }}"
    release_namespace: "{{ release_namespace }}"
  check_mode: false
  changed_when: false
  when: ansible_diff_mode
  register: existing_info

- name: "{{ release_name }} : render existing release"
  kubernetes.core.helm_template:
    chart_version: "{{ existing_info['status']['chart'][(chart_name|length + 1):] }}" # cut version from "somechart-1.2.3"
    release_values: "{{ existing_info['status']['values'] }}" # use values from last release
    validate: true # opened pull request #587 for this one
    ...
  ...
  register: existing_tpl

- name: "{{ release_name }} : render new release"
  kubernetes.core.helm_template:
    chart_version: "{{ new_version }}"
    release_values "{{ new_release_values }}"
    ...
  ...
  register: new_tpl

- name: "{{ release_name }} : diff"
  ansible.utils.fact_diff: 
    before: "{{ existing_tpl.stdout|default('')|trim }}"
    after: "{{ new_tpl.stdout|trim }}"
  ...
  changed_when: existing_tpl.stdout|default('')|trim != new_tpl.stdout|trim

fact_diff produces less verbose (only a few lines of changes) and more readable (green/red diff lines) output than running kubernetes.core.helm in diff_mode. If no current release exists, all new manifests will be displayed.

Pull request for --validate: #587

@gravesm gravesm removed the jira label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/helm Issues relating to helm plugins type/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants