From 461be5370546a5fcfd62fd9967d46117772d90a9 Mon Sep 17 00:00:00 2001 From: "Javier J. Salmeron Garcia" Date: Wed, 19 Dec 2018 01:30:51 +0100 Subject: [PATCH 1/2] [bitnami/cassandra] Allow custom cql and sh scripts Signed-off-by: Javier J. Salmeron Garcia --- bitnami/cassandra/Chart.yaml | 2 +- bitnami/cassandra/README.md | 2 +- .../docker-entrypoint-initdb.d/README.md | 3 +++ bitnami/cassandra/templates/_helpers.tpl | 11 +++++++++++ .../cassandra/templates/initdb-configmap.yaml | 13 +++++++++++++ bitnami/cassandra/templates/statefulset.yaml | 19 +++++++++++++------ bitnami/cassandra/values-production.yaml | 4 ++-- bitnami/cassandra/values.yaml | 4 ++-- 8 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 bitnami/cassandra/files/docker-entrypoint-initdb.d/README.md create mode 100644 bitnami/cassandra/templates/initdb-configmap.yaml diff --git a/bitnami/cassandra/Chart.yaml b/bitnami/cassandra/Chart.yaml index 49ab4142f..9515e2c8e 100644 --- a/bitnami/cassandra/Chart.yaml +++ b/bitnami/cassandra/Chart.yaml @@ -1,5 +1,5 @@ name: cassandra -version: 1.1.0 +version: 2.0.0 appVersion: 3.11.3 description: Apache Cassandra is a free and open-source distributed database management system designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. Cassandra offers robust support for clusters spanning multiple datacenters, with asynchronous masterless replication allowing low latency operations for all clients. icon: https://bitnami.com/assets/stacks/cassandra/img/cassandra-stack-220x234.png diff --git a/bitnami/cassandra/README.md b/bitnami/cassandra/README.md index 99d70c09e..a51e84338 100644 --- a/bitnami/cassandra/README.md +++ b/bitnami/cassandra/README.md @@ -81,7 +81,7 @@ The following tables lists the configurable parameters of the cassandra chart an | `dbUser.forcePassword` | Force the user to provide a non-empty password for `dbUser.user` | `false` | | `dbUser.password` | Password for `dbUser.user`. Randomly generated if empty | (Random generated) | | `dbUser.existingSecret` | Use an existing secret object for `dbUser.user` password (will ignore `dbUser.password`) | `nil` | -| `startupCQL` | Startup CQL commands (done in the first node). Useful for creating keyspaces at startup, for instance | `nil` | +| `initDBConfigMap` | Configmap for initialization CQL commands (done in the first node). Useful for creating keyspaces at startup, for instance | `nil` | | `livenessProbe.enabled` | Turn on and off liveness probe | `true` | | `livenessProbe.initialDelaySeconds` | Delay before liveness probe is initiated | `30` | | `livenessProbe.periodSeconds` | How often to perform the probe | `30` | diff --git a/bitnami/cassandra/files/docker-entrypoint-initdb.d/README.md b/bitnami/cassandra/files/docker-entrypoint-initdb.d/README.md new file mode 100644 index 000000000..fb663dc28 --- /dev/null +++ b/bitnami/cassandra/files/docker-entrypoint-initdb.d/README.md @@ -0,0 +1,3 @@ +You can copy here your custom `.sh` or `.cql` file so they are executed during the first boot of the image. + +More info in the [bitnami-docker-cassandra](https://github.com/bitnami/bitnami-docker-cassandra#initializing-a-new-instance) repository. diff --git a/bitnami/cassandra/templates/_helpers.tpl b/bitnami/cassandra/templates/_helpers.tpl index c4bfbbce4..cef6df7e5 100644 --- a/bitnami/cassandra/templates/_helpers.tpl +++ b/bitnami/cassandra/templates/_helpers.tpl @@ -75,3 +75,14 @@ Return the proper metrics image name {{- $tag := .Values.metrics.image.tag | toString -}} {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} {{- end -}} + + {{/* + Get the init db configmap. + */}} + {{- define "cassandra.initDbCM" -}} + {{- if .Values.initDBConfigMap -}} + {{- printf "%s" .Values.initDBConfigMap -}} + {{- else -}} + {{- printf "%s-init-scripts" (include "cassandra.fullname" .) -}} + {{- end -}} + {{- end -}} diff --git a/bitnami/cassandra/templates/initdb-configmap.yaml b/bitnami/cassandra/templates/initdb-configmap.yaml new file mode 100644 index 000000000..26ab086b6 --- /dev/null +++ b/bitnami/cassandra/templates/initdb-configmap.yaml @@ -0,0 +1,13 @@ +{{- if and (.Files.Glob "files/docker-entrypoint-initdb.d/*") (not .Values.initDBConfigMap) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "cassandra.fullname" . }}-init-scripts + labels: + app: {{ template "cassandra.name" . }} + chart: {{ template "cassandra.chart" . }} + release: {{ .Release.Name | quote }} + heritage: {{ .Release.Service | quote }} +data: +{{ (.Files.Glob "files/docker-entrypoint-initdb.d/*").AsConfig | indent 2 }} +{{- end }} diff --git a/bitnami/cassandra/templates/statefulset.yaml b/bitnami/cassandra/templates/statefulset.yaml index 83b77469c..c73c3a0d4 100644 --- a/bitnami/cassandra/templates/statefulset.yaml +++ b/bitnami/cassandra/templates/statefulset.yaml @@ -64,9 +64,11 @@ spec: if [[ $HOSTNAME =~ (.*)-0$ ]]; then echo "Setting node as password seeder" export CASSANDRA_PASSWORD_SEEDER=yes + else + # Only node 0 will execute the startup initdb scripts + export CASSANDRA_IGNORE_INITDB_SCRIPTS=1 fi /app-entrypoint.sh /run.sh - image: {{ template "cassandra.image" . }} imagePullPolicy: {{ .Values.image.pullPolicy | quote }} resources: @@ -107,10 +109,6 @@ spec: - name: JVM_EXTRA_OPTS value: {{ .Values.jvm.extraOpts | quote }} {{- end }} - {{- if .Values.startupCQL }} - - name: CASSANDRA_STARTUP_CQL - value: {{ .Values.startupCQL | quote }} - {{- end }} - name: CASSANDRA_ENABLE_RPC value: {{ .Values.cluster.enableRPC | quote }} {{- if .Values.livenessProbe.enabled }} @@ -155,6 +153,10 @@ spec: volumeMounts: - name: data mountPath: /bitnami/cassandra +{{- if or (.Files.Glob "files/docker-entrypoint-initdb.d/*") (.Values.initDBConfigMap) }} + - name: init-db + mountPath: /docker-entrypoint-initdb.d +{{- end }} {{- if .Values.image.pullSecrets }} imagePullSecrets: - name: {{ .Values.image.pullSecrets }} @@ -183,11 +185,16 @@ spec: initialDelaySeconds: 20 timeoutSeconds: 45 {{- end }} -{{- if not .Values.persistence.enabled }} volumes: +{{- if not .Values.persistence.enabled }} - name: data emptyDir: {} {{- else }} +{{- if or (.Files.Glob "files/docker-entrypoint-initdb.d/*") (.Values.initDBConfigMap) }} + - name: init-db + configMap: + name: {{ template "cassandra.initDbCM" . }} +{{- end }} volumeClaimTemplates: - metadata: name: data diff --git a/bitnami/cassandra/values-production.yaml b/bitnami/cassandra/values-production.yaml index 0be7378ad..baa7cd5a8 100644 --- a/bitnami/cassandra/values-production.yaml +++ b/bitnami/cassandra/values-production.yaml @@ -118,10 +118,10 @@ dbUser: # password: # existingSecret: -## Startup CQL commands. Useful for creating a keyspace +## ConfigMap with cql scripts. Useful for creating a keyspace ## and pre-populating data ## -# startupCQL: "CREATE KEYSPACE IF NOT EXISTS example_keyspace WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};" +# initDBConfigMap: ## Liveness and Readiness probe values. ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/ diff --git a/bitnami/cassandra/values.yaml b/bitnami/cassandra/values.yaml index 001d0743a..6e781bcaa 100644 --- a/bitnami/cassandra/values.yaml +++ b/bitnami/cassandra/values.yaml @@ -118,10 +118,10 @@ dbUser: # password: # existingSecret: -## Startup CQL commands. Useful for creating a keyspace +## ConfigMap with cql scripts. Useful for creating a keyspace ## and pre-populating data ## -# startupCQL: "CREATE KEYSPACE IF NOT EXISTS example_keyspace WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};" +# initDBConfigMap: ## Liveness and Readiness probe values. ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/ From a4f3e0296c20be14e4111682080c498d5cde7d2a Mon Sep 17 00:00:00 2001 From: "Javier J. Salmeron Garcia" Date: Wed, 19 Dec 2018 16:39:07 +0100 Subject: [PATCH 2/2] Add notable changes --- bitnami/cassandra/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bitnami/cassandra/README.md b/bitnami/cassandra/README.md index a51e84338..9a09d5498 100644 --- a/bitnami/cassandra/README.md +++ b/bitnami/cassandra/README.md @@ -138,3 +138,22 @@ The [Bitnami cassandra](https://github.com/bitnami/bitnami-docker-cassandra) ima Persistent Volume Claims are used to keep the data across deployments. This is known to work in GCE, AWS, and minikube. See the [Configuration](#configuration) section to configure the PVC or to disable persistence. + +## Initializing the database + +The [Bitnami cassandra](https://github.com/bitnami/bitnami-docker-cassandra) image allows having initialization scripts mounted in `/docker-entrypoint.initdb`. This is done in the chart by adding files in the `files/docker-entrypoint-initdb.d` folder (in order to do so, clone this chart) or by setting the `initDBConfigMap` value with a `ConfigMap` that includes the necessary `sh` or `cql` scripts: + +```bash +kubectl create configmap init-db --from-file=path/to/scripts +helm install bitnami/cassandra --set initDBConfigMap=init-db +``` + +## Upgrade + +### 2.0.0 + +This releases make it possible to specify custom initialization scripts in both cql and sh files. + +#### Breaking changes + +- `startupCQL` has been removed. Instead, for initializing the database, see [this section](#initializing-the-database).