amrit sandhu
amrit sandhu

Reputation: 170

Helm configMap support for binary files

I am trying to create a helm chart of kind ConfigMap that will replace the following command from kubernates.

kubectl create configmap my-config -n $namespace --from-file=./my-directory

my-directory contains around 5 files, 2 of them are properties file and 2 of them jpg file. I see the following result for kubectl get cm, I can see 4 DATA files in configMap

[admin@cluster ~]$ kubectl get cm
NAME                   DATA   AGE
warm-up-config         4      41m

I created a template as follows, it work if I specify only properties file but If I add jpg files it doesn't work at all

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
data:
{{ (.Files.Glob "resources/*").AsConfig | nindent 2 }}

Does anyone know how I make this work.

Upvotes: 3

Views: 4626

Answers (2)

D-rk
D-rk

Reputation: 5919

To make this a bit more dynamic use this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
data:
  {{ (.Files.Glob "resources/*").AsConfig | nindent 2 }}
binaryData:
  {{ range $path, $_ :=  .Files.Glob "resources/*.jpg" }}
  {{ base $path | nindent 2 }}:
    {{ $.Files.Get $path | b64enc | nindent 4 }}
  {{ end }}

Upvotes: 0

user15659347
user15659347

Reputation:

JPG files are binary, and should be added as such.

data:
  binaryData:
    {{ .Files.Get "/path/to/file.jpg" }}

Files in binaryData field must be encoded with base64, so:

{{ .Files.Get "/path/to/file.jpg" | b64enc }}

Don't forget proper indentation:

{{ .Files.Get "/path/to/file.jpg" | b64enc | nindent 4 }}

Upvotes: 7

Related Questions