Skip to content

Commit c3247c5

Browse files
michaellzcmarcleblanc2
authored andcommitted
fix(sourcegraph): incorrect rendering of redis connection env vars (#786)
reworked #784 ### Checklist - [x] Follow the [manual testing process](https://github.com/sourcegraph/deploy-sourcegraph-helm/blob/main/TEST.md) - [x] Update [changelog](https://github.com/sourcegraph/deploy-sourcegraph-helm/blob/main/charts/sourcegraph/CHANGELOG.md) - [x] Update [Kubernetes update doc](https://docs.sourcegraph.com/admin/updates/kubernetes) ### Test plan added unit test --------- Co-authored-by: Marc <[email protected]> (cherry picked from commit 5ff81c8)
1 parent df9d0f8 commit c3247c5

File tree

2 files changed

+81
-12
lines changed

2 files changed

+81
-12
lines changed

charts/sourcegraph/templates/_helpers.tpl

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,23 +249,35 @@ app.kubernetes.io/name: jaeger
249249
{{- end }}
250250

251251
{{/*
252-
Set redisCache and redisStore endpoints
253-
So that customers can configure them any of these ways:
254-
1. Create a new Kubernetes secret, with default values (default, no override config required)
255-
2. Use an existing Kubernetes secret, by configuring .Values.redisCache.connection.existingSecret
256-
3. Do not create or use Kubernetes secrets, just pass the default values directly as environment variables into the needed pods, by configuring .Values.sourcegraph.disableKubernetesSecrets = true
257-
4. Do not create or use Kubernetes secrets, but pass custom values (ex. external Redis) directly as environment variables into the needed pods, by configuring .Values.sourcegraph.disableKubernetesSecrets = true, .Values.redisCache.connection.endpoint = "", .Values.redisStore.connection.endpoint = "", and defining the REDIS_CACHE_ENDPOINT and REDIS_STORE_ENDPOINT env vars on frontend, gitserver, searcher, and worker pods
252+
Set redisCache and redisStore endpoints,
253+
so that customers can configure them any of these ways:
254+
255+
1. Create new Kubernetes secrets, with default values (default, no override config required)
256+
257+
2. Use existing Kubernetes secrets, managed externally, by configuring:
258+
.Values.redisCache.connection.existingSecret: <secret name>
259+
.Values.redisStore.connection.existingSecret: <secret name>
260+
261+
3. Do not create or use Kubernetes secrets, just pass the default values directly as environment variables into the needed pods, by configuring:
262+
.Values.sourcegraph.disableKubernetesSecrets: true
263+
264+
4. Do not create or use Kubernetes secrets, but provide custom values (ex. external Redis) to have this function pass them into the REDIS_CACHE_ENDPOINT and REDIS_STORE_ENDPOINT env vars on frontend, gitserver, searcher, and worker pods, by configuring:
265+
.Values.sourcegraph.disableKubernetesSecrets: true
266+
.Values.redisCache.connection.endpoint: <custom value for REDIS_CACHE_ENDPOINT>
267+
.Values.redisStore.connection.endpoint: <custom value for REDIS_STORE_ENDPOINT>
268+
258269
*/}}
259270
{{- define "sourcegraph.redisConnection" -}}
260271
{{- if .Values.sourcegraph.disableKubernetesSecrets -}}
261-
{{- if .Values.redisCache.connection.endpoint -}}
262-
- name: REDIS_CACHE_ENDPOINT
263-
value: {{ .Values.redisCache.connection.endpoint }}
272+
{{- $cacheEndpoint := dig "connection" "endpoint" "" .Values.redisCache -}}
273+
{{- $storeEndpoint := dig "connection" "endpoint" "" .Values.redisStore -}}
274+
{{- if not (and $cacheEndpoint $storeEndpoint) -}}
275+
{{- fail ".Values.redisCache.connection.endpoint and .Values.redisStore.connection.endpoint must be set when disableKubernetesSecrets is true!" -}}
264276
{{- end -}}
265-
{{- if .Values.redisStore.connection.endpoint -}}
277+
- name: REDIS_CACHE_ENDPOINT
278+
value: {{ $cacheEndpoint }}
266279
- name: REDIS_STORE_ENDPOINT
267-
value: {{ .Values.redisStore.connection.endpoint }}
268-
{{- end -}}
280+
value: {{ $storeEndpoint }}
269281
{{- else -}}
270282
- name: REDIS_CACHE_ENDPOINT
271283
valueFrom:
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
suite: redisConnection
3+
templates:
4+
- frontend/sourcegraph-frontend.Deployment.yaml
5+
tests:
6+
- it: should reference the default secret
7+
asserts:
8+
- contains:
9+
path: spec.template.spec.containers[0].env
10+
content:
11+
name: REDIS_CACHE_ENDPOINT
12+
valueFrom:
13+
secretKeyRef:
14+
key: endpoint
15+
name: redis-cache
16+
- contains:
17+
path: spec.template.spec.containers[0].env
18+
content:
19+
name: REDIS_STORE_ENDPOINT
20+
valueFrom:
21+
secretKeyRef:
22+
key: endpoint
23+
name: redis-store
24+
- it: should not reference secret when .sourcegraph.disableKubernetesSecrets is true
25+
set:
26+
sourcegraph:
27+
disableKubernetesSecrets: true
28+
redisCache:
29+
connection:
30+
endpoint: redis-cache-svc
31+
redisStore:
32+
connection:
33+
endpoint: redis-store-svc
34+
asserts:
35+
- contains:
36+
path: spec.template.spec.containers[0].env
37+
content:
38+
name: REDIS_CACHE_ENDPOINT
39+
value: redis-cache-svc
40+
- contains:
41+
path: spec.template.spec.containers[0].env
42+
content:
43+
name: REDIS_STORE_ENDPOINT
44+
value: redis-store-svc
45+
- it: should fail when .sourcegraph.disableKubernetesSecrets is true but .Values.redisCache.connection.endpoint and .Values.redisStore.connection.endpoint are not set
46+
set:
47+
sourcegraph:
48+
disableKubernetesSecrets: true
49+
redisCache:
50+
connection:
51+
endpoint: ""
52+
redisStore:
53+
connection:
54+
endpoint: ""
55+
asserts:
56+
- failedTemplate:
57+
errorMessage: .Values.redisCache.connection.endpoint and .Values.redisStore.connection.endpoint must be set when disableKubernetesSecrets is true!

0 commit comments

Comments
 (0)