title: Create file for secret in pre-install hook
body: <p>I have a helm chart and I need to create a file before installing all my resources to be able to store it in a secret. I have been reading about Helm Hooks and I think I can create a hook, insert my script files, run my script and generate the file I need, where I'm lost is on how can I get my file out of the pod and insert it as a secret.</p>
  <p>These are my hooks:</p>
  <p>Secret hook for the scripts:</p>
  <pre><code>apiVersion: v1
  kind: Secret
  metadata:
    name: hlf-genesis-block
    namespace: hlf
    annotations:
      &quot;helm.sh/hook&quot;: pre-install
      &quot;helm.sh/hook-weight&quot;: &quot;0&quot;
      &quot;helm.sh/hook-delete-policy&quot;: hook-succeeded
  type: Opaque
  data:
    createfile.sh: |-
      {{ .Files.Get &quot;scripts/createfile.sh&quot; | b64enc }}
  </code></pre>
  <p>Job Hook:</p>
  <pre><code>apiVersion: batch/v1
  kind: Job
  metadata:
    name: &quot;post-install-hook&quot;
    annotations:
      &quot;helm.sh/hook&quot;: post-install
      &quot;helm.sh/hook-weight&quot;: &quot;1&quot;
      &quot;helm.sh/hook-delete-policy&quot;: hook-succeeded
  spec:
    template:
      spec:
        volumes:
        - name: scripts
          secret:
            secretName: scripts
        restartPolicy: Never
        containers:
        - name: channel-config
          image: &quot;ubuntu:20.04&quot;
          command: [&quot;bash&quot;, &quot;-c&quot;, &quot;
                  domainname=\&quot;{{ .Values.domainName }}\&quot;
                  ./createfile.sh \&quot;$domainname\&quot;
                &quot;]
          volumeMounts:
          - mountPath: /home/
            name: scripts
            readOnly: true
  </code></pre>
  <p>Final secret file:</p>
  <pre><code>apiVersion: v1
  kind: Secret
  metadata:
    name: hlf-genesis-block
    namespace: hlf
  type: Opaque
  data:
    secret.txt: |-
      {{ .Files.Get &quot;generatedfile.txt&quot; | b64enc }}
  </code></pre>
  <p>I was thinking maybe like assigning a variable using something like this inside the job:</p>
  <pre><code>{{ $secret := echo generatedfile.txt }}
  </code></pre>
  <p>But I haven't found a function for it, or mapping a volume temporarily, but even that way I haven't been able to figure out how to take out the  secret from my job or the temporal storage, as the .Files.Get works from where the kubectl is running...</p>
  <p>Or maybe running kubectl from inside the job to create the secret? although then I wont be able to delete the secret on uninstall.</p>
  <p>Any ideas would be great.</p>
  <p>Thanks</p>
  <p>EDIT:</p>
  <p>Is it possible to modify the secret value by modifiing the mapped secret volume? I'm going to try that.</p>