secrets.yaml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. {{- /*
  2. Copyright VMware, Inc.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{- if (include "kafka.createSaslSecret" .) }}
  6. {{- $secretName := printf "%s-user-passwords" (include "common.names.fullname" .) }}
  7. apiVersion: v1
  8. kind: Secret
  9. metadata:
  10. name: {{ $secretName }}
  11. namespace: {{ include "common.names.namespace" . | quote }}
  12. labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  13. {{- if .Values.commonAnnotations }}
  14. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  15. {{- end }}
  16. type: Opaque
  17. data:
  18. {{- if (include "kafka.client.saslEnabled" .) }}
  19. {{- $secretValue := "" }}
  20. {{- $secretData := (lookup "v1" "Secret" (include "common.names.namespace" .) $secretName).data }}
  21. {{- if and $secretData (hasKey $secretData "client-passwords")}}
  22. {{- $secretValue = index $secretData "client-passwords" }}
  23. {{- end }}
  24. {{- if or (empty $secretValue) (not (eq (len .Values.sasl.client.users) (len (splitList "," (b64dec $secretValue))))) }}
  25. {{- $clientPasswords := .Values.sasl.client.passwords }}
  26. {{- if empty $clientPasswords }}
  27. {{- $clientPasswords = list }}
  28. {{- range .Values.sasl.client.users }}
  29. {{- $clientPasswords = append $clientPasswords (randAlphaNum 10) }}
  30. {{- end }}
  31. {{- end }}
  32. {{- $secretValue = join "," $clientPasswords | toString | b64enc }}
  33. {{- end }}
  34. {{- if (include "kafka.saslUserPasswordsEnabled" .) }}
  35. client-passwords: {{ $secretValue | quote }}
  36. system-user-password: {{ index (splitList "," (b64dec $secretValue)) 0 | b64enc | quote }}
  37. {{- end }}
  38. {{- end }}
  39. {{- if or .Values.sasl.zookeeper.user .Values.zookeeper.auth.client.enabled }}
  40. zookeeper-password: {{ include "common.secrets.passwords.manage" (dict "secret" $secretName "key" "zookeeper-password" "providedValues" (list "sasl.zookeeper.password" "zookeeper.auth.client.clientPassword") "failOnNew" false "context" $) }}
  41. {{- end }}
  42. {{- if regexFind "SASL" (upper .Values.listeners.interbroker.protocol) }}
  43. {{- if (include "kafka.saslUserPasswordsEnabled" .) }}
  44. inter-broker-password: {{ include "common.secrets.passwords.manage" (dict "secret" $secretName "key" "inter-broker-password" "providedValues" (list "sasl.interbroker.password") "failOnNew" false "context" $) }}
  45. {{- end }}
  46. {{- if (include "kafka.saslClientSecretsEnabled" .) }}
  47. inter-broker-client-secret: {{ include "common.secrets.passwords.manage" (dict "secret" $secretName "key" "inter-broker-client-secret" "providedValues" (list "sasl.interbroker.clientSecret") "failOnNew" false "context" $) }}
  48. {{- end }}
  49. {{- end }}
  50. {{- if regexFind "SASL" (upper .Values.listeners.controller.protocol) }}
  51. {{- if (include "kafka.saslUserPasswordsEnabled" .) }}
  52. controller-password: {{ include "common.secrets.passwords.manage" (dict "secret" $secretName "key" "controller-password" "providedValues" (list "sasl.controller.password") "failOnNew" false "context" $) }}
  53. {{- end }}
  54. {{- if (include "kafka.saslClientSecretsEnabled" .) }}
  55. controller-client-secret: {{ include "common.secrets.passwords.manage" (dict "secret" $secretName "key" "controller-client-secret" "providedValues" (list "sasl.controller.clientSecret") "failOnNew" false "context" $) }}
  56. {{- end }}
  57. {{- end }}
  58. {{- if .Values.serviceBindings.enabled }}
  59. {{- if (include "kafka.client.saslEnabled" .) }}
  60. {{- $host := list }}
  61. {{- $port := .Values.service.ports.client }}
  62. {{- $bootstrapServers := list }}
  63. {{- if not .Values.controller.controllerOnly }}
  64. {{- range $i, $e := until (int .Values.controller.replicaCount) }}
  65. {{- $controller := printf "%s-controller-%s.%s-headless.%s.svc.%s" (include "common.names.fullname" $) (print $i) (include "common.names.fullname" $) $.Release.Namespace $.Values.clusterDomain }}
  66. {{- $host = append $host $controller }}
  67. {{- $bootstrapServers = append $bootstrapServers (printf "%s:%s" $controller $.Values.service.ports.client) }}
  68. {{- end }}
  69. {{- end }}
  70. {{- range $i, $e := until (int .Values.broker.replicaCount) }}
  71. {{- $broker := printf "%s-broker-%s.%s-headless.%s.svc.%s" (include "common.names.fullname" $) (print $i) (include "common.names.fullname" $) $.Release.Namespace $.Values.clusterDomain }}
  72. {{- $host = append $host $broker }}
  73. {{- $bootstrapServers = append $bootstrapServers (printf "%s:%s" $broker $.Values.service.ports.client) }}
  74. {{- end }}
  75. {{- range $i, $e := until (len .Values.sasl.client.users) }}
  76. ---
  77. apiVersion: v1
  78. kind: Secret
  79. metadata:
  80. name: {{ include "common.names.fullname" $ }}-svcbind-user-{{ $i }}
  81. namespace: {{ $.Release.Namespace | quote }}
  82. labels: {{- include "common.labels.standard" ( dict "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
  83. {{- if $.Values.commonAnnotations }}
  84. annotations: {{- include "common.tplvalues.render" ( dict "value" $.Values.commonAnnotations "context" $ ) | nindent 4 }}
  85. {{- end }}
  86. type: servicebinding.io/kafka
  87. data:
  88. provider: {{ print "bitnami" | b64enc | quote }}
  89. type: {{ print "kafka" | b64enc | quote }}
  90. username: {{ index .Values.sasl.client.users $i | b64enc | quote }}
  91. password: {{ index .Values.sasl.client.passwords $i | b64enc | quote }}
  92. host: {{ join "," $host | b64enc | quote }}
  93. port: {{ print $port | b64enc | quote }}
  94. bootstrap-servers: {{ join "," $bootstrapServers | b64enc | quote }}
  95. {{- end }}
  96. {{- else }}
  97. ---
  98. apiVersion: v1
  99. kind: Secret
  100. metadata:
  101. name: {{ include "common.names.fullname" . }}-svcbind
  102. namespace: {{ .Release.Namespace | quote }}
  103. labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  104. {{- if .Values.commonAnnotations }}
  105. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  106. {{- end }}
  107. type: servicebinding.io/kafka
  108. data:
  109. provider: {{ print "bitnami" | b64enc | quote }}
  110. type: {{ print "kafka" | b64enc | quote }}
  111. host: {{ join "," $host | b64enc | quote }}
  112. port: {{ print $port | b64enc | quote }}
  113. bootstrap-servers: {{ join "," $bootstrapServers | b64enc | quote }}
  114. {{- end }}
  115. {{- end }}
  116. {{- end }}
  117. {{- if and .Values.kraft.enabled (not .Values.kraft.existingClusterIdSecret) }}
  118. ---
  119. apiVersion: v1
  120. kind: Secret
  121. metadata:
  122. name: {{ printf "%s-kraft-cluster-id" (include "common.names.fullname" .) }}
  123. namespace: {{ include "common.names.namespace" . | quote }}
  124. labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  125. {{- if .Values.commonAnnotations }}
  126. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  127. {{- end }}
  128. type: Opaque
  129. data:
  130. kraft-cluster-id: {{ include "common.secrets.passwords.manage" (dict "secret" (printf "%s-kraft-cluster-id" (include "common.names.fullname" .)) "key" "kraft-cluster-id" "providedValues" (list "kraft.clusterId") "length" 22 "context" $) }}
  131. {{- end }}