-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sourcegraph): add support to scale worker horizontally
- Loading branch information
1 parent
5059ec3
commit 99dc046
Showing
5 changed files
with
308 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
{{- define "sourcegraph.worker" -}} | ||
{{- $top := index . 0 }} | ||
{{- $suffix := index . 1 -}} | ||
{{- $allowlist := index . 2 -}} | ||
{{- $blocklist := index . 3 -}} | ||
{{- $resources := index . 4 -}} | ||
|
||
{{- $name := $top.Values.worker.name -}} | ||
{{- if $suffix -}} | ||
{{- $name = printf "%s-%s" $name $suffix -}} | ||
{{- end -}} | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
annotations: | ||
description: Manages background processes. | ||
labels: | ||
{{- include "sourcegraph.labels" $top | nindent 4 }} | ||
{{- if $top.Values.worker.labels }} | ||
{{- toYaml $top.Values.worker.labels | nindent 4 }} | ||
{{- end }} | ||
deploy: sourcegraph | ||
app.kubernetes.io/component: worker | ||
name: {{ $name }} | ||
spec: | ||
minReadySeconds: 10 | ||
replicas: {{ $top.Values.worker.replicaCount }} | ||
revisionHistoryLimit: {{ $top.Values.sourcegraph.revisionHistoryLimit }} | ||
selector: | ||
matchLabels: | ||
{{- include "sourcegraph.selectorLabels" $top | nindent 6 }} | ||
app: worker | ||
{{- if $suffix }} | ||
worker-replica: {{ $name | quote }} | ||
{{- end }} | ||
strategy: | ||
rollingUpdate: | ||
maxSurge: 1 | ||
maxUnavailable: 1 | ||
type: RollingUpdate | ||
template: | ||
metadata: | ||
annotations: | ||
kubectl.kubernetes.io/default-container: worker | ||
{{- include "sourcegraph.redisChecksum" $top | nindent 8 }} | ||
{{- if $top.Values.sourcegraph.podAnnotations }} | ||
{{- toYaml $top.Values.sourcegraph.podAnnotations | nindent 8 }} | ||
{{- end }} | ||
{{- if $top.Values.worker.podAnnotations }} | ||
{{- toYaml $top.Values.worker.podAnnotations | nindent 8 }} | ||
{{- end }} | ||
labels: | ||
{{- include "sourcegraph.selectorLabels" $top | nindent 8 }} | ||
{{- if $top.Values.sourcegraph.podLabels }} | ||
{{- toYaml $top.Values.sourcegraph.podLabels | nindent 8 }} | ||
{{- end }} | ||
{{- if $top.Values.worker.podLabels }} | ||
{{- toYaml $top.Values.worker.podLabels | nindent 8 }} | ||
{{- end }} | ||
deploy: sourcegraph | ||
app: worker | ||
{{- if $suffix }} | ||
worker-replica: {{ $name | quote }} | ||
{{- end }} | ||
spec: | ||
containers: | ||
- name: worker | ||
env: | ||
{{- include "sourcegraph.redisConnection" $top | nindent 8 }} | ||
{{- if $allowlist }} | ||
- name: WORKER_JOB_ALLOWLIST | ||
value: {{ $allowlist }} | ||
{{- end }} | ||
{{- if $blocklist }} | ||
- name: WORKER_JOB_BLOCKLIST | ||
value: {{ $blocklist }} | ||
{{- end }} | ||
{{- range $name, $item := $top.Values.worker.env}} | ||
- name: {{ $name }} | ||
{{- $item | toYaml | nindent 10 }} | ||
{{- end }} | ||
{{- if $top.Values.blobstore.enabled }} | ||
- name: PRECISE_CODE_INTEL_UPLOAD_BACKEND | ||
value: blobstore | ||
- name: PRECISE_CODE_INTEL_UPLOAD_AWS_ENDPOINT | ||
value: http://blobstore:9000 | ||
{{- end }} | ||
- name: POD_NAME | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.name | ||
{{- include "sourcegraph.openTelemetryEnv" $top | nindent 8 }} | ||
image: {{ include "sourcegraph.image" (list $top "worker" ) }} | ||
imagePullPolicy: {{ $top.Values.sourcegraph.image.pullPolicy }} | ||
{{- with $top.Values.worker.args }} | ||
args: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
terminationMessagePolicy: FallbackToLogsOnError | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: debug | ||
scheme: HTTP | ||
initialDelaySeconds: 60 | ||
timeoutSeconds: 5 | ||
readinessProbe: | ||
httpGet: | ||
path: /ready | ||
port: debug | ||
scheme: HTTP | ||
periodSeconds: 5 | ||
timeoutSeconds: 5 | ||
ports: | ||
- containerPort: 3189 | ||
name: http | ||
- containerPort: 6060 | ||
name: debug | ||
- containerPort: 6996 | ||
name: prom | ||
{{- if not $top.Values.sourcegraph.localDevMode }} | ||
resources: | ||
{{- toYaml $resources | nindent 10 }} | ||
{{- end }} | ||
securityContext: | ||
{{- toYaml $top.Values.worker.containerSecurityContext | nindent 10 }} | ||
volumeMounts: | ||
{{- if $top.Values.worker.extraVolumeMounts }} | ||
{{- toYaml $top.Values.worker.extraVolumeMounts | nindent 8 }} | ||
{{- end }} | ||
{{- if $top.Values.worker.extraContainers }} | ||
{{- toYaml $top.Values.worker.extraContainers | nindent 6 }} | ||
{{- end }} | ||
securityContext: | ||
{{- toYaml $top.Values.worker.podSecurityContext | nindent 8 }} | ||
{{- include "sourcegraph.nodeSelector" (list $top "worker" ) | trim | nindent 6 }} | ||
{{- include "sourcegraph.affinity" (list $top "worker" ) | trim | nindent 6 }} | ||
{{- include "sourcegraph.tolerations" (list $top "worker" ) | trim | nindent 6 }} | ||
{{- with $top.Values.sourcegraph.imagePullSecrets }} | ||
imagePullSecrets: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- include "sourcegraph.renderServiceAccountName" (list $top "worker") | trim | nindent 6 }} | ||
volumes: | ||
{{- if $top.Values.worker.extraVolumes }} | ||
{{- toYaml $top.Values.worker.extraVolumes | nindent 6 }} | ||
{{- end }} | ||
{{- end -}} |
144 changes: 22 additions & 122 deletions
144
charts/sourcegraph/templates/worker/worker.Deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,22 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
annotations: | ||
description: Manages background processes. | ||
labels: | ||
{{- include "sourcegraph.labels" . | nindent 4 }} | ||
{{- if .Values.worker.labels }} | ||
{{- toYaml .Values.worker.labels | nindent 4 }} | ||
{{- end }} | ||
deploy: sourcegraph | ||
app.kubernetes.io/component: worker | ||
name: {{ .Values.worker.name }} | ||
spec: | ||
minReadySeconds: 10 | ||
replicas: {{ .Values.worker.replicaCount }} | ||
revisionHistoryLimit: {{ .Values.sourcegraph.revisionHistoryLimit }} | ||
selector: | ||
matchLabels: | ||
{{- include "sourcegraph.selectorLabels" . | nindent 6 }} | ||
app: worker | ||
strategy: | ||
rollingUpdate: | ||
maxSurge: 1 | ||
maxUnavailable: 1 | ||
type: RollingUpdate | ||
template: | ||
metadata: | ||
annotations: | ||
kubectl.kubernetes.io/default-container: worker | ||
{{- include "sourcegraph.redisChecksum" . | nindent 8 }} | ||
{{- if .Values.sourcegraph.podAnnotations }} | ||
{{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} | ||
{{- end }} | ||
{{- if .Values.worker.podAnnotations }} | ||
{{- toYaml .Values.worker.podAnnotations | nindent 8 }} | ||
{{- end }} | ||
labels: | ||
{{- include "sourcegraph.selectorLabels" . | nindent 8 }} | ||
{{- if .Values.sourcegraph.podLabels }} | ||
{{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} | ||
{{- end }} | ||
{{- if .Values.worker.podLabels }} | ||
{{- toYaml .Values.worker.podLabels | nindent 8 }} | ||
{{- end }} | ||
deploy: sourcegraph | ||
app: worker | ||
spec: | ||
containers: | ||
- name: worker | ||
env: | ||
{{- include "sourcegraph.redisConnection" .| nindent 8 }} | ||
{{- range $name, $item := .Values.worker.env}} | ||
- name: {{ $name }} | ||
{{- $item | toYaml | nindent 10 }} | ||
{{- end }} | ||
{{- if .Values.blobstore.enabled }} | ||
- name: PRECISE_CODE_INTEL_UPLOAD_BACKEND | ||
value: blobstore | ||
- name: PRECISE_CODE_INTEL_UPLOAD_AWS_ENDPOINT | ||
value: http://blobstore:9000 | ||
{{- end }} | ||
- name: POD_NAME | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.name | ||
{{- include "sourcegraph.openTelemetryEnv" . | nindent 8 }} | ||
image: {{ include "sourcegraph.image" (list . "worker" ) }} | ||
imagePullPolicy: {{ .Values.sourcegraph.image.pullPolicy }} | ||
{{- with .Values.worker.args }} | ||
args: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
terminationMessagePolicy: FallbackToLogsOnError | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: debug | ||
scheme: HTTP | ||
initialDelaySeconds: 60 | ||
timeoutSeconds: 5 | ||
readinessProbe: | ||
httpGet: | ||
path: /ready | ||
port: debug | ||
scheme: HTTP | ||
periodSeconds: 5 | ||
timeoutSeconds: 5 | ||
ports: | ||
- containerPort: 3189 | ||
name: http | ||
- containerPort: 6060 | ||
name: debug | ||
- containerPort: 6996 | ||
name: prom | ||
{{- if not .Values.sourcegraph.localDevMode }} | ||
resources: | ||
{{- toYaml .Values.worker.resources | nindent 10 }} | ||
{{- end }} | ||
securityContext: | ||
{{- toYaml .Values.worker.containerSecurityContext | nindent 10 }} | ||
volumeMounts: | ||
{{- if .Values.worker.extraVolumeMounts }} | ||
{{- toYaml .Values.worker.extraVolumeMounts | nindent 8 }} | ||
{{- end }} | ||
{{- if .Values.worker.extraContainers }} | ||
{{- toYaml .Values.worker.extraContainers | nindent 6 }} | ||
{{- end }} | ||
securityContext: | ||
{{- toYaml .Values.worker.podSecurityContext | nindent 8 }} | ||
{{- include "sourcegraph.nodeSelector" (list . "worker" ) | trim | nindent 6 }} | ||
{{- include "sourcegraph.affinity" (list . "worker" ) | trim | nindent 6 }} | ||
{{- include "sourcegraph.tolerations" (list . "worker" ) | trim | nindent 6 }} | ||
{{- with .Values.sourcegraph.imagePullSecrets }} | ||
imagePullSecrets: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- include "sourcegraph.renderServiceAccountName" (list . "worker") | trim | nindent 6 }} | ||
volumes: | ||
{{- if .Values.worker.extraVolumes }} | ||
{{- toYaml .Values.worker.extraVolumes | nindent 6 }} | ||
{{- end }} | ||
{{- if not .Values.worker.replicas }} | ||
{{- include "sourcegraph.worker" (list . "" "" "" .Values.worker.resources ) | nindent 0 }} | ||
{{- else }} | ||
{{- $dedicatedJobs := list }} | ||
{{- range .Values.worker.replicas }} | ||
{{- $dedicatedJobs = $dedicatedJobs | concat .jobs }} | ||
{{- end }} | ||
{{- $primaryBlocklist := join "," ($dedicatedJobs | uniq | sortAlpha) }} | ||
--- | ||
{{- include "sourcegraph.worker" (list . "" "all" $primaryBlocklist $.Values.worker.resources) | nindent 0 }} | ||
|
||
{{- range $idx, $item := .Values.worker.replicas }} | ||
--- | ||
{{- $replicaName := printf "%d" $idx }} | ||
{{- $allowlist := join "," ($item.jobs | uniq | sortAlpha) }} | ||
{{- $resources := $.Values.worker.resources -}} | ||
{{- if $item.resources -}} | ||
{{- $resources = $item.resources -}} | ||
{{- end -}} | ||
{{- include "sourcegraph.worker" (list $ $replicaName $allowlist "" $resources) | nindent 0 }} | ||
{{- end }} | ||
{{- end }} |
Oops, something went wrong.