<p>I'm planning to have an <em>initcontainer</em> that will handle some crypto stuff and then generate a source file to be sourced by a <em>container</em>.
The source file will be dynamically generated, the VARS will be dynamic, this means I will never know the VAR names or it's contents. This also means I cannot use k8s <em>env</em>.
The file name will always be the same.</p>
<p>I know I can change the Dockerfile from my applications and include an entrypoint to execute a script before running the workload to source the file, but, still, is this the only option?
There's no way to achieve this in k8s?</p>
<p>My <em>container</em> can mount the dir where the file was created by the <em>initcontainer</em>. But it can't, somehow, source the file?</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: pod-init
  namespace: default
spec:
  nodeSelector:
    env: sm
  initContainers:
    name: genenvfile
    image: busybox
    imagePullPolicy: Always
    command: [&quot;/bin/sh&quot;]
    # just an example, there will be a software here that will translate some encrypted stuff into VARS and then append'em to a file
    args: [&quot;-c&quot;, &quot;echo MYVAR=func &gt; /tmp/sm/filetobesourced&quot;]
    volumeMounts:
    - mountPath: /tmp/sm
      name: tmpdir
  containers:
    image: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
    imagePullPolicy: IfNotPresent
    name: mypod-cm
    tty: true
    volumeMounts:
    - mountPath: /tmp/sm
      readOnly: true
      name: tmpdir
  volumes:
    name: tmpdir
    emptyDir:
      medium: Memory
</code></pre>
<p>The step-by-step that I'm thinking would be:</p>
<ol>
<li><em>initcontainer</em> mounts /tmp/sm and generates a file called /tmp/sm/filetobesourced</li>
<li><em>container</em> mounts the /tmp/sm</li>
<li><em>container</em> source the /tmp/sm/filetobesourced</li>
<li>workload runs using all the vars sourced by the last step</li>
</ol>
<p>Am I missing something to get the third step done?</p>

JGG
<p>Change the <code>command</code> and/or <code>args</code> on the main container to be more like <code>bash -c 'source /tmp/sm/filetobesourced &amp;&amp; exec whatevertheoriginalcommandwas'</code>.</p>
