2 min read | by Jordi Prats
When writing helm charts being able to specify the files to use for ConfigMap or a Secret objects is way more convenient than having the object already rendered. Using .Files.Glob we can tell help to import a set of files into the object
If we want to push a file into a ConfigMap we can specify to .Files.Glob the files we want to import (we can use a wildcard for that) and then we can use AsConfig to it's result to be able to push it to a ConfigMap object, for example:
apiVersion: v1
kind: ConfigMap
metadata:
name: cm-demo
data:
{{ (.Files.Glob "foo/*").AsConfig | indent 2 }}
For Secret it works the same way it does for ConfigMap, we just need to use AsSecrets instead:
apiVersion: v1
kind: Secret
metadata:
name: secret-demo
type: Opaque
data:
{{ (.Files.Glob "bar/*").AsSecrets | indent 2 }}
These functions are available starting Helm 2.0.2
Posted on 08/07/2022