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

add reset_then_reuse_values support to helm module #802

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

b0z02003
Copy link

@b0z02003 b0z02003 commented Nov 30, 2024

SUMMARY

Starting with version 3.14.0, Helm supports --reset-then-reuse-values. As discussed on the original PR. This greatly improves on --reuse-values as it allows to avoid templates errors when new features are added to an upgraded chart.

Closes #803

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

helm

ADDITIONAL INFORMATION

This PR is greatly 'inspired' by #575 and because I wasn't sure how I could provide additional tests for it, I actually copied those build previously for --reuse-values (as it is an improvement on this feature.

Copy link

@yurnov yurnov mentioned this pull request Dec 10, 2024
32 tasks
@b0z02003 b0z02003 force-pushed the helm_reset_then_reuse_values branch 2 times, most recently from 01b422e to 6486e64 Compare December 14, 2024 16:48
Copy link

Copy link

Copy link
Contributor

@abikouo abikouo left a comment

Choose a reason for hiding this comment

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

@b0z02003 Thanks for submitting this PR.
In addition to the requested changes, you must include the new test files in main.yml of the corresponding integration test targets.

plugins/modules/helm.py Outdated Show resolved Hide resolved
plugins/modules/helm.py Outdated Show resolved Hide resolved
Copy link

@b0z02003
Copy link
Author

@abikouo Thanks for the suggestions ! I've tried to improve on them to also check for helm version and added the integration tests (that was a big oversight on my part, my bad).

Copy link

Copy link
Contributor

@abikouo abikouo left a comment

Choose a reason for hiding this comment

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

This will address linters issues

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
Copy link

Copy link

@abikouo
Copy link
Contributor

abikouo commented Jan 6, 2025

@b0z02003 Some tests are failing because you need to rebase your branch with the main branch. However, you'll also need to fix the new tests you introduced.

Copy link

@b0z02003 b0z02003 force-pushed the helm_reset_then_reuse_values branch from f771f25 to 6ff5f87 Compare January 18, 2025 08:37
Copy link

@yurnov
Copy link
Contributor

yurnov commented Jan 18, 2025

I see some race conditions:

TASK [helm : Initial chart installation] ***************************************
task path: /home/runner/collections/ansible_collections/kubernetes/core/tests/integration/targets/helm/tasks/test_helm_reset_then_reuse_values.yml:17
Saturday 18 January 2025  18:31:30 +0000 (0:00:00.039)       0:03:29.157 ****** 
......
fatal: [localhost]: FAILED! => {
    "changed": false,
    "command": "/tmp/helm/linux-amd64/helm upgrade -i --reset-values --create-namespace -f=/tmp/tmpvpofk4e1.yml test-redis 'oci://registry-1.docker.io/bitnamicharts/redis'",
    "invocation": {
        "module_args": {
            "api_key": null,
            "atomic": false,
            "binary_path": "/tmp/helm/linux-amd64/helm",
            "ca_cert": null,
            "chart_ref": "oci://registry-1.docker.io/bitnamicharts/redis",
            "chart_repo_url": null,
            "chart_version": null,
            "context": null,
            "create_namespace": true,
            "dependency_update": false,
            "disable_hook": false,
            "force": false,
            "history_max": null,
            "host": null,
            "kubeconfig": null,
            "post_renderer": null,
            "purge": true,
            "release_name": "test-redis",
            "release_namespace": "helm-reuse-values",
            "release_state": "present",
            "release_values": {
                "master": {
                    "count": 1,
                    "kind": "Deployment"
                },
                "replica": {
                    "replicaCount": 3
                }
            },
            "replace": false,
            "reset_then_reuse_values": false,
            "reset_values": true,
            "reuse_values": null,
            "set_values": null,
            "skip_crds": false,
            "timeout": null,
            "update_repo_cache": false,
            "validate_certs": true,
            "values_files": [],
            "wait": false,
            "wait_timeout": null
        }
    },
    "msg": "Failure when executing Helm command. Exited 1.\nstdout: \nstderr: Error: UPGRADE FAILED: create: failed to create: secrets \"sh.helm.release.v1.test-redis.v3\" is forbidden: unable to create new content in namespace helm-reuse-values because it is being terminated\n",
    "stderr": "Error: UPGRADE FAILED: create: failed to create: secrets \"sh.helm.release.v1.test-redis.v3\" is forbidden: unable to create new content in namespace helm-reuse-values because it is being terminated\n",
    "stderr_lines": [
        "Error: UPGRADE FAILED: create: failed to create: secrets \"sh.helm.release.v1.test-redis.v3\" is forbidden: unable to create new content in namespace helm-reuse-values because it is being terminated"
    ],
    "stdout": "",
    "stdout_lines": []
}

