0

I am trying to build a template that loops over multiple partial contexts (instead of the root context) so that I could use relative data where I need it and reference the "root" context using $

My template function looks like

{{- $dot := . }}
{{- $files := .Files }}
{{- range $env := .Values.subChart.deployments.envs }}
{{- if eq $env.name $.Values.targetEnvironment -}}
{{ with $env }}
{{- range $file := $.Values.subChart.files }}
{{- tpl ($files.Get $file ) $dot -}}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

My values.yaml looks like

subChart:
  # Include all the files that you want the stack to use
  files:
    - files/autoscaling.yaml
    # - files/deployment.yaml
    # - files/nginx-config.yaml
    # - files/service.yaml
    # - files/serviceaccount.yaml
    # - files/sigsci-config.yaml
  deployments:
    envs:
      - name: dev
        deployment: extractor
      - name: dev
        deployment: loader
      - name: test
        deployment: extractor
      - name: test
        deployment: loader
targetEnvironment: dev

I want, given an environment, deploy the stack, consisting of all the files for all the apps types. This would generate one deployment file consisting of multiple deployment resource definitions.

The problem lies in using range within a with especially in this line {- tpl ($files.Get $file ) $dot -}} So far, I have tried, $dot, $, which results the same since I am essentially passing the root context. I would like to pass in $env so that I can refer to my deployment as .deployment but that fails with an error message

: "BasePath" is not a value

The template for files/autoscaling.yaml looks like

apple: {{ $.Values.targetEnvironment }}
banana: {{ .Values.name }}

Any ideas on how I can pass in the relative context as a second argument to the tpl function? Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.