helmfile/pkg/tmpl
Nils 753de35ee0
Add readDir as a templating function (#1934)
Adds a new templating function called `readDir`. With `readDir` users can read the contents of a specified directory and get a list of all contained files. This is useful when reading a bunch of files from a directory. The following example shows a snippet of a values file for configuring a Logstash deployment. Using only `readFile`, a user must specify each file by hand and adjust this list as the number of files to be read grows.
```yaml
logstash:
  configs:
    logstash.yml: |
      {{- tpl (readFile "config/logstash.yml.gotmpl") . | nindent 6 }}
    jvm.options: |
      {{- readFile "config/jvm.options" | nindent 6 }}
    pipelines.yml: |
      {{- readFile "config/pipelines.yml" | nindent 6 }}
  pipelines:
    beats-log4j.conf: |
      {{- readFile "config/pipelines/beats-log4j.conf" | nindent 6 }}
    nginx-access.conf: |
      {{- readFile "config/pipelines/nginx-access.conf" | nindent 6 }}
    nginx-error.conf: |
      {{- readFile "config/pipelines/nginx-error.conf" | nindent 6 }}
    syslog-logs.conf: |
      {{- readFile "config/pipelines/syslog-logs.conf" | nindent 6 }}
    tcp-logs.conf: |
      {{- readFile "config/pipelines/tcp-logs.conf" | nindent 6 }}
    udp-debug.conf: |
      {{- readFile "config/pipelines/udp-debug.conf" | nindent 6 }}
    udp-logs.conf: |
      {{- readFile "config/pipelines/udp-logs.conf" | nindent 6 }}
  certificates:
    ca.crt: |
      {{- readFile "config/certificates/ca.crt" | nindent 6 }}
    logstash.crt: |
      {{- readFile "config/certificates/logstash.crt" | nindent 6 }}
    logstash.key: |
      {{- readFile "config/certificates/logstash.key" | nindent 6 }}
```
With `readDir` the above snippet can be rewritten as follows:
```yaml
logstash:
  configs:
  {{- range readDir "config" }}
    {{ base . }}: |
      {{- if hasSuffix "gotmpl" . }}
          {{- tpl (readFile .) $ | nindent 6 }}
      {{- else }}
          {{- readFile . | nindent 6 }}
      {{- end }}
  {{- end }}
  pipelines:
  {{- range readDir "config/pipelines" }}
    {{ base . }}: |
      {{- readFile . | nindent 6 }}
  {{- end }}
  certificates:
  {{- range readDir "config/certificates" }}
    {{ base . }}: |
      {{- readFile . | nindent 6 }}
  {{- end }}
```
2022-01-10 17:22:24 +09:00
..
context.go chore: tidy up pkgs (#636) 2019-06-01 13:36:05 +09:00
context_funcs.go Add readDir as a templating function (#1934) 2022-01-10 17:22:24 +09:00
context_funcs_test.go Use ghodss/yaml for yaml marshaling & unmarshaling in template (#1556) 2020-12-13 11:03:20 +09:00
context_tmpl.go feat: Helmfile renders *.yaml.gotmpl in a K8s manifests/kustomization directory (#1745) 2021-04-06 14:22:34 +09:00
context_tmpl_test.go feat: add tmpl function `required` (#1188) 2020-04-10 08:23:42 +09:00
expand_secret_ref.go feat(template): added secret template function (#1221) 2020-04-25 21:10:02 +09:00
expand_secret_ref_test.go feat(template): added secret template function (#1221) 2020-04-25 21:10:02 +09:00
expand_secrets_mock.go feat(template): added secret template function (#1221) 2020-04-25 21:10:02 +09:00
file_renderer.go fix: --state-values-set panic: value of type interface {} is not assignable to type string (#680) 2019-06-12 13:35:04 +09:00
file_renderer_test.go chore: tidy up pkgs (#636) 2019-06-01 13:36:05 +09:00
get_or_nil.go chore: tidy up pkgs (#636) 2019-06-01 13:36:05 +09:00
get_or_nil_test.go chore: tidy up pkgs (#636) 2019-06-01 13:36:05 +09:00
sprig_functions_test.go Bump sprig to v3.1.0 and mergo 3.11 (#1456) 2020-09-04 09:58:54 +09:00
text_renderer.go chore: tidy up pkgs (#636) 2019-06-01 13:36:05 +09:00