Skip to content

Commit b228fa6

Browse files
committed
fix(sourcegraph): incorrect rendering of redis conn env var
1 parent 28a024f commit b228fa6

File tree

2 files changed

+86
-11
lines changed

2 files changed

+86
-11
lines changed

charts/sourcegraph/templates/_helpers.tpl

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,23 +249,41 @@ 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:
252+
Set redisCache and redisStore endpoints,
253+
so that customers can configure them any of these ways:
254+
254255
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
256+
257+
2. Use an existing Kubernetes secret, 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+
269+
5. Do not create or use Kubernetes secrets, but pass custom values (ex. external Redis) directly as environment variables into the needed pods, by configuring:
270+
.Values.sourcegraph.disableKubernetesSecrets: true,
271+
.Values.redisCache.connection.endpoint: "",
272+
.Values.redisStore.connection.endpoint: "",
273+
and defining the REDIS_CACHE_ENDPOINT and REDIS_STORE_ENDPOINT env vars on frontend, gitserver, searcher, and worker pods
274+
258275
*/}}
259276
{{- define "sourcegraph.redisConnection" -}}
260277
{{- if .Values.sourcegraph.disableKubernetesSecrets -}}
261-
{{- if .Values.redisCache.connection.endpoint -}}
262-
- name: REDIS_CACHE_ENDPOINT
263-
value: {{ .Values.redisCache.connection.endpoint }}
278+
{{- $cacheEndpoint := dig "connection" "endpoint" "" .Values.redisCache -}}
279+
{{- $storeEndpoint := dig "connection" "endpoint" "" .Values.redisStore -}}
280+
{{- if not (and $cacheEndpoint $storeEndpoint) -}}
281+
{{- fail ".Values.redisCache.connection.endpoint and .Values.redisStore.connection.endpoint must be set when disableKubernetesSecrets is true!" -}}
264282
{{- end -}}
265-
{{- if .Values.redisStore.connection.endpoint -}}
283+
- name: REDIS_CACHE_ENDPOINT
284+
value: {{ $cacheEndpoint }}
266285
- name: REDIS_STORE_ENDPOINT
267-
value: {{ .Values.redisStore.connection.endpoint }}
268-
{{- end -}}
286+
value: {{ $storeEndpoint }}
269287
{{- else -}}
270288
- name: REDIS_CACHE_ENDPOINT
271289
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)