Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read secrets from file in Helm

I've created some secrets and I'm trying to import the file in this way:

apiVersion: v1
kind: Secret
metadata:
  name: {{ template "amq.broker.fullname" . }}-tls
  labels:
    app: {{ template "amq.name" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    component: "{{ .Values.broker.name }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
type: Opaque
data:
{{ (.Files.Glob "secrets/broker.ks").AsSecrets | indent 2 }}

The file is under the secrets dir. When I run the install, the broker.ks secret is not there. However the secret is under the secrets folder. Any idea?

Here the dir struct

├── Chart.yaml
├── README.md
├── secrets
│   ├── broker.ks
│   ├── broker_cert
│   ├── client.ks
│   └── client.ts
├── templates
│   ├── NOTES.txt
│   ├── _helpers.tpl
└── values.yaml
like image 482
Mazzy Avatar asked Nov 28 '17 17:11

Mazzy


Video Answer


1 Answers

The solution to this is, as per the docs, the following:

{{- $root := . -}}
{{- range $path, $bytes := .Files.Glob "secrets/broker.ks" }}
{{ base $path }}: '{{ $root.Files.Get $path | b64enc }}'
{{- end }}

You can also pull all the files of a specific type in the folder with .Files.Glob "secrets/*.ks"

Also make sure that the folder has not been added to .helmignore otherwise the files won't be accessible.

like image 60
iomv Avatar answered Sep 28 '22 11:09

iomv