<p>I am trying to migrate our cassandra tables to use <code>liquibase</code>. Basically the idea is trivial, have a <code>pre-install</code> and <code>pre-upgrade</code> job that will run some <code>liquibase</code> scripts and will manage our database upgrade.</p>
<p>For that purpose I have created a custom docker image that will have the actual <code>liquibase cli</code> and then I can invoke it from the job. For example:</p>
<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: &quot;{{ .Release.Name }}-update-job&quot;
  namespace: spring-k8s
  labels:
    app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
    app.kubernetes.io/instance: {{ .Release.Name | quote }}
    app.kubernetes.io/version: {{ .Chart.AppVersion }}
    helm.sh/chart: &quot;{{ .Chart.Name }}-{{ .Chart.Version }}&quot;
  annotations:
    # This is what defines this resource as a hook. Without this line, the
    # job is considered part of the release.
    &quot;helm.sh/hook&quot;: pre-install, pre-upgrade
    &quot;helm.sh/hook-weight&quot;: &quot;5&quot;
    &quot;helm.sh/hook-delete-policy&quot;: before-hook-creation
spec:
  template:
    metadata:
      name: &quot;{{ .Release.Name }}-cassandra-update-job&quot;
      namespace: spring-k8s
      labels:
        app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
        app.kubernetes.io/instance: {{ .Release.Name | quote }}
        helm.sh/chart: &quot;{{ .Chart.Name }}-{{ .Chart.Version }}&quot;
    spec:
      restartPolicy: Never
      containers:
        - name: pre-install-upgrade-job
          image: &quot;lq/liquibase-cassandra:1.0.0&quot;
          command: [&quot;/bin/bash&quot;]
          args:
            - &quot;-c&quot;
            - &quot;./liquibase-cassandra.sh --username {{ .Values.liquibase.username }} --password {{ .Values.liquibase.username }} --url {{ .Values.liquibase.url | squote }} --file {{ .Values.liquibase.file }}&quot;
</code></pre>
<p>Where <code>.Values.liquibase.file</code> == <code>databaseChangelog.json</code>.</p>
<p>So this image <code>lq/liquibase-cassandra:1.0.0</code> basically has a script <code>liquibase-cassandra.sh</code> that when passed some arguments can do its magic and update the DB schema (not going to go into the details).</p>
<p>The problem is that last argument: <code>--file {{ .Values.liquibase.file }}</code>. This file resides <em>not</em> in the image, obviously, but in each micro-services repository.</p>
<p>I need a way to &quot;copy&quot; that file to the image, so that I could invoke it. One way would be to build this <code>lq/liquibase-cassandra</code> all the time (with the same lifecycle of the project itself) and copy the file into it, but that will take time and seems like at least cumbersome. What am I missing?</p>

<p>It turns out that <code>helm</code> hooks can be used for other things, not only jobs. As such, I can mount this file into a <code>ConfigMap</code> <em>before</em> the Job even starts (the file I care about resides in <code>resources/databaseChangelog.json</code>):</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: &quot;liquibase-changelog-config-map&quot;
  namespace: spring-k8s
  annotations:
    helm.sh/hook: pre-install, pre-upgrade
    helm.sh/hook-delete-policy: hook-succeeded
    helm.sh/hook-weight: &quot;1&quot;
data:
{{ (.Files.Glob &quot;resources/*&quot;).AsConfig | indent 2 }}
</code></pre>
<p>And then just reference it inside the job:</p>
<pre><code>  .....
  spec:
  restartPolicy: Never
  volumes:
    - name: liquibase-changelog-config-map
      configMap:
        name: liquibase-changelog-config-map
        defaultMode: 0755
  containers:
    - name: pre-install-upgrade-job
      volumeMounts:
        - name: liquibase-changelog-config-map
          mountPath: /liquibase-changelog-file
      image: &quot;lq/liquibase-cassandra:1.0.0&quot;
      command: [&quot;/bin/bash&quot;]
      args:
        - &quot;-c&quot;
        - &quot;./liquibase-cassandra.sh --username {{ .Values.liquibase.username }} --password {{ .Values.liquibase.username }} --url {{ .Values.liquibase.url | squote }} --file {{ printf &quot;/liquibase-changelog-file/%s&quot; .Values.liquibase.file }}&quot;
</code></pre>
