Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 402
Harald Pollak Avatar asked Aug 15 '19 06:08

Harald Pollak


People also ask

How do I copy a local file to a helm deployment?

You can either put config file directly into confimap and use it there via helm rendering. Or using initContainers you can change config file via some sort of bash script. Because initContainers run before the actual container and volumes can be shared.

What is a TPL file in Helm?

Helm allows for the use of Go templating in resource files for Kubernetes. A file named _helpers.tpl is usually used to define Go template helpers with this syntax: {{- define "yourFnName" -}} {{- printf "%s-%s" .Values.name .Values.version | trunc 63 -}} {{- end -}}


1 Answers

Try this :

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: serilog-configmap
data:
  serilog.json: |-
    {{- $.Files.Get "configurations/serilog.json"  | nindent 6 -}}

with a relative path for the json file (hellowebapi/configurations/serilog.json)

It will produce :

---
# Source: serilog/templates/test.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: serilog-configmap
data:
  serilog.json: |-
      {
          "apiVersion": "v1",
          "kind": "Pod",
          "metadata": {
              "annotations": {
like image 147
Bertrand Avatar answered Oct 23 '22 04:10

Bertrand