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.
These are my hooks:
Secret hook for the scripts:
apiVersion: v1
kind: Secret
metadata:
name: hlf-genesis-block
namespace: hlf
annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": hook-succeeded
type: Opaque
data:
createfile.sh: |-
{{ .Files.Get "scripts/createfile.sh" | b64enc }}
Job Hook:
apiVersion: batch/v1
kind: Job
metadata:
name: "post-install-hook"
annotations:
"helm.sh/hook": post-install
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
spec:
volumes:
- name: scripts
secret:
secretName: scripts
restartPolicy: Never
containers:
- name: channel-config
image: "ubuntu:20.04"
command: ["bash", "-c", "
domainname=\"{{ .Values.domainName }}\"
./createfile.sh \"$domainname\"
"]
volumeMounts:
- mountPath: /home/
name: scripts
readOnly: true
Final secret file:
apiVersion: v1
kind: Secret
metadata:
name: hlf-genesis-block
namespace: hlf
type: Opaque
data:
secret.txt: |-
{{ .Files.Get "generatedfile.txt" | b64enc }}
I was thinking maybe like assigning a variable using something like this inside the job:
{{ $secret := echo generatedfile.txt }}
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...
Or maybe running kubectl from inside the job to create the secret? although then I wont be able to delete the secret on uninstall.
Any ideas would be great.
Thanks
EDIT:
Is it possible to modify the secret value by modifiing the mapped secret volume? I'm going to try that.