_tplvalues.tpl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. {{/*
  2. Copyright Broadcom, Inc. All Rights Reserved.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{/* vim: set filetype=mustache: */}}
  6. {{/*
  7. Renders a value that contains template perhaps with scope if the scope is present.
  8. Usage:
  9. {{ include "common.tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $ ) }}
  10. {{ include "common.tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $ "scope" $app ) }}
  11. */}}
  12. {{- define "common.tplvalues.render" -}}
  13. {{- $value := typeIs "string" .value | ternary .value (.value | toYaml) }}
  14. {{- if contains "{{" (toJson .value) }}
  15. {{- if .scope }}
  16. {{- tpl (cat "{{- with $.RelativeScope -}}" $value "{{- end }}") (merge (dict "RelativeScope" .scope) .context) }}
  17. {{- else }}
  18. {{- tpl $value .context }}
  19. {{- end }}
  20. {{- else }}
  21. {{- $value }}
  22. {{- end }}
  23. {{- end -}}
  24. {{/*
  25. Merge a list of values that contains template after rendering them.
  26. Merge precedence is consistent with http://masterminds.github.io/sprig/dicts.html#merge-mustmerge
  27. Usage:
  28. {{ include "common.tplvalues.merge" ( dict "values" (list .Values.path.to.the.Value1 .Values.path.to.the.Value2) "context" $ ) }}
  29. */}}
  30. {{- define "common.tplvalues.merge" -}}
  31. {{- $dst := dict -}}
  32. {{- range .values -}}
  33. {{- $dst = include "common.tplvalues.render" (dict "value" . "context" $.context "scope" $.scope) | fromYaml | merge $dst -}}
  34. {{- end -}}
  35. {{ $dst | toYaml }}
  36. {{- end -}}
  37. {{/*
  38. Merge a list of values that contains template after rendering them.
  39. Merge precedence is consistent with https://masterminds.github.io/sprig/dicts.html#mergeoverwrite-mustmergeoverwrite
  40. Usage:
  41. {{ include "common.tplvalues.merge-overwrite" ( dict "values" (list .Values.path.to.the.Value1 .Values.path.to.the.Value2) "context" $ ) }}
  42. */}}
  43. {{- define "common.tplvalues.merge-overwrite" -}}
  44. {{- $dst := dict -}}
  45. {{- range .values -}}
  46. {{- $dst = include "common.tplvalues.render" (dict "value" . "context" $.context "scope" $.scope) | fromYaml | mergeOverwrite $dst -}}
  47. {{- end -}}
  48. {{ $dst | toYaml }}
  49. {{- end -}}