Helm: howto use ".Files.Get" to import a json into a config map

8/15/2019

I try to import a json file into a configmap but the map doesn't contain the file.

my ConfigMap-Template:

apiVersion: v1
kind: ConfigMap
metadata:
  name: serilog-configmap
data:
  serilog.json: |-
{{ .Files.Get "serilog.json" | indent 4}}

serilog.json is in the root-path of the Project, there is a sub-dir with the Chart and the templetes ( from helm create ).

I allso tried "../../serilog.json" and the fullpath as the filename but it allways ends with the same result when i run helm install --debug --dry-run.

---
# Source: hellowebapi/templates/serilogConfigMap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: serilog-configmap
data:
  serilog.json: |-
---

I would excpect:

---
# Source: hellowebapi/templates/serilogConfigMap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: serilog-configmap
data:
  serilog.json: |-
{
    "Serilog": {
        "Using": [
            "Serilog.Sinks.ColoredConsole"
        ],
...
---

Can anybody tell me where i make my mistake?

-- Harald Pollak
kubernetes-helm

1 Answer

8/15/2019

Your json file should be in your chart directory.

See Accessing Files Inside Templates

λ ls
Chart.yaml  charts/  serilog.json  templates/  values.yaml

λ helm template .
---
# Source: templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: serilog-configmap
data:
  serilog.json: |-
    {
      "Serilog": {
        "Using": [
            "Serilog.Sinks.ColoredConsole"
        ]
      }
    }
-- edbighead
Source: StackOverflow