within this commit helm and helm diff plugin updated to versions that
suppots --reset-then-reuse-values, fixed a few small CI fault and added
tests for older version to ensure warning message. Race condition fixed
by using separate namespace.

--reset-then-reuse-values flag to 'helm upgrade' supported starting from 3.14.0

ref: https://github.com/helm/helm/releases/tag/v3.14.0, helm/helm@a9d59f9
Copy link

@yurnov
Copy link
Contributor

yurnov commented Jan 18, 2025

I see some race conditions:

I have fixed this race condition and all other parts of the integration test for this PR and added a test to ensure that a warning appears in case of older versions of Helm and Helm diff, so the CI part is fully OK.

However, I still have a not resolved question:
https://github.com/b0z02003/kubernetes.core/blob/baed9a658fa538476d415978406c1cd579fe83d3/plugins/modules/helm.py#L540C1-L547C59

Should we have just a warning message and skips of the unsupported option --reset-then-reuse-values here? It potentially may lead to unexpected results with just warning that easy to didn't catch in CI/automation, so, probably it better to have something like:

    if reset_then_reuse_values:
        helm_version = module.get_helm_version()
        if LooseVersion(helm_version) < LooseVersion("3.14.0"):
            module.fail_json(
                msg='helm support option --reset-then-reuse-values starting release >= 3.14.0',
                **opt_result
            )
        else:
            deploy_command += " --reset-then-reuse-values"

And same here:
https://github.com/b0z02003/kubernetes.core/blob/baed9a658fa538476d415978406c1cd579fe83d3/plugins/modules/helm.py#L700C1-L712C48

I'm not sure, looking for suggestions from repo maintainers and @b0z02003.

Att @gravesm, @abikouo

if reset_then_reuse_values:
helm_version = module.get_helm_version()
if LooseVersion(helm_version) < LooseVersion("3.14.0"):
module.warn(
Copy link
Contributor

@yurnov yurnov Jan 18, 2025

Choose a reason for hiding this comment

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

it it ok to have worning, or better to change to fail like:

            module.fail_json(
                msg='helm support option --reset-then-reuse-values starting release >= 3.14.0',
                **opt_result

just to avoid a case when helm will runs without --reset-then-reuse-values with unexpected result in CI

Copy link
Author

@b0z02003 b0z02003 Jan 19, 2025

Choose a reason for hiding this comment

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

You are right, we should fail when trying to use that kind of unsupported feature, I updated the PR accordingly. However, I did not include the **opt_result part (nor any parameter other than msg) since the failure is not the result of a command execution. I also changed the message to better reflect the versioning status and to better match the messages I found in the collection, are you OK with that?

helm_diff_version = get_plugin_version("diff")
helm_version = module.get_helm_version()
if LooseVersion(helm_diff_version) < LooseVersion("3.9.12"):
module.warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Copy link

@yurnov
Copy link
Contributor

yurnov commented Jan 19, 2025

Hi @b0z02003, you committed to testing in CI https://github.com/ansible-collections/kubernetes.core/actions/runs/12853271360/job/35836239457, and all tests passed.

if reset_then_reuse_values:
helm_diff_version = get_plugin_version("diff")
helm_version = module.get_helm_version()
if LooseVersion(helm_diff_version) < LooseVersion("3.9.12"):
Copy link
Contributor

Choose a reason for hiding this comment

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

I see a case when both requirement aren't meet, the only fist check will be executed and only reset_then_reuse_values requires helm diff >= 3.9.12, current version is {0} will be on fail message.

So, it better to check both conditions and have a message that contains helm, helm diff or both, depends on versions installed.

If you don't mind, I will prepare commit that improve this part

the main idea to check both versions and print both version in single run

before this commit a failed two requrement will cause only single version in error message
@yurnov
Copy link
Contributor

yurnov commented Jan 19, 2025

Hi @abikouo, @gravesm,

would you please review this PR? The integration test is completed here.

Copy link

Copy link

no feature release planned in stable-5 branch
Copy link

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.

add support for reset_then_reuse_values to helm upgrade
3 participants