ramesh reddy
ramesh reddy

Reputation: 597

trying to create configmap which takes the config from environments folder. but unable to find correct syntax

I am creating configmap YAML file using helm, we are injecting JSON data from respective environments folders, but could not get exact helm syntax.

we have a folder structure like files/Dev, files/Tst, Files/ACC, files/PRD

I have environment variable in values_dev.yaml

environment: Dev

my configmap.yaml

data: {{- .Files.Get "files/%s/*".Values.environment" | fromJson | toYaml | nindent 2 }}

but it did not work.. any help is much-appreciated .thanks in advance

Upvotes: 0

Views: 370

Answers (1)

edbighead
edbighead

Reputation: 6334

If you are planning to inject Configmap data into a volume

apiVersion: v1
kind: ConfigMap
metadata:
  name: configmap
data: 
{{- range $path, $_ :=  .Files.Glob  (printf "files/%s/*" .Values.environment ) }}
  {{ base $path }}: |-
{{ $.Files.Get $path | indent 4 }} 
{{ end }}

If you want to configure all key-value pairs in a ConfigMap as container environment variables

apiVersion: v1
kind: ConfigMap
metadata:
  name: configmap
data: 
{{ $files := (.Files.Glob (printf "files/%s/*" .Values.environment ) ) }}
{{- range $k,$v := $files }}
  {{ $file := fromJson ($.Files.Get $k)  }}
  {{- range $key,$val := $file }}
    {{- $key | squote }}: {{ $val | squote }}
  {{ end }}
{{ end }}

File structure

.
├── Chart.yaml
├── files
│   └── dev
│       └── file1.json
├── templates
│   ├── _helpers.tpl
│   ├── configmap.yaml
│   └── pod.yaml
└── values.yaml

Upvotes: 2

Related Questions