Skip to content

Commit 091ea29

Browse files
committed
zoekt: use the standard graceful shutdown settings
Both Zoekt workloads now render SRC_PRE_SHUTDOWN_PAUSE and SRC_GRACEFUL_SHUTDOWN_TIMEOUT and take the usual preShutdownPause, gracefulShutdownTimeout and terminationGracePeriodSeconds overrides. The searcher no longer has its own 15 s drain, so its 60 s termination grace and the check that it is at least 30 s are gone. The helpers also accept a values map for nested services like zoekt.indexer. Amp-Thread-ID: https://ampcode.com/threads/T-597f342f-9754-47be-8f3e-3c5ffc344e41
1 parent 24c7d39 commit 091ea29

8 files changed

Lines changed: 52 additions & 25 deletions

File tree

‎charts/sourcegraph/README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,4 +641,3 @@ In addition to the documented values, all services also support the following va
641641
| zoektSearcher.storageLabels | object | `{}` | Labels to add to the `data` volume claim template of the `zoekt-searcher` StatefulSet. Kubernetes does not allow changing them on an installed StatefulSet. |
642642
| zoektSearcher.storageSize | string | `"200Gi"` | PVC Storage Request for the `zoekt-searcher` data volume, which caches the generations a webserver serves |
643643
| zoektSearcher.storageSubPath | string | `""` | Optional subPath for the `zoekt-searcher` primary data volume mount |
644-
| zoektSearcher.terminationGracePeriodSeconds | int | `60` | Time Kubernetes allows a Zoekt searcher to drain before forced termination. Must be at least 30. |

‎charts/sourcegraph/templates/_helpers/_gracefulShutdown.tpl‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{{/*
2-
Render the standard graceful-shutdown environment variables for a service.
3-
Service-specific values override global defaults. Explicit entries in the service's env map
2+
Render the standard graceful-shutdown environment variables for a service, given its values key or,
3+
for nested services such as zoekt.indexer, its values map. Service-specific values override global defaults. Explicit entries in the service's env map
44
take precedence so existing configurations remain valid.
55
*/}}
66
{{- define "sourcegraph.gracefulShutdownEnv" -}}
77
{{- $top := index . 0 -}}
8-
{{- $serviceName := index . 1 -}}
9-
{{- $service := index $top.Values $serviceName -}}
8+
{{- $service := index . 1 -}}
9+
{{- if kindIs "string" $service }}{{ $service = index $top.Values $service }}{{ end -}}
1010
{{- if not (hasKey $service.env "SRC_PRE_SHUTDOWN_PAUSE") }}
1111
- name: SRC_PRE_SHUTDOWN_PAUSE
1212
value: {{ default $top.Values.sourcegraph.preShutdownPause $service.preShutdownPause | quote }}
@@ -17,10 +17,11 @@ take precedence so existing configurations remain valid.
1717
{{- end }}
1818
{{- end }}
1919

20-
{{/* Render the pod termination deadline for a service. */}}
20+
{{/* Render the pod termination deadline for a service, given its values key or values map. */}}
2121
{{- define "sourcegraph.terminationGracePeriodSeconds" -}}
2222
{{- $top := index . 0 -}}
23-
{{- $service := index $top.Values (index . 1) -}}
23+
{{- $service := index . 1 -}}
24+
{{- if kindIs "string" $service }}{{ $service = index $top.Values $service }}{{ end -}}
2425
{{- $terminationGracePeriodSeconds := $top.Values.sourcegraph.terminationGracePeriodSeconds -}}
2526
{{- if and (hasKey $service "terminationGracePeriodSeconds") (ne $service.terminationGracePeriodSeconds nil) -}}
2627
{{- $terminationGracePeriodSeconds = $service.terminationGracePeriodSeconds -}}

‎charts/sourcegraph/templates/_helpers/_zoekt.tpl‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ Fail rendering when the zoekt values are inconsistent.
7171
{{- define "sourcegraph.zoekt.validate" -}}
7272
{{- $zoekt := .Values.zoekt -}}
7373
{{- if $zoekt.enabled -}}
74-
{{- if lt (int .Values.zoektSearcher.terminationGracePeriodSeconds) 30 -}}
75-
{{- fail "zoektSearcher.terminationGracePeriodSeconds must be at least 30" -}}
76-
{{- end -}}
7774
{{- if gt (int $zoekt.replicas) (int .Values.zoektSearcher.replicaCount) -}}
7875
{{- fail "zoekt.replicas must not exceed zoektSearcher.replicaCount" -}}
7976
{{- end -}}

