chart icon indicating copy to clipboard operation
chart copied to clipboard

helm install order of operations prioritizes db migrate job before env

Open jessebot opened this issue 1 year ago • 1 comments

When installing this chart via ArgoCD, it always tries to create job-db-migreate.yaml first, but it can't run the job without the configmap-env.yaml being applied, but the config map can't be applied because the job is set to run before everything else via a helm hook:

https://github.com/mastodon/chart/blob/4b6fd9f7e6273cb2708e5f8e16b87b1d07114eb8/templates/job-db-migrate.yaml#L7-L10

According to the helm docs:

pre-install - Executes after templates are rendered, but before any resources are created in Kubernetes post-install - Executes after all resources are loaded into Kubernetes

and the same docs further down:

Helm defines two hooks for the install lifecycle: pre-install and post-install. If the developer of the foo chart implements both hooks, the lifecycle is altered like this: ... 4. After some verification, the library renders the foo templates 5. The library prepares to execute the pre-install hooks (loading hook resources into Kubernetes) 6. The library sorts hooks by weight (assigning a weight of 0 by default), by resource kind and finally by name in ascending order. 7. The library then loads the hook with the lowest weight first (negative to positive) 8. The library waits until the hook is "Ready" (except for CRDs) 9. The library loads the resulting resources into Kubernetes. Note that if the --wait flag is set, the library will wait until all resources are in a ready state and will not run the post-install hook until they are ready. 10. The library executes the post-install hook (loading hook resources) 11. The library waits until the hook is "Ready"

But the config map doesn't have anything similar: https://github.com/mastodon/chart/blob/4b6fd9f7e6273cb2708e5f8e16b87b1d07114eb8/templates/configmap-env.yaml#L3-L7

I can submit a PR to add the following to the configmap-env.yaml:

metadata:
  annotations: 
    "helm.sh/hook": pre-install
    "helm.sh/hook-weight": "-3"

I believe this might also affect https://github.com/mastodon/chart/issues/18 because the job has highest priority and is executed before the configMap would be available.

jessebot avatar Jul 06 '23 10:07 jessebot

Further discussion is taking place in #74

jessebot avatar Jul 06 '23 11:07 jessebot