<p>I have written Pre- and Post-upgrade hooks for my Helm chart, which will get invoked when I do a helm upgrade. My Pre-upgrade hook is supposed to write some information to a file in the shared persistent storage volume. Somehow, I dont see this file getting created though I am able to see the hook getting invoked.</p>

<p>This is what my pre-upgrade hook looks like:</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: "{{.Release.Name}}-preupgrade"
  labels:
    heritage: {{.Release.Service | quote }}
    release: {{.Release.Name | quote }}
    chart: "{{.Chart.Name}}-{{.Chart.Version}}"
  annotations:
    "helm.sh/hook": pre-upgrade
    "helm.sh/hook-weight": "0"
    "helm.sh/hook-delete-policy": hook-succeeded
spec:
  template:
    metadata:
      name: "{{.Release.Name}}"
      labels:
        heritage: {{.Release.Service | quote }}
        release: {{.Release.Name | quote }}
        chart: "{{.Chart.Name}}-{{.Chart.Version}}"
  spec:
    restartPolicy: Never
    containers:
    - name: pre-upgrade-job
      image: {{ .Values.registry }}/{{ .Values.imageRepo }}:{{ .Values.imageTag }}
      imagePullPolicy: {{ .Values.imagePullPolicy }}
      volumeMounts:
      - mountPath: {{ .Values.pvc.shared_storage_path }}/{{ template "fullname" . }}
        name: shared-pvc
        command: ['/bin/sh -c scripts/preUpgradeScript.sh {{ .Values.pvc.shared_storage_path }}/{{ template "fullname" . }}']
  volumes:
    - name: shared-pvc
      persistentVolumeClaim:
        claimName: {{ template "fullname" . }}-shared-pv-claim
</code></pre>

<p>My expectation is that the hook should be able to write information to the PVC volume which was already created prior to the upgrade. When I did a describe on the upgrade pods, I could see the following error:</p>

<pre><code>Error: failed to start container "pre-upgrade-job": Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/bin/sh -c scripts/preUpgradeScript.sh /opt/flink/share/myfl-flink\": stat /bin/sh -c scripts/preUpgradeScript.sh /opt/flink/share/myfl-flink: no such file or directory"
</code></pre>

<p>Doesn't the hook first mount the volume before running the command? Also, I'm packaging the script with the docker image, so I believe it should be there.
I am unable to exec into the hook pod as it goes into the Failed state.
Can anyone help me with this?</p>

<p>[Update] I added a sleep command to enter the pod and check if the script is available and if the mount path exists. All looks fine. I don't understand why this error would come up.</p>

James Isaac
<p>Looks like I needed to give the command differently:</p>

<pre><code>command: ["/bin/sh", "-c", "scripts/preUpgradeScript.sh","{{ .Values.pvc.shared_storage_path }}/{{ template "fullname" . }}"]
</code></pre>
