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: add support for history-max parameter #164

Merged
merged 5 commits into from
Jul 15, 2021

Conversation

vvanouytsel
Copy link
Contributor

SUMMARY

The --history-max parameter allows the user to set a maximum amount of
revisions per release to be kept in the history.

By default helm keeps 10 revisions per release, which means that 10
secrets will be kept per release. If you have multiple helm releases, the amount of secrets created by Helm will quickly add up.

With supporting the 'history-max' CLI parameter via the ansible module, the user will have the posibility to determine how many revisions he wants to keep per release.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

plugins/modules/helm.py

ADDITIONAL INFORMATION

Before change:

- name: example
  hosts: localhost
  tasks:
    - name: "Deploy helm chart before change"
      kubernetes.core.helm:
        name: "example"
        chart_ref: "/tmp/example"
        release_namespace: default
        wait_timeout: 10m
PLAY [example] ***********************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Deploy helm chart before change] ***********************************************************************************************************************************************************************************************
changed: [localhost] => {"changed": true, "command": "/usr/bin/helm upgrade -i --reset-values example /tmp/example", "status": {"app_version": "3.0.0", "chart": "example-3.0.0", "name": "example", "namespace": "default", "revision": "1", "status": "deployed", "updated": "2021-07-08 08:38:47.591116754 +0000 UTC", "values": {}}, "stderr": "", "stderr_lines": [], "stdout": "Release \"example\" does not exist. Installing it now.\nNAME: example\nLAST DEPLOYED: Thu Jul  8 08:38:47 2021\nNAMESPACE: default\nSTATUS: deployed\nREVISION: 1\nTEST SUITE: None\nNOTES:\nDeployed!\n", "stdout_lines": ["Release \"example\" does not exist. Installing it now.", "NAME: example", "LAST DEPLOYED: Thu Jul  8 08:38:47 2021", "NAMESPACE: default", "STATUS: deployed", "REVISION: 1", "TEST SUITE: None", "NOTES:", "Deployed!"]}

PLAY RECAP ***************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

After change:
Without history_max set:

- name: example
  hosts: localhost
  tasks:
    - name: "Deploy helm chart without history_max"
      kubernetes.core.helm:
        name: "example"
        chart_ref: "/tmp/example"
        release_namespace: default
        wait_timeout: 10m
PLAY [example] ***********************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Deploy helm chart without history_max] *****************************************************************************************************************************************************************************************
changed: [localhost] => {"changed": true, "command": "/usr/bin/helm upgrade -i --reset-values --history-max=10 example /tmp/example", "status": {"app_version": "3.0.0", "chart": "example-3.0.0", "name": "example", "namespace": "default", "revision": "1", "status": "deployed", "updated": "2021-07-08 08:33:24.728443982 +0000 UTC", "values": {}}, "stderr": "", "stderr_lines": [], "stdout": "Release \"example\" does not exist. Installing it now.\nNAME: example\nLAST DEPLOYED: Thu Jul  8 08:33:24 2021\nNAMESPACE: default\nSTATUS: deployed\nREVISION: 1\nTEST SUITE: None\nNOTES:\nDeployed!\n", "stdout_lines": ["Release \"example\" does not exist. Installing it now.", "NAME: example", "LAST DEPLOYED: Thu Jul  8 08:33:24 2021", "NAMESPACE: default", "STATUS: deployed", "REVISION: 1", "TEST SUITE: None", "NOTES:", "Deployed!"]}

PLAY RECAP ***************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 

With history_max set:

- name: example
  hosts: localhost
  tasks:
    - name: "Deploy helm chart with history_max"
      kubernetes.core.helm:
        name: "example"
        chart_ref: "/tmp/example"
        release_namespace: default
        wait_timeout: 10m
        history_max: 3
PLAY [example] ***********************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Deploy helm chart with history_max] ********************************************************************************************************************************************************************************************
changed: [localhost] => {"changed": true, "command": "/usr/bin/helm upgrade -i --reset-values --history-max=3 example /tmp/example", "status": {"app_version": "3.0.0", "chart": "example-3.0.0", "name": "example", "namespace": "default", "revision": "1", "status": "deployed", "updated": "2021-07-08 08:35:28.231751834 +0000 UTC", "values": {}}, "stderr": "", "stderr_lines": [], "stdout": "Release \"example\" does not exist. Installing it now.\nNAME: example\nLAST DEPLOYED: Thu Jul  8 08:35:28 2021\nNAMESPACE: default\nSTATUS: deployed\nREVISION: 1\nTEST SUITE: None\nNOTES:\nDeployed!\n", "stdout_lines": ["Release \"example\" does not exist. Installing it now.", "NAME: example", "LAST DEPLOYED: Thu Jul  8 08:35:28 2021", "NAMESPACE: default", "STATUS: deployed", "REVISION: 1", "TEST SUITE: None", "NOTES:", "Deployed!"]}

PLAY RECAP ***************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  

The --history-max parameter allows the user to set a maximum amount of
revisions per release to be kept in the history.

By default helm keeps 10 revisions per release, which means that 10
secrets will be kept per release.
@codecov
Copy link

codecov bot commented Jul 8, 2021

Codecov Report

Merging #164 (c94da3c) into main (25100e7) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #164   +/-   ##
=======================================
  Coverage   24.02%   24.02%           
=======================================
  Files           1        1           
  Lines         154      154           
  Branches       29       29           
=======================================
  Hits           37       37           
- Misses        111      112    +1     
+ Partials        6        5    -1     
Impacted Files Coverage Δ
...ections/kubernetes/core/plugins/action/k8s_info.py 24.02% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25100e7...c94da3c. Read the comment docs.

