Skip to content

On hook failure, the cleanup mechanism should also run on all previous hooks - #10811

Closed
prafull01 wants to merge 1 commit into
helm:mainfrom
prafull01:fix-hooks-deletion-on-failure
Closed

prafull01 wants to merge 1 commit into
helm:mainfrom
prafull01:fix-hooks-deletion-on-failure

Conversation

@prafull01

Copy link
Copy Markdown

closes #10279

What this PR does / why we need it:
Currently, In case of multiple hooks if any of the hook fail, only that hook is deleted (if deletion policy is set). The other hooks are not deleted because code immediately returns error after cleaning up failed hook.

This PR adds mechanism to not only clean the failed hook, but clean the successful hook as well based on their deletion policy

Special notes for your reviewer:

If applicable:

  • this PR contains documentation
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

@pull-request-size pull-request-size Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 28, 2022
@prafull01
prafull01 force-pushed the fix-hooks-deletion-on-failure branch from 95081c4 to 8359e00 Compare March 28, 2022 21:40
@bacongobbler

Copy link
Copy Markdown
Member

Can you please write a unit test for execHook to catch and check for this new behavior?

@prafull01

Copy link
Copy Markdown
Author

IMHO execHook function can not be properly covered with unit tests. The execHook function creates hooks resources reading from the release and deletes the successful/failed hooks resources based on the delete policy. Unless I can check that a particular resources is created or deleted (as per delete policy) after running the execHook function. This can be only achieved if we are running kube-apiserver and etcd (using envtest) where this objects are persisted.

Do you have any pointer, how can I write unit tests for this function?

@prafull01

Copy link
Copy Markdown
Author

@bacongobbler Can you please have a look at above comment. Thanks :)

@bacongobbler

Copy link
Copy Markdown
Member

// Package fake implements various fake KubeClients for use in testing

You could wrap the FailingKubeClient to mark each resource that enters Delete, then check whether every hook was deleted or not.

@uvegla uvegla mentioned this pull request Sep 12, 2022
1 of 3 tasks
@uvegla

uvegla commented Sep 13, 2022

Copy link
Copy Markdown
Contributor

@bacongobbler @prafull01 Hi! 👋🏻 I have a pull request with this change and tests added: #11334 Could you please check it?

@joejulian joejulian modified the milestone: 3.11.0 Nov 8, 2022
@joejulian

Copy link
Copy Markdown
Contributor

As this PR has had no responses and there's another PR that has the requested changes, I'm closing this in favor of #11334.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

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