_secret.tpl 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. {{/* Returns Secret Volume */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.pod.volume.secret" (dict "rootCtx" $ "objectData" $objectData) }}
  4. rootCtx: The root context of the chart.
  5. objectData: The object data to be used to render the volume.
  6. */}}
  7. {{- define "ix.v1.common.lib.pod.volume.secret" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- if not $objectData.objectName -}}
  11. {{- fail "Persistence - Expected non-empty <objectName> on <secret> type" -}}
  12. {{- end -}}
  13. {{- $objectName := tpl $objectData.objectName $rootCtx -}}
  14. {{- $expandName := true -}}
  15. {{- if kindIs "bool" $objectData.expandObjectName -}}
  16. {{- $expandName = $objectData.expandObjectName -}}
  17. {{- end -}}
  18. {{- if $expandName -}}
  19. {{- $object := (get $rootCtx.Values.secret $objectName) -}}
  20. {{- $certObject := (get $rootCtx.Values.scaleCertificate $objectName) -}}
  21. {{- if and (not $object) (not $certObject) -}}
  22. {{- fail (printf "Persistence - Expected secret [%s] defined in <objectName> to exist" $objectName) -}}
  23. {{- end -}}
  24. {{- $objectName = (printf "%s-%s" (include "ix.v1.common.lib.chart.names.fullname" $rootCtx) $objectName) -}}
  25. {{- end -}}
  26. {{- $defMode := "" -}}
  27. {{- if (and $objectData.defaultMode (not (kindIs "string" $objectData.defaultMode))) -}}
  28. {{- fail (printf "Persistence - Expected <defaultMode> to be [string], but got [%s]" (kindOf $objectData.defaultMode)) -}}
  29. {{- end -}}
  30. {{- with $objectData.defaultMode -}}
  31. {{- $defMode = tpl $objectData.defaultMode $rootCtx -}}
  32. {{- end -}}
  33. {{- if and $defMode (not (mustRegexMatch "^[0-9]{4}$" $defMode)) -}}
  34. {{- fail (printf "Persistence - Expected <defaultMode> to have be in format of [\"0777\"], but got [%q]" $defMode) -}}
  35. {{- end }}
  36. - name: {{ $objectData.shortName }}
  37. secret:
  38. secretName: {{ $objectName }}
  39. {{- with $defMode }}
  40. defaultMode: {{ . }}
  41. {{- end -}}
  42. {{- with $objectData.items }}
  43. items:
  44. {{- range . -}}
  45. {{- if not .key -}}
  46. {{- fail "Persistence - Expected non-empty <items.key>" -}}
  47. {{- end -}}
  48. {{- if not .path -}}
  49. {{- fail "Persistence - Expected non-empty <items.path>" -}}
  50. {{- end }}
  51. - key: {{ tpl .key $rootCtx }}
  52. path: {{ tpl .path $rootCtx }}
  53. {{- end -}}
  54. {{- end -}}
  55. {{- end -}}