Helm subchart pre-upgrade hooks run every time the umbrella chart is upgraded

Viewed 635

I have an umbrella helm chart which has subcharts. Some of the subcharts have pre-install/pre-upgrade hooks (jobs). Every time I run helm upgrade <release name> <umbrella chart> the pre-upgrade hooks of all subcharts are executed, even if there are no changes in corresponding subcharts.

Is this expected behavior? And is there a possibility to run subchart hooks only in case when there are changes in subchart?

UPD: more details

So this is the chart structure:

parent_chart/
├─ charts/
│  ├─ child_chart_1/
│  │  ├─ templates/
│  │  │  ├─ hooks_1.yaml
│  │  │  ├─ deployment_1.yaml
│  │  ├─ Chart.yaml
│  │  ├─ values.yaml
│  ├─ child_chart_2/
│  │  ├─ templates/
│  │  │  ├─ deployment_2.yaml
│  │  │  ├─ hooks_2.yaml
│  │  ├─ Chart.yaml
│  │  ├─ values.yaml
├─ values.yaml
├─ Chart.yaml

hook manifest looks like this:

apiVersion: batch/v1
kind: Job
metadata:
  name: {{ .Release.Name }}-migration-hook
  namespace: {{ .Values.namespace }}
  labels:
    app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
    app.kubernetes.io/instance: {{ .Release.Name | quote }}
    helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
  annotations:
    "helm.sh/hook": pre-install, pre-upgrade
    "helm.sh/hook-weight": "-5"
    "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
  ...

Let's assume this chart is installed.
Then I do changes in child_chart_1/values.yaml and upgrade the umbrella chart:

helm upgrade release_name parent_chart

During the upgrade hooks from both hooks_1.yaml and hooks_2.yaml are executed, but I need only hooks_1.yaml to run, because there are no changes in child_chart_2.

1 Answers

Try to add the annotation checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} to avoid the executing the child chart that was not updated. So if the spec is not changed, then the application keeps running with the old configuration resulting in an inconsistent deployment.

For more information please refer to this 'Chart Development Tips and Tricks' article


UPDATE

Then it's expected behaviour. What's your Helm version? Since it's was totally expected behaviour in Helm 2 and there is a Issue in GitHub with similar problem as yours.

Also we can see the resolution comment that's explaining of New 3-way Strategic Merge Patches that should resolve this issue somehow, but in their examples I can't see that it was fixed with the annotation pre-upgrade. Fell free to open that issue and ping them.

Related