diff --git a/bitnami/cassandra/Chart.yaml b/bitnami/cassandra/Chart.yaml index a30c879cf..9515e2c8e 100644 --- a/bitnami/cassandra/Chart.yaml +++ b/bitnami/cassandra/Chart.yaml @@ -1,5 +1,5 @@ name: cassandra -version: 1.2.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 1a2df5bb8..bb3839687 100644 --- a/bitnami/cassandra/README.md +++ b/bitnami/cassandra/README.md @@ -82,7 +82,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` | @@ -139,3 +139,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). 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 48f198cd0..dcf4fbae5 100644 --- a/bitnami/cassandra/templates/_helpers.tpl +++ b/bitnami/cassandra/templates/_helpers.tpl @@ -76,6 +76,17 @@ Return the proper metrics image name {{- 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 -}} + {{/* Get the configuration configmap. */}} 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 e286bfd51..0ac9f3fc8 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 or (.Files.Glob "files/conf/*") .Values.existingConfiguration }} - name: configurations mountPath: /bitnami/cassandra/conf @@ -197,6 +199,11 @@ spec: - 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 5c5316eac..5f510f551 100644 --- a/bitnami/cassandra/values-production.yaml +++ b/bitnami/cassandra/values-production.yaml @@ -121,10 +121,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 f0b46c5b1..be5218f63 100644 --- a/bitnami/cassandra/values.yaml +++ b/bitnami/cassandra/values.yaml @@ -121,10 +121,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/