‎charts/sourcegraph/templates/zoekt/zoekt-indexer.Deployment.yaml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ spec:
4343
app: zoekt-indexer
4444
deploy: sourcegraph
4545
spec:
46-
terminationGracePeriodSeconds: {{ .Values.sourcegraph.terminationGracePeriodSeconds }}
46+
{{- include "sourcegraph.terminationGracePeriodSeconds" (list . $indexer) | nindent 6 }}
4747
containers:
4848
- name: zoekt-indexer
4949
image: {{ include "sourcegraph.zoekt.image" (list . .Values.zoekt.indexerImage) }}
@@ -68,6 +68,7 @@ spec:
6868
fieldPath: metadata.name
6969
- name: TMPDIR
7070
value: /data
71+
{{- include "sourcegraph.gracefulShutdownEnv" (list . $indexer) | nindent 8 }}
7172
- name: HOME
7273
value: /data
7374
# The indexer deletes this directory's contents at startup.

‎charts/sourcegraph/templates/zoekt/zoekt-searcher.StatefulSet.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ spec:
7070
valueFrom:
7171
fieldRef:
7272
fieldPath: metadata.name
73+
{{- include "sourcegraph.gracefulShutdownEnv" (list . "zoektSearcher") | nindent 8 }}
7374
{{- if not .Values.sourcegraph.disableKubernetesSecrets }}
7475
{{- include "sourcegraph.databaseAuth" (list . "pgsql" "PG") | nindent 8 }}
7576
{{- end }}

‎charts/sourcegraph/tests/gracefulShutdown_test.yaml‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,44 @@ tests:
123123
name: SRC_GRACEFUL_SHUTDOWN_TIMEOUT
124124
value: 15s
125125
documentIndex: 0
126+
- it: should render global defaults for the Zoekt searcher
127+
template: zoekt/zoekt-searcher.StatefulSet.yaml
128+
set:
129+
zoekt.enabled: true
130+
asserts:
131+
- equal:
132+
path: spec.template.spec.terminationGracePeriodSeconds
133+
value: 30
134+
- contains:
135+
path: spec.template.spec.containers[0].env
136+
content:
137+
name: SRC_PRE_SHUTDOWN_PAUSE
138+
value: 5s
139+
- contains:
140+
path: spec.template.spec.containers[0].env
141+
content:
142+
name: SRC_GRACEFUL_SHUTDOWN_TIMEOUT
143+
value: 15s
144+
- it: should render service overrides for the Zoekt indexer
145+
template: zoekt/zoekt-indexer.Deployment.yaml
146+
set:
147+
zoekt:
148+
enabled: true
149+
indexer:
150+
preShutdownPause: 7s
151+
gracefulShutdownTimeout: 25s
152+
terminationGracePeriodSeconds: 35
153+
asserts:
154+
- equal:
155+
path: spec.template.spec.terminationGracePeriodSeconds
156+
value: 35
157+
- contains:
158+
path: spec.template.spec.containers[0].env
159+
content:
160+
name: SRC_PRE_SHUTDOWN_PAUSE
161+
value: 7s
162+
- contains:
163+
path: spec.template.spec.containers[0].env
164+
content:
165+
name: SRC_GRACEFUL_SHUTDOWN_TIMEOUT
166+
value: 25s

‎charts/sourcegraph/tests/zoekt_test.yaml‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ tests:
172172
value: RollingUpdate
173173
- equal:
174174
path: spec.template.spec.terminationGracePeriodSeconds
175-
value: 60
175+
value: 30
176176
- equal:
177177
path: spec.template.spec.containers[0].readinessProbe.httpGet.path
178178
value: /ready
@@ -483,17 +483,6 @@ tests:
483483
- failedTemplate:
484484
errorMessage: zoekt.activationTolerance must be less than zoekt.replicas
485485

486-
- it: should reject a webserver termination grace period below 30 seconds
487-
set:
488-
zoekt:
489-
enabled: true
490-
zoektSearcher:
491-
terminationGracePeriodSeconds: 10
492-
template: zoekt/zoekt-searcher.StatefulSet.yaml
493-
asserts:
494-
- failedTemplate:
495-
errorMessage: zoektSearcher.terminationGracePeriodSeconds must be at least 30
496-
497486
- it: should reject routing false once indexed-search is removed
498487
set:
499488
zoekt:

‎charts/sourcegraph/values.yaml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,6 @@ zoektSearcher:
784784
replicaCount: 2
785785
# -- Pod disruption budget for `zoekt-searcher`. Configure either `minAvailable` or `maxUnavailable` to enable it.
786786
podDisruptionBudget: {}
787-
# -- Time Kubernetes allows a Zoekt searcher to drain before forced termination. Must be at least 30.
788-
terminationGracePeriodSeconds: 60
789787
# -- Liveness probe tuning for the `zoekt-searcher` container (`/healthz` on port 6070)
790788
livenessProbe:
791789
failureThreshold: 10

0 commit comments

Comments
 (0)