diff --git a/charts/cassandra-migrations/templates/_helpers.tpl b/charts/cassandra-migrations/templates/_helpers.tpl new file mode 100644 index 0000000000..71a57640c4 --- /dev/null +++ b/charts/cassandra-migrations/templates/_helpers.tpl @@ -0,0 +1,108 @@ +{{- define "cassandraGalleyHost" -}} +{{ $cassandraGalley := default dict .Values.cassandraGalley }} +{{- default (.Values.cassandra.host) $cassandraGalley.host }} +{{- end -}} + +{{- define "cassandraBrigHost" -}} +{{ $cassandraBrig := default dict .Values.cassandraBrig }} +{{- default (.Values.cassandra.host) $cassandraBrig.host }} +{{- end -}} + +{{- define "cassandraGundeckHost" -}} +{{ $cassandraGundeck := default dict .Values.cassandraGundeck }} +{{- default (.Values.cassandra.host) $cassandraGundeck.host }} +{{- end -}} + +{{- define "cassandraSparHost" -}} +{{ $cassandraSpar := default dict .Values.cassandraSpar }} +{{- default (.Values.cassandra.host) $cassandraSpar.host }} +{{- end -}} + +{{/* +Note: in the past, 'replicaCount' was used, this fallback is only used +for backwards-compatibility with already-installed charts to not break existing installations. + +Thus the order of priority is: + +1. cassandraGalley.replicationMap +2. cassandra.replicationMap +3. cassandraGalley.replicationFactor +4. cassandra.replicationFactor +5. cassandra.replicaCount + +*/}} + +{{- define "cassandraGalleyReplicationArg" -}} +{{ $cassandraGalley := default dict .Values.cassandraGalley }} +{{- if (or .Values.cassandra.replicationMap $cassandraGalley.replicationMap) -}} +{{- default (.Values.cassandra.replicationMap) $cassandraGalley.replicationMap -}} +{{- else -}} +{{- default (default (.Values.cassandra.replicaCount) .Values.cassandra.replicationFactor) $cassandraGalley.replicationFactor -}} +{{- end -}} +{{- end -}} + +{{- define "cassandraGalleyReplicationType" -}} +{{ $cassandraGalley := default dict .Values.cassandraGalley }} +{{- if (or .Values.cassandra.replicationMap $cassandraGalley.replicationMap) -}} +{{- printf "--replication-map" -}} +{{- else -}} +{{- printf "--replication-factor" -}} +{{- end -}} +{{- end -}} + + +{{- define "cassandraGundeckReplicationArg" -}} +{{ $cassandraGundeck := default dict .Values.cassandraGundeck }} +{{- if (or .Values.cassandra.replicationMap $cassandraGundeck.replicationMap) -}} +{{- default (.Values.cassandra.replicationMap) $cassandraGundeck.replicationMap -}} +{{- else -}} +{{- default (default (.Values.cassandra.replicaCount) .Values.cassandra.replicationFactor) $cassandraGundeck.replicationFactor -}} +{{- end -}} +{{- end -}} + +{{- define "cassandraGundeckReplicationType" -}} +{{ $cassandraGundeck := default dict .Values.cassandraGundeck }} +{{- if (or .Values.cassandra.replicationMap $cassandraGundeck.replicationMap) -}} +{{- printf "--replication-map" -}} +{{- else -}} +{{- printf "--replication-factor" -}} +{{- end -}} +{{- end -}} + + +{{- define "cassandraBrigReplicationArg" -}} +{{ $cassandraBrig := default dict .Values.cassandraBrig }} +{{- if (or .Values.cassandra.replicationMap $cassandraBrig.replicationMap) -}} +{{- default (.Values.cassandra.replicationMap) $cassandraBrig.replicationMap -}} +{{- else -}} +{{- default (default (.Values.cassandra.replicaCount) .Values.cassandra.replicationFactor) $cassandraBrig.replicationFactor -}} +{{- end -}} +{{- end -}} + +{{- define "cassandraBrigReplicationType" -}} +{{ $cassandraBrig := default dict .Values.cassandraBrig }} +{{- if (or .Values.cassandra.replicationMap $cassandraBrig.replicationMap) -}} +{{- printf "--replication-map" -}} +{{- else -}} +{{- printf "--replication-factor" -}} +{{- end -}} +{{- end -}} + + +{{- define "cassandraSparReplicationArg" -}} +{{ $cassandraSpar := default dict .Values.cassandraSpar }} +{{- if (or .Values.cassandra.replicationMap $cassandraSpar.replicationMap) -}} +{{- default (.Values.cassandra.replicationMap) $cassandraSpar.replicationMap -}} +{{- else -}} +{{- default (default (.Values.cassandra.replicaCount) .Values.cassandra.replicationFactor) $cassandraSpar.replicationFactor -}} +{{- end -}} +{{- end -}} + +{{- define "cassandraSparReplicationType" -}} +{{ $cassandraSpar := default dict .Values.cassandraSpar }} +{{- if (or .Values.cassandra.replicationMap $cassandraSpar.replicationMap) -}} +{{- printf "--replication-map" -}} +{{- else -}} +{{- printf "--replication-factor" -}} +{{- end -}} +{{- end -}} diff --git a/charts/cassandra-migrations/templates/galley-migrate-data.yaml b/charts/cassandra-migrations/templates/galley-migrate-data.yaml index 90e7f4a58b..3800615d2b 100644 --- a/charts/cassandra-migrations/templates/galley-migrate-data.yaml +++ b/charts/cassandra-migrations/templates/galley-migrate-data.yaml @@ -1,6 +1,7 @@ # This jobs runs migrations on the galley DB using the galley-migrate-data tool. # The source for the tool can be found at services/galley in the wire-server # repository. +{{- if .Values.enableGalleyMigrations }} apiVersion: batch/v1 kind: Job metadata: @@ -32,8 +33,9 @@ spec: imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }} args: - --cassandra-host - - "{{ .Values.cassandra.host }}" + - "{{ template "cassandraGalleyHost" . }}" - --cassandra-port - "9042" - --cassandra-keyspace - galley +{{- end }} diff --git a/charts/cassandra-migrations/templates/migrate-schema.yaml b/charts/cassandra-migrations/templates/migrate-schema.yaml index 1934d51066..b64815b655 100644 --- a/charts/cassandra-migrations/templates/migrate-schema.yaml +++ b/charts/cassandra-migrations/templates/migrate-schema.yaml @@ -23,61 +23,70 @@ spec: # to avoid 'Column family ID mismatch' / schema disagreements # see https://stackoverflow.com/questions/29030661/creating-new-table-with-cqlsh-on-existing-keyspace-column-family-id-mismatch#40325651 for details. initContainers: + {{- if .Values.enableGundeckMigrations }} - name: gundeck-schema image: "{{ .Values.images.gundeck }}:{{ .Values.images.tag }}" imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }} command: - gundeck-schema - --host - - "{{ .Values.cassandra.host }}" + - "{{ template "cassandraGundeckHost" . }}" - --port - "9042" - --keyspace - gundeck - - --replication-factor - - "{{ .Values.cassandra.replicaCount }}" + - {{ template "cassandraGundeckReplicationType" . }} + - "{{ template "cassandraGundeckReplicationArg" . }}" + {{- end }} + {{- if .Values.enableBrigMigrations }} - name: brig-schema image: "{{ .Values.images.brig }}:{{ .Values.images.tag }}" imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }} command: - brig-schema - --host - - "{{ .Values.cassandra.host }}" + - "{{ template "cassandraBrigHost" . }}" - --port - "9042" - --keyspace - brig - - --replication-factor - - "{{ .Values.cassandra.replicaCount }}" + - {{ template "cassandraBrigReplicationType" . }} + - "{{ template "cassandraBrigReplicationArg" . }}" + {{- end }} + {{- if .Values.enableGalleyMigrations }} - name: galley-schema image: "{{ .Values.images.galley }}:{{ .Values.images.tag }}" imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }} command: - galley-schema - --host - - "{{ .Values.cassandra.host }}" + - "{{ template "cassandraGalleyHost" . }}" - --port - "9042" - --keyspace - galley - - --replication-factor - - "{{ .Values.cassandra.replicaCount }}" + - {{ template "cassandraGalleyReplicationType" . }} + - "{{ template "cassandraGalleyReplicationArg" . }}" + {{- end }} + {{- if .Values.enableSparMigrations }} - name: spar-schema image: "{{ .Values.images.spar }}:{{ .Values.images.tag }}" imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }} command: - spar-schema - --host - - "{{ .Values.cassandra.host }}" + - "{{ template "cassandraSparHost" . }}" - --port - "9042" - --keyspace - spar - - --replication-factor - - "{{ .Values.cassandra.replicaCount }}" + - {{ template "cassandraSparReplicationType" . }} + - "{{ template "cassandraSparReplicationArg" . }}" + {{- end }} + containers: - name: job-done image: busybox:1.32.0 diff --git a/charts/cassandra-migrations/templates/spar-migrate-data.yaml b/charts/cassandra-migrations/templates/spar-migrate-data.yaml index 78c3ce3de7..26710c7369 100644 --- a/charts/cassandra-migrations/templates/spar-migrate-data.yaml +++ b/charts/cassandra-migrations/templates/spar-migrate-data.yaml @@ -1,6 +1,7 @@ # This jobs runs data migrations for the spar DB using the spar-migrate-data tool. # The source for the tool can be found at services/spar/migrate-data # +{{- if (and .Values.enableSparMigrations .Values.enableBrigMigrations) }} apiVersion: batch/v1 kind: Job metadata: @@ -32,14 +33,15 @@ spec: imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }} args: - --cassandra-host-spar - - "{{ .Values.cassandra.host }}" + - "{{ template "cassandraSparHost" . }}" - --cassandra-port-spar - "9042" - --cassandra-keyspace-spar - spar - --cassandra-host-brig - - "{{ .Values.cassandra.host }}" + - "{{ template "cassandraBrigHost" . }}" - --cassandra-port-brig - "9042" - --cassandra-keyspace-brig - brig +{{- end }} diff --git a/charts/cassandra-migrations/values.yaml b/charts/cassandra-migrations/values.yaml index 0347fac256..6aff2da268 100644 --- a/charts/cassandra-migrations/values.yaml +++ b/charts/cassandra-migrations/values.yaml @@ -6,3 +6,52 @@ images: spar: quay.io/wire/spar-schema galleyMigrateData: quay.io/wire/galley-migrate-data sparMigrateData: quay.io/wire/spar-migrate-data + +# Setting cassandra host name and replication is mandatory to specify. +# +# Example production case: +# +# cassandra: +# host: cassandra-external +# replicationFactor: 3 +# +# Example demo case (single cassandra machine, test deployment): +# +# cassandra: +# host: cassandra-ephemeral +# replicationFactor: 1 +# +# The following is optional and useful only in a multi-datacenter setup. +# if 'replicationMap' is set, it's used; otherwise replicationFactor is used. +# +# cassandra: +# replicationMap: DC1:3,DC2:5 +# +# The following is optional. If set, it overrides the otherwise-used +# cassandra.host and cassandra.replicationFactor / replicationMap for +# the specific haskell service in case you have separate +# cassandra clusters for each service. +# +# cassandraGalley: +# host: cassandra-ephemeral-galley +# replicationMap: eu-west-1:3 +# +# cassandraBrig: +# host: cassandra-ephemeral-galley +# replicationMap: eu-central-1:3 +# +# cassandraSpar: +# host: cassandra-ephemeral-galley +# replicationMap: us-east-1:3 +# +# cassandraGundeck: +# host: cassandra-ephemeral-galley +# replicationMap: eu-west-1:3 + + +# Overriding the following is only useful during datacenter migration time periods, +# where some other job already migrates schemas. +enableGalleyMigrations: true +enableBrigMigrations: true +enableGundeckMigrations: true +enableSparMigrations: true