_secret.tpl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. {{/* Secret Class */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.class.secret" (dict "rootCtx" $ "objectData" $objectData) }}
  4. rootCtx: The root context of the chart.
  5. objectData:
  6. name: The name of the secret.
  7. labels: The labels of the secret.
  8. annotations: The annotations of the secret.
  9. type: The type of the secret.
  10. data: The data of the secret.
  11. */}}
  12. {{- define "ix.v1.common.class.secret" -}}
  13. {{- $rootCtx := .rootCtx -}}
  14. {{- $objectData := .objectData -}}
  15. {{- $secretType := "Opaque" -}}
  16. {{- if eq $objectData.type "certificate" -}}
  17. {{- $secretType = "kubernetes.io/tls" -}}
  18. {{- else if eq $objectData.type "imagePullSecret" -}}
  19. {{- $secretType = "kubernetes.io/dockerconfigjson" -}}
  20. {{- else if $objectData.type -}}
  21. {{- $secretType = $objectData.type -}}
  22. {{- end }}
  23. ---
  24. apiVersion: v1
  25. kind: Secret
  26. type: {{ $secretType }}
  27. metadata:
  28. name: {{ $objectData.name }}
  29. {{- $labels := (mustMerge ($objectData.labels | default dict) (include "ix.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}}
  30. {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }}
  31. labels:
  32. {{- . | nindent 4 }}
  33. {{- end -}}
  34. {{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "ix.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}}
  35. {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }}
  36. annotations:
  37. {{- . | nindent 4 }}
  38. {{- end -}}
  39. {{- if (mustHas $objectData.type (list "certificate" "imagePullSecret")) }}
  40. data:
  41. {{- if eq $objectData.type "certificate" }}
  42. tls.crt: {{ $objectData.data.certificate | trim | b64enc }}
  43. tls.key: {{ $objectData.data.privatekey | trim | b64enc }}
  44. {{- else if eq $objectData.type "imagePullSecret" }}
  45. .dockerconfigjson: {{ $objectData.data | trim | b64enc }}
  46. {{- end -}}
  47. {{- else }}
  48. stringData:
  49. {{- tpl (toYaml $objectData.data) $rootCtx | nindent 2 }}
  50. {{/* This comment is here to add a new line */}}
  51. {{- end -}}
  52. {{- end -}}