How can we read index.js file in configmap with TPL function in Helm. Means how to read below like index.js file.
exports.CDN_URL = 'http://100.470.255.255/';
exports.CDN_NAME = 'staticFilesNew';
exports.REDIS = [
{
host: 'redis-{{.Release.Name}}.{{.Release.Namespace}}.svc.cluster.local',
port: '26379',
},
];
file structure is below
.
├── Chart.yaml
├── templates
│ ├── NOTES.txt
│ ├── _helpers.tpl
│ ├── configmap.yaml
│ ├── deployment.yaml
│ └── service.yaml
└── values
├──values.yaml
├── index.js
tried with below solution on configmap.yaml but getting error
apiVersion: v1
kind: ConfigMap
metadata:
name: test_config
data:
{{- tpl (.Files.Get (printf "values/index.js" .)) . | quote 12 }}
Getting ERROR
Error: YAML parse error on app-name/templates/configmap.yaml: error converting YAML to JSON: yaml: line 6: did not find expected key
helm.go:88: [debug] error converting YAML to JSON: yaml: line 6: did not find expected key
So it works what you are trying but I think you have issues with the indention.
Use nindent
to ensure all lines are indented and dont quote the value.
kind: ConfigMap
apiVersion: v1
metadata:
name: test
namespace: test
data:
index.js: | {{- tpl (.Files.Get "values/index.js") $ | nindent 4 }}