scripts-configmap.yaml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: {{ printf "%s-scripts" (include "common.names.fullname" .) }}
  5. namespace: {{ template "zookeeper.namespace" . }}
  6. labels: {{- include "common.labels.standard" . | nindent 4 }}
  7. app.kubernetes.io/component: zookeeper
  8. {{- if .Values.commonLabels }}
  9. {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
  10. {{- end }}
  11. {{- if .Values.commonAnnotations }}
  12. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  13. {{- end }}
  14. data:
  15. init-certs.sh: |-
  16. #!/bin/bash
  17. {{- if .Values.tls.client.enabled }}
  18. if [[ -f "/certs/client/tls.key" ]] && [[ -f "/certs/client/tls.crt" ]] && [[ -f "/certs/client/ca.crt" ]]; then
  19. if [[ -f "/opt/bitnami/zookeeper/config/certs/client/.initialized" ]]; then
  20. exit 0
  21. fi
  22. openssl pkcs12 -export -in "/certs/client/tls.crt" \
  23. -passout pass:"${ZOO_TLS_CLIENT_KEYSTORE_PASSWORD}" \
  24. -inkey "/certs/client/tls.key" \
  25. -out "/tmp/keystore.p12"
  26. keytool -importkeystore -srckeystore "/tmp/keystore.p12" \
  27. -srcstoretype PKCS12 \
  28. -srcstorepass "${ZOO_TLS_CLIENT_KEYSTORE_PASSWORD}" \
  29. -deststorepass "${ZOO_TLS_CLIENT_KEYSTORE_PASSWORD}" \
  30. -destkeystore "/opt/bitnami/zookeeper/config/certs/client/zookeeper.keystore.jks"
  31. rm "/tmp/keystore.p12"
  32. keytool -import -file "/certs/client/ca.crt" \
  33. -keystore "/opt/bitnami/zookeeper/config/certs/client/zookeeper.truststore.jks" \
  34. -storepass "${ZOO_TLS_CLIENT_TRUSTSTORE_PASSWORD}" \
  35. -noprompt
  36. touch /opt/bitnami/zookeeper/config/certs/client/.initialized
  37. {{- if .Values.tls.client.autoGenerated }}
  38. else
  39. echo "Couldn't find the expected PEM certificates! They are mandatory when Client encryption via TLS is enabled."
  40. exit 1
  41. fi
  42. {{- else }}
  43. elif [[ -f {{ printf "/certs/client/%s" (include "zookeeper.client.tlsTruststoreKey" .) | quote }} ]] && [[ -f {{ printf "/certs/client/%s" (include "zookeeper.client.tlsKeystoreKey" .) | quote }} ]]; then
  44. cp {{ printf "/certs/client/%s" (include "zookeeper.client.tlsTruststoreKey" .) | quote }} "/opt/bitnami/zookeeper/config/certs/client/zookeeper.truststore.jks"
  45. cp {{ printf "/certs/client/%s" (include "zookeeper.client.tlsKeystoreKey" .) | quote }} "/opt/bitnami/zookeeper/config/certs/client/zookeeper.keystore.jks"
  46. else
  47. echo "Couldn't find the expected Java Key Stores (JKS) files! They are mandatory when Client encryption via TLS is enabled."
  48. exit 1
  49. fi
  50. {{- end }}
  51. {{- end }}
  52. {{- if .Values.tls.quorum.enabled }}
  53. if [[ -f "/certs/quorum/tls.key" ]] && [[ -f "/certs/quorum/tls.crt" ]] && [[ -f "/certs/quorum/ca.crt" ]]; then
  54. openssl pkcs12 -export -in "/certs/quorum/tls.crt" \
  55. -passout pass:"${ZOO_TLS_QUORUM_KEYSTORE_PASSWORD}" \
  56. -inkey "/certs/quorum/tls.key" \
  57. -out "/tmp/keystore.p12"
  58. keytool -importkeystore -srckeystore "/tmp/keystore.p12" \
  59. -srcstoretype PKCS12 \
  60. -srcstorepass "${ZOO_TLS_QUORUM_KEYSTORE_PASSWORD}" \
  61. -deststorepass "${ZOO_TLS_QUORUM_KEYSTORE_PASSWORD}" \
  62. -destkeystore "/opt/bitnami/zookeeper/config/certs/quorum/zookeeper.keystore.jks"
  63. rm "/tmp/keystore.p12"
  64. keytool -import -file "/certs/quorum/ca.crt" \
  65. -keystore "/opt/bitnami/zookeeper/config/certs/quorum/zookeeper.truststore.jks" \
  66. -storepass "${ZOO_TLS_QUORUM_TRUSTSTORE_PASSWORD}" \
  67. -noprompt
  68. {{- if .Values.tls.quorum.autoGenerated }}
  69. else
  70. echo "Couldn't find the expected PEM certificates! They are mandatory when encryption Quorum via TLS is enabled."
  71. exit 1
  72. fi
  73. {{- else }}
  74. elif [[ -f {{ printf "/certs/quorum/%s" (include "zookeeper.quorum.tlsTruststoreKey" .) | quote }} ]] && [[ -f {{ printf "/certs/quorum/%s" (include "zookeeper.quorum.tlsKeystoreKey" .) | quote }} ]]; then
  75. cp {{ printf "/certs/quorum/%s" (include "zookeeper.quorum.tlsTruststoreKey" .) | quote }} "/opt/bitnami/zookeeper/config/certs/quorum/zookeeper.truststore.jks"
  76. cp {{ printf "/certs/quorum/%s" (include "zookeeper.quorum.tlsKeystoreKey" .) | quote }} "/opt/bitnami/zookeeper/config/certs/quorum/zookeeper.keystore.jks"
  77. else
  78. echo "Couldn't find the expected Java Key Stores (JKS) files! They are mandatory when Quorum encryption via TLS is enabled."
  79. exit 1
  80. fi
  81. {{- end }}
  82. {{- end }}
  83. setup.sh: |-
  84. #!/bin/bash
  85. # Execute entrypoint as usual after obtaining ZOO_SERVER_ID
  86. # check ZOO_SERVER_ID in persistent volume via myid
  87. # if not present, set based on POD hostname
  88. if [[ -f "/bitnami/zookeeper/data/myid" ]]; then
  89. export ZOO_SERVER_ID="$(cat /bitnami/zookeeper/data/myid)"
  90. else
  91. HOSTNAME="$(hostname -s)"
  92. if [[ $HOSTNAME =~ (.*)-([0-9]+)$ ]]; then
  93. ORD=${BASH_REMATCH[2]}
  94. export ZOO_SERVER_ID="$((ORD + {{ .Values.minServerId }} ))"
  95. else
  96. echo "Failed to get index from hostname $HOST"
  97. exit 1
  98. fi
  99. fi
  100. exec /entrypoint.sh /run.sh