Skip to content

Commit 33eafc2

Browse files
michaellzcclaude
andauthored
feat(worker): support per-replica replicaCount override (#887)
## Summary Follow-up to #582, which added support for scaling `worker` horizontally by configuring dedicated replicas per set of jobs. This PR adds a `replicaCount` override for each distinct worker replica. Previously every generated worker deployment (the primary `worker` and each dedicated `worker-N`) inherited the single top-level `worker.replicaCount`. Now each entry under `worker.replicas` can set its own `replicaCount`, falling back to `worker.replicaCount` when unset. This lets operators scale individual dedicated workers horizontally only for jobs that are safe to scale that way. ```yaml worker: replicas: - replicaCount: 3 # make sure jobs are safe to scale horizontally jobs: - job1 - job2 - jobs: - job3 # inherits worker.replicaCount ``` ## Changes - `templates/_worker.tpl`: added a `$replicaCount` parameter to the `sourcegraph.worker` helper and use it for `spec.replicas`. - `templates/worker/worker.Deployment.yaml`: pass `worker.replicaCount` for the primary worker, and per-replica `replicaCount` (defaulting to `worker.replicaCount`) for each dedicated replica. - `values.yaml`: documented the new per-replica `replicaCount` option. - `tests/worker_test.yaml`: added tests covering the default-inheritance and per-replica override behaviour. - `CHANGELOG.md`: added an entry. ## Test plan - `helm unittest charts/sourcegraph` — all 99 tests pass (7 in the worker suite). - `./scripts/helm-docs.sh` produces no uncommitted changes. Slack thread: https://sourcegraph.slack.com/archives/C0ATB8N5P3Q/p1781106413632049 --- _Generated by [Claude Code](https://claude.ai/code/session_01L76QgBN8t9M3gbJo5NdyZo)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6c0bd14 commit 33eafc2

5 files changed

Lines changed: 71 additions & 4 deletions

File tree

charts/sourcegraph/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Use `**BREAKING**:` to denote a breaking change
88

99
## Unreleased
1010

11+
- Added support for overriding `replicaCount` per dedicated `worker` replica via `worker.replicas[].replicaCount`, falling back to `worker.replicaCount` when unset
1112
- Added support for overriding the image repository on a per-service basis via `<serviceName>.image.repository`, falling back to the global `sourcegraph.image.repository` when unset
1213
- Added livenessProbe to zoekt-webserver in indexed-search to detect and restart hung pods
1314
- Fix Pod Disruption Budget for sourcegraph-frontend

charts/sourcegraph/templates/_worker.tpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{{- $allowlist := index . 2 -}}
55
{{- $blocklist := index . 3 -}}
66
{{- $resources := index . 4 -}}
7+
{{- $replicaCount := index . 5 -}}
78

89
{{- $name := $top.Values.worker.name -}}
910
{{- if $suffix -}}
@@ -24,7 +25,7 @@ metadata:
2425
name: {{ $name }}
2526
spec:
2627
minReadySeconds: 10
27-
replicas: {{ $top.Values.worker.replicaCount }}
28+
replicas: {{ $replicaCount }}
2829
revisionHistoryLimit: {{ $top.Values.sourcegraph.revisionHistoryLimit }}
2930
selector:
3031
matchLabels:

charts/sourcegraph/templates/worker/worker.Deployment.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{- end }}
55

66
{{- if not .Values.worker.replicas }}
7-
{{- include "sourcegraph.worker" (list . "" "" $globalBlocklist .Values.worker.resources ) | nindent 0 }}
7+
{{- include "sourcegraph.worker" (list . "" "" $globalBlocklist .Values.worker.resources .Values.worker.replicaCount ) | nindent 0 }}
88
{{- else }}
99
{{- $dedicatedJobs := list }}
1010
{{- $dedicatedJobs = $dedicatedJobs | concat .Values.worker.blocklist }}
@@ -13,7 +13,7 @@
1313
{{- end }}
1414
{{- $primaryBlocklist := join "," ($dedicatedJobs | uniq | sortAlpha) }}
1515
---
16-
{{- include "sourcegraph.worker" (list . "" "all" $primaryBlocklist $.Values.worker.resources) | nindent 0 }}
16+
{{- include "sourcegraph.worker" (list . "" "all" $primaryBlocklist $.Values.worker.resources $.Values.worker.replicaCount) | nindent 0 }}
1717

1818
{{- range $idx, $item := .Values.worker.replicas }}
1919
---
@@ -23,6 +23,10 @@
2323
{{- if $item.resources -}}
2424
{{- $resources = $item.resources -}}
2525
{{- end -}}
26-
{{- include "sourcegraph.worker" (list $ $replicaName $allowlist "" $resources) | nindent 0 }}
26+
{{- $replicaCount := $.Values.worker.replicaCount -}}
27+
{{- if $item.replicaCount -}}
28+
{{- $replicaCount = $item.replicaCount -}}
29+
{{- end -}}
30+
{{- include "sourcegraph.worker" (list $ $replicaName $allowlist "" $resources $replicaCount) | nindent 0 }}
2731
{{- end }}
2832
{{- end }}

charts/sourcegraph/tests/worker_test.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,61 @@ tests:
147147
requests:
148148
cpu: 2000m
149149
memory: 4Gi
150+
- it: should default each replica deployment to worker.replicaCount when replicaCount is not overridden
151+
template: worker/worker.Deployment.yaml
152+
set:
153+
worker:
154+
replicaCount: 2
155+
replicas:
156+
- jobs: ["job1", "job2"]
157+
- jobs: ["job3", "job4"]
158+
asserts:
159+
- equal:
160+
path: spec.replicas
161+
value: 2
162+
documentIndex: 0
163+
- equal:
164+
path: spec.replicas
165+
value: 2
166+
documentIndex: 1
167+
- equal:
168+
path: spec.replicas
169+
value: 2
170+
documentIndex: 2
171+
- it: should override replicaCount per replica deployment
172+
template: worker/worker.Deployment.yaml
173+
set:
174+
worker:
175+
replicaCount: 1
176+
replicas:
177+
- jobs: ["job1", "job2"]
178+
replicaCount: 3
179+
- jobs: ["job3", "job4"]
180+
asserts:
181+
- containsDocument:
182+
kind: Deployment
183+
apiVersion: apps/v1
184+
name: worker
185+
documentIndex: 0
186+
- equal:
187+
path: spec.replicas
188+
value: 1
189+
documentIndex: 0
190+
- containsDocument:
191+
kind: Deployment
192+
apiVersion: apps/v1
193+
name: worker-0
194+
documentIndex: 1
195+
- equal:
196+
path: spec.replicas
197+
value: 3
198+
documentIndex: 1
199+
- containsDocument:
200+
kind: Deployment
201+
apiVersion: apps/v1
202+
name: worker-1
203+
documentIndex: 2
204+
- equal:
205+
path: spec.replicas
206+
value: 1
207+
documentIndex: 2

charts/sourcegraph/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,9 @@ worker:
13141314
replicas:
13151315
[]
13161316
# - jobs: []
1317+
# # -- Number of pods for this dedicated worker replica. Defaults to worker.replicaCount.
1318+
# # Only increase this for replicas whose jobs are safe to scale horizontally.
1319+
# replicaCount: 1
13171320
# resources:
13181321
# limits:
13191322
# cpu: "2"

0 commit comments

Comments
 (0)