'How to iterate files in a directory to create configmap use Asconfig function in helm

I have 'n' yaml files inside test folder. I want to mount it as configMap in helm as follows. The below sample is just to show two yaml files but I need to add entry like this for all yaml files under 'test' directory.

configmap.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
    name: sample-conf
data:
  sample-config.yaml: |
{{ tpl ( .Files.Get "test/sample-config.yaml" ) . | indent 4 }}
  sample1-config.yaml: |
{{ tpl ( .Files.Get "test/sample1-config.yaml" ) . | indent 4 }}

da-statefulset.yaml entry will look like:

apiVersion: v1
kind: Pod
metadata:
  name: my-lamp-site
spec:
    containers:
    - name: container-a
      image: My_image
      volumeMounts:
      - name: sample-profile
        mountPath: /root/dir1/sample-config.yaml
        subPath: sample-config.yaml
      - name: sample-profile
        mountPath: /root/dir1/sample-config.yaml
        subPath: sample-config.yaml
    volumes:
    - name: sample-profile
        configMap:
          items:
          - key: sample-config.yaml
            path: sample-config.yaml
          - key: sample1-config.yaml
            path: sample1-config.yaml
          name: sample-conf
          defaultMode: 0755

I saw the solution for creating configmap as below: configmap.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
    name: sample-conf
data:
  {{ (.Files.Glob "test/**.yaml").AsConfig | indent 4 }}

But how to use Asconfig function to prepare configmap with key: value as expected (above)? Also how to do iteration for the same in da-statefulset entries? As a note, I won't have these file names or its content inside values.yaml

It would be helpful if any one could help me on this. Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source