diff --git a/.gitignore b/.gitignore index 496ee2ca6..4befed30a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.DS_Store \ No newline at end of file +.DS_Store +.idea diff --git a/README.md b/README.md index 2bbb7cd20..e3b70c291 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,26 @@ Big thanks from the maintainers of the [deprecated chart](https://github.com/hel For now the full list of values is not documented but you can get inspired by the values.yaml specific to each directory. +## Upgrading from 3.1.0 version of this Chart to 4.0.0 + +Following Helm Chart best practices the new version introduces some breaking changes, all configuration for external +resources moved to separate config branches: `externalClickhouse`, `externalKafka`, `externalRedis`, `externalPostgresql`. + +Here is a mapping table of old values and new values: + +| Before | After | +| ------------------------------- | ------------------------------------ | +| `postgresql.postgresqlHost` | `externalPostgresql.host` | +| `postgresql.postgresqlPort` | `externalPostgresql.port` | +| `postgresql.postgresqlUsername` | `externalPostgresql.username` | +| `postgresql.postgresqlPassword` | `externalPostgresql.password` | +| `postgresql.postgresqlDatabase` | `externalPostgresql.database` | +| `postgresql.postgresSslMode` | `externalPostgresql.sslMode` | +| `redis.host` | `externalRedis.host` | +| `redis.port` | `externalRedis.port` | +| `redis.password` | `externalRedis.password` | + + ## Upgrading from deprecated 9.0 -> 10.0 Chart As this chart runs in helm 3 and also tries its best to follow on from the original Sentry chart. There are some steps that needs to be taken in order to correctly upgrade. diff --git a/sentry/Chart.yaml b/sentry/Chart.yaml index 9d75cb196..4a7dcce00 100644 --- a/sentry/Chart.yaml +++ b/sentry/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: sentry description: A Helm chart for Kubernetes type: application -version: 3.1.0 +version: 4.0.0 appVersion: 10.0.0 dependencies: - name: redis diff --git a/sentry/templates/_helper.tpl b/sentry/templates/_helper.tpl index e3de50896..2c03e32d0 100644 --- a/sentry/templates/_helper.tpl +++ b/sentry/templates/_helper.tpl @@ -96,7 +96,7 @@ Set postgres host {{- if .Values.postgresql.enabled -}} {{- template "sentry.postgresql.fullname" . -}} {{- else -}} -{{- .Values.postgresql.postgresqlHost -}} +{{ required "A valid .Values.externalPostgresql.host is required" .Values.externalPostgresql.host }} {{- end -}} {{- end -}} @@ -116,9 +116,42 @@ Set postgres port */}} {{- define "sentry.postgresql.port" -}} {{- if .Values.postgresql.enabled -}} - "5432" +{{- default 5432 .Values.postgresql.service.port }} {{- else -}} -{{- default "5432" .Values.postgresql.postgresqlPort | quote -}} +{{- required "A valid .Values.externalPostgresql.port is required" .Values.externalPostgresql.port -}} +{{- end -}} +{{- end -}} + +{{/* +Set postgresql username +*/}} +{{- define "sentry.postgresql.username" -}} +{{- if .Values.postgresql.enabled -}} +{{- default "postgres" .Values.postgresql.postgresqlUsername }} +{{- else -}} +{{ required "A valid .Values.externalPostgresql.username is required" .Values.externalPostgresql.username }} +{{- end -}} +{{- end -}} + +{{/* +Set postgresql password +*/}} +{{- define "sentry.postgresql.password" -}} +{{- if .Values.postgresql.enabled -}} +{{- default "" .Values.postgresql.postgresqlPassword }} +{{- else -}} +{{ required "A valid .Values.externalPostgresql.password is required" .Values.externalPostgresql.password }} +{{- end -}} +{{- end -}} + +{{/* +Set postgresql database +*/}} +{{- define "sentry.postgresql.database" -}} +{{- if .Values.postgresql.enabled -}} +{{- default "sentry" .Values.postgresql.postgresqlDatabase }} +{{- else -}} +{{ required "A valid .Values.externalPostgresql.database is required" .Values.externalPostgresql.database }} {{- end -}} {{- end -}} @@ -127,13 +160,9 @@ Set redis host */}} {{- define "sentry.redis.host" -}} {{- if .Values.redis.enabled -}} - {{- if .Values.redis.hostOverride -}} - {{- .Values.redis.hostOverride -}} - {{- else -}} - {{- template "sentry.redis.fullname" . -}}-master - {{- end -}} +{{- template "sentry.redis.fullname" . -}}-master {{- else -}} - {{- .Values.redis.host -}} +{{ required "A valid .Values.externalRedis.host is required" .Values.externalRedis.host }} {{- end -}} {{- end -}} @@ -153,9 +182,20 @@ Set redis port */}} {{- define "sentry.redis.port" -}} {{- if .Values.redis.enabled -}} - 6379 +{{- default 6379 .Values.redis.redisPort }} +{{- else -}} +{{ required "A valid .Values.externalRedis.port is required" .Values.externalRedis.port }} +{{- end -}} +{{- end -}} + +{{/* +Set redis password +*/}} +{{- define "sentry.redis.password" -}} +{{- if .Values.redis.enabled -}} +{{ .Values.redis.password }} {{- else -}} -{{- default 6379 .Values.redis.port -}} +{{ .Values.externalRedis.password }} {{- end -}} {{- end -}} @@ -171,61 +211,57 @@ Create the name of the service account to use {{- end -}} {{/* -Set Clickhouse host +Set ClickHouse host */}} {{- define "sentry.clickhouse.host" -}} - {{- default "clickhouse" (include "sentry.clickhouse.fullname" .) -}} +{{- if .Values.clickhouse.enabled -}} +{{- template "sentry.clickhouse.fullname" . -}} +{{- else -}} +{{ required "A valid .Values.externalClickhouse.host is required" .Values.externalClickhouse.host }} {{- end -}} - -{{/* -Set Clickhouse port -*/}} -{{- define "sentry.clickhouse.port" -}} - {{- default 9000 .Values.clickhouse.clickhouse.tcp_port }} {{- end -}} {{/* -Set Kafka Confluent host +Set ClickHouse port */}} -{{- define "sentry.kafka.host" -}} -{{- if .Values.kafka.enabled -}} - {{- template "sentry.kafka.fullname" . -}} +{{- define "sentry.clickhouse.port" -}} +{{- if .Values.clickhouse.enabled -}} +{{- default 9000 .Values.clickhouse.clickhouse.tcp_port }} {{- else -}} - kafka-confluent +{{ required "A valid .Values.externalClickhouse.tcpPort is required" .Values.externalClickhouse.tcpPort }} {{- end -}} {{- end -}} {{/* -Set Kafka Confluent port +Set ClickHouse cluster name */}} -{{- define "sentry.kafka.port" -}} -{{- if and (.Values.kafka.enabled) (.Values.kafka.service.port) -}} - {{- .Values.kafka.service.port }} +{{- define "sentry.clickhouse.cluster.name" -}} +{{- if .Values.clickhouse.enabled -}} +{{ .Release.Name | printf "%s-clickhouse" }} {{- else -}} - 9092 +{{ required "A valid .Values.externalClickhouse.clusterName is required" .Values.externalClickhouse.clusterName }} {{- end -}} {{- end -}} - {{/* -Set Zookeeper host +Set Kafka Confluent host */}} -{{- define "sentry.kafka.zookeeper.host" -}} -{{- if .Values.kafka.zookeeper.enabled -}} - {{- template "sentry.kafka.zookeeper.fullname" . -}} +{{- define "sentry.kafka.host" -}} +{{- if .Values.kafka.enabled -}} +{{- template "sentry.kafka.fullname" . -}} {{- else -}} - "zookeeper" +{{ required "A valid .Values.externalKafka.host is required" .Values.externalKafka.host }} {{- end -}} {{- end -}} {{/* -Set Zookeeper port +Set Kafka Confluent port */}} -{{- define "sentry.kafka.zookeeper.port" -}} -{{- if .Values.kafka.zookeeper.enabled -}} - {{- default "2181" .Values.kafka.zookeeper.service.port }} +{{- define "sentry.kafka.port" -}} +{{- if and (.Values.kafka.enabled) (.Values.kafka.service.port) -}} +{{- .Values.kafka.service.port }} {{- else -}} - "2181" +{{ required "A valid .Values.externalKafka.port is required" .Values.externalKafka.port }} {{- end -}} {{- end -}} @@ -234,9 +270,8 @@ Set RabbitMQ host */}} {{- define "sentry.rabbitmq.host" -}} {{- if .Values.rabbitmq.enabled -}} - {{- default "sentry-rabbitmq-ha" (include "sentry.rabbitmq.fullname" .) -}} +{{- default "sentry-rabbitmq-ha" (include "sentry.rabbitmq.fullname" .) -}} {{- else -}} - {{ .Values.rabbitmq.host }} +{{ .Values.rabbitmq.host }} {{- end -}} {{- end -}} - diff --git a/sentry/templates/configmap-sentry.yaml b/sentry/templates/configmap-sentry.yaml index a5a82cacc..2a37383cb 100644 --- a/sentry/templates/configmap-sentry.yaml +++ b/sentry/templates/configmap-sentry.yaml @@ -1,6 +1,6 @@ {{- $redisHost := include "sentry.redis.host" . -}} {{- $redisPort := include "sentry.redis.port" . -}} -{{- $redisPass := .Values.redis.password -}} +{{- $redisPass := include "sentry.redis.password" . -}} apiVersion: v1 kind: ConfigMap metadata: @@ -110,14 +110,14 @@ data: DATABASES = { "default": { "ENGINE": "sentry.db.postgres", - "NAME": "{{ .Values.postgresql.postgresqlDatabase }}", - "USER": "{{ .Values.postgresql.postgresqlUsername }}", - "PASSWORD": os.environ.get("POSTGRES_PASSWORD", "{{ .Values.postgresql.postgresqlPassword }}"), - "HOST": "{{ default ( include "sentry.postgresql.host" .) .Values.postgresql.hostOverride }}", + "NAME": "{{ include "sentry.postgresql.database" . }}", + "USER": "{{ include "sentry.postgresql.username" . }}", + "PASSWORD": os.environ.get("POSTGRES_PASSWORD", "{{ include "sentry.postgresql.password" . }}"), + "HOST": "{{ include "sentry.postgresql.host" . }}", "PORT": {{ template "sentry.postgresql.port" . }}, - {{- if .Values.postgresql.postgresSslMode }} + {{- if .Values.externalPostgresql.sslMode }} 'OPTIONS': { - 'sslmode': '{{ .Values.postgresql.postgresSslMode }}', + 'sslmode': '{{ .Values.externalPostgresql.sslMode }}', }, {{- end }} } @@ -147,7 +147,7 @@ data: {{- if or (.Values.rabbitmq.enabled) (.Values.rabbitmq.host) }} BROKER_URL = os.environ.get("BROKER_URL", "amqp://{{ .Values.rabbitmq.rabbitmqUsername }}:{{ .Values.rabbitmq.rabbitmqPassword }}@{{ template "sentry.rabbitmq.host" . }}:5672//") - {{- else if .Values.redis.usePassword }} + {{- else if $redisPass }} BROKER_URL = os.environ.get("BROKER_URL", "redis://:{{ $redisPass }}@{{ $redisHost }}:{{ $redisPort }}/0") {{- else }} BROKER_URL = os.environ.get("BROKER_URL", "redis://{{ $redisHost }}:{{ $redisPort }}/0") diff --git a/sentry/templates/configmap-snuba.yaml b/sentry/templates/configmap-snuba.yaml index 16e2d15bb..9ae75a154 100644 --- a/sentry/templates/configmap-snuba.yaml +++ b/sentry/templates/configmap-snuba.yaml @@ -1,3 +1,4 @@ +{{- $redisPass := include "sentry.redis.password" . -}} apiVersion: v1 kind: ConfigMap metadata: @@ -16,14 +17,12 @@ data: DEBUG = env("DEBUG", "0").lower() in ("1", "true") - {{- if .Values.kafka.enabled }} DEFAULT_BROKERS = [{{ printf "%s:%s" (include "sentry.kafka.host" .) (include "sentry.kafka.port" .) | quote }}] - {{- end }} REDIS_HOST = {{ include "sentry.redis.host" . | quote }} REDIS_PORT = {{ include "sentry.redis.port" . }} - {{- if .Values.redis.password }} - REDIS_PASSWORD = {{ .Values.redis.password | quote }} + {{- if $redisPass }} + REDIS_PASSWORD = {{ $redisPass | quote }} {{- end }} REDIS_DB = int(env("REDIS_DB", 1)) USE_REDIS_CLUSTER = False diff --git a/sentry/templates/deployment-sentry-cron.yaml b/sentry/templates/deployment-sentry-cron.yaml index a4d366ef8..6bb763908 100644 --- a/sentry/templates/deployment-sentry-cron.yaml +++ b/sentry/templates/deployment-sentry-cron.yaml @@ -1,4 +1,4 @@ -{{- $redisHost := .Values.redis.hostOverride | default (include "sentry.redis.host" .) -}} +{{- $redisHost := include "sentry.redis.host" . -}} apiVersion: apps/v1 kind: Deployment metadata: diff --git a/sentry/templates/hooks/clickhouse-init.job.yaml b/sentry/templates/hooks/clickhouse-init.job.yaml index b9ce5875f..81289088f 100644 --- a/sentry/templates/hooks/clickhouse-init.job.yaml +++ b/sentry/templates/hooks/clickhouse-init.job.yaml @@ -1,9 +1,10 @@ {{- if .Values.hooks.enabled -}} {{- $clickhouseHost := include "sentry.clickhouse.host" . -}} {{- $clickhousePort := include "sentry.clickhouse.port" . -}} +{{- $clickhouseClusterName := include "sentry.clickhouse.cluster.name" . -}} {{- $tables := "errors groupassignee groupedmessage outcomes_hourly outcomes_mv_hourly outcomes_raw sentry sessions_hourly sessions_hourly_mv sessions_raw transactions" -}} {{- $dropQuery := "DROP TABLE IF EXISTS ${tbl}_dist" -}} -{{- $createQuery := .Release.Name | printf "CREATE TABLE ${tbl}_dist AS ${tbl}_local ENGINE = Distributed(%s-clickhouse, default, ${tbl}_local, rand())" -}} +{{- $createQuery := $clickhouseClusterName | printf "CREATE TABLE ${tbl}_dist AS ${tbl}_local ENGINE = Distributed(%s, default, ${tbl}_local, rand())" -}} apiVersion: batch/v1 kind: Job metadata: @@ -39,6 +40,7 @@ spec: - /bin/bash - -ec - >- + {{- if .Values.clickhouse.enabled }} for tbl in {{ $tables }}; do for ((i=0;i<{{ .Values.clickhouse.clickhouse.replicas }};i++)); do clickhouse-client --database=default --host={{ $clickhouseHost }}-$i.{{ $clickhouseHost }}-headless --port={{ $clickhousePort }} --query="{{ $dropQuery }}"; @@ -47,4 +49,10 @@ spec: clickhouse-client --database=default --host={{ $clickhouseHost }}-replica-$i.{{ $clickhouseHost }}-replica-headless --port={{ $clickhousePort }} --query="{{ $createQuery }}"; done done + {{- else }} + for tbl in {{ $tables }}; do + clickhouse-client --database=default --host={{ $clickhouseHost }} --port={{ $clickhousePort }} --query="{{ $dropQuery }}"; + clickhouse-client --database=default --host={{ $clickhouseHost }} --port={{ $clickhousePort }} --query="{{ $createQuery }}"; + done + {{- end }} {{- end }} diff --git a/sentry/templates/hooks/sentry-db-init.job.yaml b/sentry/templates/hooks/sentry-db-init.job.yaml index 8f48d692b..d92e7a5b2 100644 --- a/sentry/templates/hooks/sentry-db-init.job.yaml +++ b/sentry/templates/hooks/sentry-db-init.job.yaml @@ -57,4 +57,4 @@ spec: - name: config configMap: name: {{ template "sentry.fullname" . }}-sentry -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/sentry/templates/hooks/snuba-db-init.job.yaml b/sentry/templates/hooks/snuba-db-init.job.yaml index f8da6db5d..dca21005a 100644 --- a/sentry/templates/hooks/snuba-db-init.job.yaml +++ b/sentry/templates/hooks/snuba-db-init.job.yaml @@ -45,12 +45,17 @@ spec: - /bin/bash - -ec - >- + {{- if .Values.clickhouse.enabled }} for ((i=0;i<{{ .Values.clickhouse.clickhouse.replicas }};i++)); do export CLICKHOUSE_HOST={{ $clickhouseHost }}-$i.{{ $clickhouseHost }}-headless; snuba bootstrap --force; export CLICKHOUSE_HOST={{ $clickhouseHost }}-replica-$i.{{ $clickhouseHost }}-replica-headless; snuba bootstrap --force; done + {{- else }} + export CLICKHOUSE_HOST={{ $clickhouseHost }}; + snuba bootstrap --force; + {{- end }} env: - name: LOG_LEVEL value: debug diff --git a/sentry/templates/hooks/snuba-migrate.job.yaml b/sentry/templates/hooks/snuba-migrate.job.yaml index a741984bf..52d49d0bc 100644 --- a/sentry/templates/hooks/snuba-migrate.job.yaml +++ b/sentry/templates/hooks/snuba-migrate.job.yaml @@ -45,12 +45,17 @@ spec: - /bin/bash - -ec - >- + {{- if .Values.clickhouse.enabled }} for ((i=0;i<{{ .Values.clickhouse.clickhouse.replicas }};i++)); do export CLICKHOUSE_HOST={{ $clickhouseHost }}-$i.{{ $clickhouseHost }}-headless; snuba migrate; export CLICKHOUSE_HOST={{ $clickhouseHost }}-replica-$i.{{ $clickhouseHost }}-replica-headless; snuba migrate; done + {{- else }} + export CLICKHOUSE_HOST={{ $clickhouseHost }}; + snuba migrate; + {{- end }} env: - name: LOG_LEVEL value: debug diff --git a/sentry/templates/service-sentry.yaml b/sentry/templates/service-sentry.yaml index d381a6002..89a2402a7 100644 --- a/sentry/templates/service-sentry.yaml +++ b/sentry/templates/service-sentry.yaml @@ -35,4 +35,4 @@ spec: {{- with .Values.service.loadBalancerSourceRanges }} loadBalancerSourceRanges: {{- toYaml . | nindent 4 }} - {{- end }} \ No newline at end of file + {{- end }} diff --git a/sentry/templates/service-snuba.yaml b/sentry/templates/service-snuba.yaml index 724eb54d6..f65ef63e0 100644 --- a/sentry/templates/service-snuba.yaml +++ b/sentry/templates/service-snuba.yaml @@ -35,4 +35,4 @@ spec: {{- with .Values.service.loadBalancerSourceRanges }} loadBalancerSourceRanges: {{- toYaml . | nindent 4 }} - {{- end }} \ No newline at end of file + {{- end }} diff --git a/sentry/values.yaml b/sentry/values.yaml index 1b22cb677..2e821790a 100644 --- a/sentry/values.yaml +++ b/sentry/values.yaml @@ -280,6 +280,19 @@ clickhouse: - "ReadWriteOnce" storage: "30Gi" +## This value is only used when clickhouse.enabled is set to false +## +externalClickhouse: + ## Hostname or ip address of external clickhouse + ## + host: "clickhouse" + tcpPort: 9000 + ## Cluster name, can be found in config + ## (https://clickhouse.tech/docs/en/operations/server-configuration-parameters/settings/#server-settings-remote-servers) + ## or by executing `select * from system.clusters` + ## + # clusterName: test_shard_localhost + kafka: enabled: true replicaCount: 3 @@ -292,41 +305,55 @@ kafka: service: port: 9092 +## This value is only used when kafka.enabled is set to false +## +externalKafka: + ## Hostname or ip address of external kafka + ## + # host: "kafka-confluent" + port: 9092 + redis: - ## Required if the Redis component of this chart is disabled. (Existing Redis) - # - hostOverride: "" enabled: true nameOverride: sentry-redis usePassword: false - # Only used when internal redis is disabled - # host: redis - # Just omit the password field if your redis cluster doesn't use password + ## Just omit the password field if your redis cluster doesn't use password # password: redis - # port: 6379 master: persistence: enabled: true +## This value is only used when redis.enabled is set to false +## +externalRedis: + ## Hostname or ip address of external redis cluster + ## + # host: "redis" + port: 6379 + ## Just omit the password field if your redis cluster doesn't use password + # password: redis + postgresql: - ## Required if the Postgresql component of this chart is disabled. (Existing Postgres) - # - hostOverride: "" enabled: true nameOverride: sentry-postgresql postgresqlUsername: postgres postgresqlDatabase: sentry - # Only used when internal PG is disabled - # postgresqlHost: postgres - # postgresqlPassword: postgres - # postgresqlPort: 5432 - # postgresSslMode: require replication: enabled: false slaveReplicas: 2 synchronousCommit: "on" numSynchronousReplicas: 1 +## This value is only used when postgresql.enabled is set to false +## +externalPostgresql: + # host: postgres + port: 5432 + username: postgres + # password: postgres + database: sentry + # sslMode: require + rabbitmq: ## If disabled, Redis will be used instead as the broker. enabled: true @@ -339,7 +366,7 @@ rabbitmq: podDisruptionBudget: minAvailable: 1 - + persistentVolume: enabled: true resources: {}