_render.tpl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. {{/* Renders a dict of labels */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $ "labels" $labels) }}
  4. {{ include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $ "annotations" $annotations) }}
  5. */}}
  6. {{- define "ix.v1.common.lib.metadata.render" -}}
  7. {{- $labels := .labels -}}
  8. {{- $annotations := .annotations -}}
  9. {{- $rootCtx := .rootCtx -}}
  10. {{- $seenLabels := list -}}
  11. {{- $seenAnnotations := list -}}
  12. {{- with $labels -}}
  13. {{- range $k, $v := . -}}
  14. {{- if and $k $v -}}
  15. {{- if not (mustHas $k $seenLabels) }}
  16. {{ $k }}: {{ tpl $v $rootCtx | quote }}
  17. {{- $seenLabels = mustAppend $seenLabels $k -}}
  18. {{- end -}}
  19. {{- end -}}
  20. {{- end -}}
  21. {{- end -}}
  22. {{- with $annotations -}}
  23. {{- range $k, $v := . -}}
  24. {{- if and $k $v -}}
  25. {{- if not (mustHas $k $seenAnnotations) }}
  26. {{ $k }}: {{ tpl $v $rootCtx | quote }}
  27. {{- $seenAnnotations = mustAppend $seenAnnotations $k -}}
  28. {{- end -}}
  29. {{- end -}}
  30. {{- end -}}
  31. {{- end -}}
  32. {{- end -}}