Skip to content

Commit

Permalink
feat: separate config for external services (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
donbeave authored Jul 7, 2020
1 parent fe269f2 commit 5e80eba
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 78 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
.idea
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion sentry/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
121 changes: 78 additions & 43 deletions sentry/templates/_helper.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

Expand All @@ -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 -}}

Expand All @@ -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 -}}

Expand All @@ -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 -}}

Expand All @@ -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 -}}

Expand All @@ -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 -}}

16 changes: 8 additions & 8 deletions sentry/templates/configmap-sentry.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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 }}
}
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 3 additions & 4 deletions sentry/templates/configmap-snuba.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $redisPass := include "sentry.redis.password" . -}}
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sentry/templates/deployment-sentry-cron.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- $redisHost := .Values.redis.hostOverride | default (include "sentry.redis.host" .) -}}
{{- $redisHost := include "sentry.redis.host" . -}}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
10 changes: 9 additions & 1 deletion sentry/templates/hooks/clickhouse-init.job.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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 }}";
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion sentry/templates/hooks/sentry-db-init.job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ spec:
- name: config
configMap:
name: {{ template "sentry.fullname" . }}-sentry
{{- end -}}
{{- end -}}
5 changes: 5 additions & 0 deletions sentry/templates/hooks/snuba-db-init.job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions sentry/templates/hooks/snuba-migrate.job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sentry/templates/service-sentry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ spec:
{{- with .Values.service.loadBalancerSourceRanges }}
loadBalancerSourceRanges:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion sentry/templates/service-snuba.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ spec:
{{- with .Values.service.loadBalancerSourceRanges }}
loadBalancerSourceRanges:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Loading

0 comments on commit 5e80eba

Please sign in to comment.