3
votes

Let's say I have two versions of chart Foo - v1 and v2. I had installed v1 (as revision 1) then upgraded to v2 (revision 2).

Now I'd like to rollback to first revision (helm rollback Foo 1). Is there any way to run job defined in v2 at some point of rollback after v1 resources are restored.

It must perform some actions on v1 resources because backwards incompatible changes made in v2.

I'd assume that pre-rollback hook defined in v2 should do the job. Unfortunetly chart lifecycle documentation is a bit confusing for me.


I tried to use

  annotations:
    "helm.sh/hook": post-rollback

as suggested in the answers. Unfortunately when I do rollback from v2 to v1 then v1's version of pre/post rollback job is executed. I need to execute job defined in v2 chart.

3
Based on your edits, it sounds like you're interested in a pre-rollback hook, since you're rolling back v2 and want the job defined there to run? I'm not sure you could accomplish getting the v2 job to run only after the roll back to v1 is complete.victoryNap

3 Answers

1
votes

No it's not possible, Helm always uses hooks from target release, in this case from v1.

0
votes

pre-rollback is executed before any resources are created. Your desire state is to have that job to run on already created resources so you have to use post-rollback hook as described in the documentation:

post-rollback Executes on a rollback request after all resources have been modified

0
votes

The following documentation and examples should clear up your confusion -

https://helm.sh/docs/topics/charts_hooks/#the-available-hooks

https://helm.sh/docs/topics/charts_hooks/#writing-a-hook

tldr

Add the following to the job you want to execute.

annotations:
  "helm.sh/hook": post-rollback