secrets.yaml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. {{- /*
  2. Copyright VMware, Inc.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{- $host := include "postgresql.v1.primary.fullname" . }}
  6. {{- $port := include "postgresql.v1.service.port" . }}
  7. {{- $customUser := include "postgresql.v1.username" . }}
  8. {{- $postgresPassword := include "common.secrets.lookup" (dict "secret" (include "postgresql.v1.secretName" .) "key" (coalesce .Values.global.postgresql.auth.secretKeys.adminPasswordKey .Values.auth.secretKeys.adminPasswordKey) "defaultValue" (ternary (coalesce .Values.global.postgresql.auth.password .Values.auth.password .Values.global.postgresql.auth.postgresPassword .Values.auth.postgresPassword) (coalesce .Values.global.postgresql.auth.postgresPassword .Values.auth.postgresPassword) (or (empty $customUser) (eq $customUser "postgres"))) "context" $) | trimAll "\"" | b64dec }}
  9. {{- if and (not $postgresPassword) .Values.auth.enablePostgresUser }}
  10. {{- $postgresPassword = randAlphaNum 10 }}
  11. {{- end }}
  12. {{- $replicationPassword := "" }}
  13. {{- if eq .Values.architecture "replication" }}
  14. {{- $replicationPassword = include "common.secrets.passwords.manage" (dict "secret" (include "postgresql.v1.secretName" .) "key" (coalesce .Values.global.postgresql.auth.secretKeys.replicationPasswordKey .Values.auth.secretKeys.replicationPasswordKey) "providedValues" (list "auth.replicationPassword") "context" $) | trimAll "\"" | b64dec }}
  15. {{- end }}
  16. {{- $ldapPassword := "" }}
  17. {{- if and .Values.ldap.enabled (or .Values.ldap.bind_password .Values.ldap.bindpw) }}
  18. {{- $ldapPassword = coalesce .Values.ldap.bind_password .Values.ldap.bindpw }}
  19. {{- end }}
  20. {{- $password := "" }}
  21. {{- if and (not (empty $customUser)) (ne $customUser "postgres") }}
  22. {{- $password = include "common.secrets.passwords.manage" (dict "secret" (include "postgresql.v1.secretName" .) "key" (coalesce .Values.global.postgresql.auth.secretKeys.userPasswordKey .Values.auth.secretKeys.userPasswordKey) "providedValues" (list "global.postgresql.auth.password" "auth.password") "context" $) | trimAll "\"" | b64dec }}
  23. {{- end }}
  24. {{- $database := include "postgresql.v1.database" . }}
  25. {{- if (include "postgresql.v1.createSecret" .) }}
  26. apiVersion: v1
  27. kind: Secret
  28. metadata:
  29. name: {{ include "common.names.fullname" . }}
  30. namespace: {{ .Release.Namespace | quote }}
  31. labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  32. {{- if .Values.commonAnnotations }}
  33. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  34. {{- end }}
  35. type: Opaque
  36. data:
  37. {{- if $postgresPassword }}
  38. postgres-password: {{ $postgresPassword | b64enc | quote }}
  39. {{- end }}
  40. {{- if $password }}
  41. password: {{ $password | b64enc | quote }}
  42. {{- end }}
  43. {{- if $replicationPassword }}
  44. replication-password: {{ $replicationPassword | b64enc | quote }}
  45. {{- end }}
  46. # We don't auto-generate LDAP password when it's not provided as we do for other passwords
  47. {{- if and .Values.ldap.enabled (or .Values.ldap.bind_password .Values.ldap.bindpw) }}
  48. ldap-password: {{ $ldapPassword | b64enc | quote }}
  49. {{- end }}
  50. {{- end }}
  51. {{- if .Values.serviceBindings.enabled }}
  52. {{- if $postgresPassword }}
  53. ---
  54. apiVersion: v1
  55. kind: Secret
  56. metadata:
  57. name: {{ include "common.names.fullname" . }}-svcbind-postgres
  58. namespace: {{ .Release.Namespace | quote }}
  59. labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  60. {{- if .Values.commonAnnotations }}
  61. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  62. {{- end }}
  63. type: servicebinding.io/postgresql
  64. data:
  65. provider: {{ print "bitnami" | b64enc | quote }}
  66. type: {{ print "postgresql" | b64enc | quote }}
  67. host: {{ $host | b64enc | quote }}
  68. port: {{ $port | b64enc | quote }}
  69. username: {{ print "postgres" | b64enc | quote }}
  70. database: {{ print "postgres" | b64enc | quote }}
  71. password: {{ $postgresPassword | b64enc | quote }}
  72. uri: {{ printf "postgresql://postgres:%s@%s:%s/postgres" $postgresPassword $host $port | b64enc | quote }}
  73. {{- end }}
  74. {{- if $password }}
  75. ---
  76. apiVersion: v1
  77. kind: Secret
  78. metadata:
  79. name: {{ include "common.names.fullname" . }}-svcbind-custom-user
  80. namespace: {{ .Release.Namespace | quote }}
  81. labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  82. {{- if .Values.commonAnnotations }}
  83. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  84. {{- end }}
  85. type: servicebinding.io/postgresql
  86. data:
  87. provider: {{ print "bitnami" | b64enc | quote }}
  88. type: {{ print "postgresql" | b64enc | quote }}
  89. host: {{ $host | b64enc | quote }}
  90. port: {{ $port | b64enc | quote }}
  91. username: {{ $customUser | b64enc | quote }}
  92. password: {{ $password | b64enc | quote }}
  93. {{- if $database }}
  94. database: {{ $database | b64enc | quote }}
  95. {{- end }}
  96. uri: {{ printf "postgresql://%s:%s@%s:%s/%s" $customUser $password $host $port $database | b64enc | quote }}
  97. {{- end }}
  98. {{- end }}