plugins/modules/helm.py Outdated Show resolved Hide resolved
plugins/modules/helm.py Outdated Show resolved Hide resolved
plugins/modules/helm.py Outdated Show resolved Hide resolved
When the history_max option is not set, the module will not pass
'--history-max' to the CLI command. This ensures that the defaults of
the helm CLI will alwasy be used.
@vvanouytsel vvanouytsel requested a review from Akasurde July 9, 2021 08:45
@vvanouytsel
Copy link
Contributor Author

Thanks for you review @Akasurde , I've added your remarks to the PR.
If you have any more remarks please let them know.

Thanks!

@vvanouytsel
Copy link
Contributor Author

Thanks for reviewing @abikouo!
Are you able to approve the workflow for this PR as well?

@abikouo
Copy link
Contributor

abikouo commented Jul 15, 2021

Thanks for reviewing @abikouo!
Are you able to approve the workflow for this PR as well?

Should be ok now.

Copy link
Member

@gravesm gravesm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vvanouytsel Thank you for the PR! The --history-max option is not supported for helm install which is used when the replace param is set. The history_max and replace parameters will need to be set to mutually exclusive. This can be done here:

mutually_exclusive=[
and also by updating the documentation for each parameter, an example of which is here:
- mutually exclusive with C(apply)

The 'history_max' parameter is not available when using the 'helm
install' command, it is only implemented for 'helm ugprade'.

The 'replace' option uses the 'install' parameter, thus 'replace' and
'history_max' have to be mutually exclusive.
@vvanouytsel
Copy link
Contributor Author

@gravesm Thanks for your review!
I have fixed the linting issue and have also added both 'replace' and 'history_max' to the 'mutually_exclusive' parameter.
Let me know if you require any more changes.

@vvanouytsel vvanouytsel requested a review from gravesm July 15, 2021 14:57
Copy link
Member

@gravesm gravesm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small nits and then everything else looks good.

changelogs/fragments/164-add-history-max.yaml Outdated Show resolved Hide resolved
plugins/modules/helm.py Outdated Show resolved Hide resolved
plugins/modules/helm.py Outdated Show resolved Hide resolved
@vvanouytsel vvanouytsel requested a review from gravesm July 15, 2021 15:12
Copy link
Member

@gravesm gravesm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vvanouytsel!

@gravesm gravesm merged commit a0a6d71 into ansible-collections:main Jul 15, 2021
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Apr 26, 2022
Add helm dependency update

SUMMARY

Execute the helm dependency update under the hood when found dependencies block in Chart.yaml file.
Support the execution of:

Standalone dependency update by executing: helm dependency update CHART
Inline dependency update when specifying the helm chart_repo_url by adding --dependency-update to the helm install command.


ISSUE TYPE


Feature Pull Request #191

COMPONENT NAME

helm, helm_template
ADDITIONAL INFORMATION





There is a doc generated for history_max option for the helm module. I think that is not generated in the previous PR #164.


There is others changes affect the docs/ folder when I run the collection_prep_add_docs -p .  command. These changes are added in the last commit  64eab40. I let you decide rather we keep the commit or remove it.


The --dependency-update insertion option is tested used a local helm chart repository create via docker. So here are the tasks that test this feature.  Maybe if we create a GitHub repository for the helm chart, we can add this test code in the CI pipeline.


# Test The update dependency with chart_repo_url
- name: "Test chart without dependencies block and chart_repo_url defined"
  block:
    - name: "Test chart without dependencies block and chart_repo_url defined"
      helm:
        binary_path: "{{ helm_binary }}"
        name: test
        chart_ref: "ingress-nginx"
        chart_repo_url: https://kubernetes.github.io/ingress-nginx
        chart_version: "{{ chart_source_version | default(omit) }}"
        namespace: "{{ helm_namespace }}"
        create_namespace: yes
      register: release

    - assert:
        that:
          - "'--dependency-update' not in release.command"
          - "'upgrade' in release.command"
        success_msg: "Command does not contains '--dependency-update' options"
        fail_msg: "Command contains '--dependency-update' options"

- name: "Test chart with dependencies block and chart_repo_url defined and replace True"
  block:
    - name: "Test chart with dependencies block and chart_repo_url defined and replace True"
      helm:
        binary_path: "{{ helm_binary }}"
        name: test1
        chart_ref: "dep_up"
        chart_repo_url: http://repo:8080/charts
        chart_version: "{{ chart_source_version | default(omit) }}"
        namespace: "{{ helm_namespace }}"
        create_namespace: yes
        replace: true
      register: release
    - debug: var=release
    - assert:
        that:
          - "'--dependency-update' in release.command"
          - "'install' in release.command"
        success_msg: "Command contains '--dependency-update' options with helm install command"
        fail_msg: "Command not contains '--dependency-update' with helm install command"

- name: "Test chart with dependencies block and chart_repo_url defined and replace False fails"
  block:
    - name: "Test chart with dependencies block and chart_repo_url defined and replace False fails"
      helm:
        binary_path: "{{ helm_binary }}"
        name: test2
        chart_ref: "dep_up"
        chart_repo_url: http://repo:8080/charts
        chart_version: "{{ chart_source_version | default(omit) }}"
        namespace: "{{ helm_namespace }}"
        create_namespace: yes
        replace: false
      register: release
      ignore_errors: true

    - assert:
        that:
          - release.failed
          - release.msg == "'--dependency-update' hasn't been supported yet with 'helm upgrade'. Please use 'helm install' instead by adding 'replace' option"
        success_msg: "Command build fail when adding  '--dependency-update' with the helm upgrade command"

Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Wissem BEN CHAABANE <benchaaben.wissem@gmail.com>
Reviewed-by: Bikouo Aubin <None>
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 this pull request may close these issues.

4 participants