2

I use an install script in a post-install hook. When I run helm install with --wait option, helm waits that all pods are ready, but helm does not launch post-install hooks script. Then, the pods are not yet ready (pods are waiting for install script to finish).

I tried with pre-install hook instead, but the install script needs other services to be running...

PS: it works fine if I don't use "--wait", but CI from gitlab won't fail if there is an error during pod startups.

Is there a way to run the post-install hooks during the helm install --wait period?

Vincent J
  • 4,968
  • 4
  • 40
  • 50

2 Answers2

2

I don't think you can solve your problem with Helm post-install hook, but you may with vanilla Kubernetes jobs or perhaps hooks, i.e. running job/hook along with your deployment that will depend only on Kubernetes.

One of the first things to try is to remove helm.sh/hook annotations from your existing job.

  annotations:
    # This is what defines this resource as a hook. Without this line, the
    # job is considered part of the release.
    "helm.sh/hook": post-install
    "helm.sh/hook-weight": "-5"
    "helm.sh/hook-delete-policy": hook-succeeded

Helm can then wait for them to finish as they will be executed by Kubernetes.

Filip Nikolov
  • 1,687
  • 15
  • 22
  • unfortunately, if I remove the "install" hook, the install script will be launched at upgrades too... – Vincent J Feb 18 '20 at 13:46
  • Just throwing two idea here: Is it not possible to use some kind of persistent storage to store the state of the script - installed / not installed? Or check with the script if given resource/object is present before executing? – Filip Nikolov Feb 18 '20 at 14:15
  • In a similar situation, I wrapped the job in a `{{- if .Release.IsInstall -}}`. That way it is only created during the initial install - not on subsequent upgrades. See https://helm.sh/docs/chart_template_guide/builtin_objects/. – tfischbach Oct 21 '21 at 07:27
0

You can use delete policy

annotations:
    # This is what defines this resource as a hook. Without this line, the
    # job is considered part of the release.
    "helm.sh/hook": post-install
    "helm.sh/hook-weight": "-10"
    "helm.sh/hook-delete-policy": hook-succeeded , hook-failed , before-hook-creation
Vincent J
  • 4,968
  • 4
  • 40
  • 50