<p>I have a pre-upgrade hook in my Helm chart that looks like this:</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:
    # This is what defines this resource as a hook. Without this line, the
    # job is considered part of the release.
    "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
      securityContext:
#       Because we are running as non root user and group id/User id of the flink user is 1000/1000.
        fsGroup: {{ .Values.spec.securityContext.fsGroup }}
        runAsNonRoot: {{ .Values.spec.securityContext.runAsNonRootFlag }}
        runAsUser: {{ .Values.spec.securityContext.runAsUser }}
      containers:
      - name: pre-upgrade-job
        image: {{ .Values.registry }}/{{ .Values.imageRepo }}:{{ .Values.imageTag }}
        imagePullPolicy: {{ .Values.imagePullPolicy }}
# Got error /bin/sleep: invalid time interval 'lcm_hook'
        args:
        - lcm_hook
        env:
#       Need to add this env variable so that the custom flink conf values will be written to $FLINK_HOME/conf.
#       This is needed for the hook scripts to connect to the Flink JobManager
        - name: FLINK_KUBE_CONFIGMAP_PATH
          value: {{ .Values.spec.config.mountPath }}
        volumeMounts:
        - name: {{ template "fullname" . }}-flink-config
          mountPath: {{ .Values.spec.config.mountPath }}
        - 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" . }}"]
        command: ["/bin/sleep","10"]
      volumes:
        - name: {{ template "fullname" . }}-flink-config
          configMap:
            name: {{ template "fullname" . }}-flink-config
        - name: shared-pvc
          persistentVolumeClaim:
            claimName: {{ template "fullname" . }}-shared-pv-claim
</code></pre>

<p>Here, I need to pass an argument called "lcm_hooks" to my docker container. But when I do this, this argument seems to override the argument for my second command ["/bin/sleep","10"], and I get an error </p>

<blockquote>
  <p>/bin/sleep: invalid time interval 'lcm_hook'</p>
</blockquote>

<p>during the upgrade phase. What is the right way to ensure that I am able to pass one argument to my container, and a totally different one to my bash command in the helm hook?</p>

James Isaac
<blockquote>
  <p>my docker container, called "lcm_hooks"</p>
</blockquote>

<p>Your hook has one container which is not called <code>lcm_hooks</code>, you called it <code>pre-upgrade-job</code>. I'm mentioning this because perhaps you forgot to include a piece of code, or misunderstood how it works.</p>

<blockquote>
  <p>I need to pass an argument to my docker container</p>
</blockquote>

<p>Your yaml specifies both <code>command</code> and <code>args</code>, therefore the image's original <code>entrypoint</code> and <code>cmd</code> will be completely ignored. If you want to "pass argument to container" you should omit the <code>command</code> from the yaml and override the <code>args</code> only.</p>

<blockquote>
  <p>second command</p>
</blockquote>

<p>Your container spec does specify two commands, which means only the latter will execute. If you want to execute both of them you should chain them.</p>

<blockquote>
  <p>What is the right way to ensure that I am able to pass one argument to my container, and a totally different one to my bash command in the helm hook</p>
</blockquote>

<p>You separate the hook container from the actual container you wanted to deploy using Helm.</p>

<p>I recommend the you review the container spec, and Helm hooks docs, that might clarify things:</p>

<ul>
<li><a href="https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell</a></li>
<li><a href="https://github.com/kubernetes/helm/blob/master/docs/charts_hooks.md" rel="nofollow noreferrer">https://github.com/kubernetes/helm/blob/master/docs/charts_hooks.md</a></li>
</ul>
