Skip to content

fix: Process all hook deletions on failure - #30673

Merged
scottrigby merged 8 commits into
helm:mainfrom
nvanthao:process-all-hook-deletions-on-failure
Apr 16, 2025
Merged

scottrigby merged 8 commits into
helm:mainfrom
nvanthao:process-all-hook-deletions-on-failure

Conversation

@nvanthao

@nvanthao nvanthao commented Mar 14, 2025 •

Copy link
Copy Markdown

What this PR does / why we need it:
fixes #10279
closes #11334

Special notes for your reviewer:

If applicable:

  • this PR contains user facing changes (the docs needed label should be applied if so)
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

uvegla and others added 8 commits March 15, 2025 08:29
@pull-request-size pull-request-size Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 14, 2025
@nvanthao nvanthao mentioned this pull request Mar 14, 2025
1 of 3 tasks
@scottrigby

Copy link
Copy Markdown
Member

@nvanthao thanks for picking back up on this when you ran into this issue.

Note to other maintainers if you get to this one first — from #11334 (comment) that we should squash commit and add this Co-authored-by line:

@nvanthao If you already got it working / have the change, please go for it by all means! 🙂 The real credit goes to @prafull01 for the original PR: #10811. I merely added the tests in this one. I would love to finally see this fixed in Helm, thank you for picking this up! 🙇🏻 🙂

Thanks for noting this. We can squash commit #30673 when that gets in an add Co-authored-by commit trailer for @prafull01 when we do 👍 Always try our best to give credit where it's due. And appreciate your work on this as well!

@scottrigby scottrigby added the bug Categorizes issue or PR as related to a bug. label Mar 17, 2025

@scottrigby scottrigby left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good—looking forward to finally getting this in.

Also manually tested:

  1. create example chart:

    $ d=`mktemp -d`
    $ name=pr-30673
    $ mkdir -p $d/$name/templates
    $ cat > $d/$name/Chart.yaml <<EOF
    apiVersion: 0.1.0
    name: $name
    version: 0.1.0
    EOF
    $ cat > $d/$name/templates/job.yaml <<EOF
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: "{{ .Release.Name }}-successful-job"
      labels:
        app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
        app.kubernetes.io/instance: {{ .Release.Name | quote }}
        app.kubernetes.io/version: {{ .Chart.AppVersion }}
        helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
      annotations:
        "helm.sh/hook": pre-install
        "helm.sh/hook-weight": "1"
        "helm.sh/hook-delete-policy": "hook-succeeded,hook-failed"
    spec:
      template:
        metadata:
          name: successful-job
          labels:
            app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
            app.kubernetes.io/instance: {{ .Release.Name | quote }}
            helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
        spec:
          restartPolicy: Never
          containers:
          - name: bash
            command:
              - bash
              - -c 
              - exit 0
            image: bash:latest
    ---
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: "{{ .Release.Name }}-failed-job"
      labels:
        app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
        app.kubernetes.io/instance: {{ .Release.Name | quote }}
        app.kubernetes.io/version: {{ .Chart.AppVersion }}
        helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
      annotations:
        "helm.sh/hook": pre-install
        "helm.sh/hook-weight": "2"
        "helm.sh/hook-delete-policy": "hook-failed,hook-succeeded"
    spec:
      backoffLimit: 0  
      template:
        metadata:
          name: failed-job
          labels:
            app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
            app.kubernetes.io/instance: {{ .Release.Name | quote }}
            helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
        spec:
          restartPolicy: Never
          containers:
          - name: bash
            command:
              - bash
              - -c 
              - exit 1
            image: bash:latest
    EOF
  2. test without PR fix:

    $ helm install without-fix $d/$name
    Error: INSTALLATION FAILED: failed pre-install: 1 error occurred:
        * job pr-30673-failed-job failed: BackoffLimitExceeded
    $ kubectl get job
    NAME                         STATUS     COMPLETIONS   DURATION   AGE
    without-fix-successful-job   Complete   1/1           3s         4m3s

    The successful job with hook-succeeded policy was not deleted.

    Cleanup:

    $ helm uninstall without-fix
    $ kubectl delete job without-fix-successful-job
  3. test with PR fix:

    $ cd /PATH/TO/HELM/REPO
    $ make
    $ ./bin/helm install with-fix $d/$name
    Error: INSTALLATION FAILED: failed pre-install: 1 error occurred:
        * job with-fix-failed-job failed: BackoffLimitExceeded
    $ kubectl get job
    NAME                         STATUS     COMPLETIONS   DURATION   AGE

    The job was deleted successfully.

@scottrigby scottrigby added the Has One Approval This PR has one approval. It still needs a second approval to be merged. label Mar 17, 2025

@sabre1041 sabre1041 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@scottrigby scottrigby removed the Has One Approval This PR has one approval. It still needs a second approval to be merged. label Apr 16, 2025
@scottrigby
scottrigby merged commit e397f44 into helm:main Apr 16, 2025
@scottrigby scottrigby added the Needs v3 backport Label PRs for v4/main, which are still applicable to v3 so need a separate backport PR label Apr 16, 2025
nvanthao pushed a commit to nvanthao/helm that referenced this pull request Apr 17, 2025
Signed-off-by: Gerard Nguyen <[email protected]>
benoittgt added a commit to benoittgt/helm that referenced this pull request Apr 17, 2025
helm#30673 merge break main because of
changes on wait strategy. This PR try to fix linting and tests.

Signed-off-by: Benoit Tigeot <[email protected]>
@scottrigby scottrigby added v3 port complete For completed v2->v3 ports and removed Needs v3 backport Label PRs for v4/main, which are still applicable to v3 so need a separate backport PR labels Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. v3 port complete For completed v2->v3 ports

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook delete policy of "hook-failed" not honored for preceding resource on a failure

5 participants