scripts-configmap.yaml 5.2 KB

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