Skip to content

Commit 6e9ed2f

Browse files
committed
Add the Zoekt indexer and searchers
Adds two opt-in services next to the legacy indexed-search StatefulSet: - zoekt-indexer (zoektIndexer.enabled): a Deployment that runs index jobs and publishes generations through object storage, with a scratch PVC per pod by default or an emptyDir. - zoekt-searcher (zoektSearcher.enabled): a StatefulSet of webservers that serve the active generations of their slots. Like gitserver continuity, the Zoekt settings (SRC_ZOEKT_*) are environment variables only; the chart has no values for them. indexedSearch.enabled removes the legacy StatefulSet once searches have switched, and the frontend then gets an empty INDEXED_SEARCH_SERVERS. Amp-Thread-ID: https://ampcode.com/threads/T-597f342f-9754-47be-8f3e-3c5ffc344e41
1 parent f689d28 commit 6e9ed2f

20 files changed

Lines changed: 1321 additions & 3 deletions

‎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 the experimental `zoekt-indexer` Deployment and `zoekt-searcher` StatefulSet behind `zoektIndexer.enabled` and `zoektSearcher.enabled` (both default `false`, which renders the same manifests as before). The indexer builds index generations and publishes them through object storage, and the searchers download and serve them, next to `indexed-search`. The chart does not configure the Zoekt indexer itself: it stays off until `SRC_ZOEKT_INDEXER_ENABLED` is set in the services' `env`. Added `indexedSearch.enabled` (default `true`) to remove the `indexed-search` objects; the frontend then stops discovering them. Prometheus scrapes the searchers and indexers on port `6060`. See [Zoekt indexer and searchers](README.md#zoekt-indexer-and-searchers). Requires Sourcegraph images that include the Zoekt indexer and searchers.
1112
- The `correct-data-dir-permissions` init containers of `pgsql`, `codeintel-db`, and `codeinsights-db` now run the database's own image instead of `sourcegraph/alpine-3.14`, which was based on an end-of-life Alpine release. The chart no longer pulls `alpine-3.14`, so private registries no longer need to mirror it. `alpine.image` has been removed and is ignored if set; `alpine.containerSecurityContext`, `alpine.resources`, and `codeInsightsDB.init.containerSecurityContext` still apply.
1213
- Added `sourcegraph.selectorLabelsOverride`, `<serviceName>.extraSelectorLabels`, and `storageLabels` on `gitserver`, `grafana`, `indexedSearch`, and `searcher`, so the chart can render the selectors and volume claim templates of workloads created outside it, such as with Kustomize, and a Helm release can take them over without deleting them. All default to empty, so existing releases render the same selectors. Never change them on an installed release: Kubernetes does not allow changing these fields. See [Adopting existing workloads](README.md#adopting-existing-workloads).
1314
- Fixed `frontend.command` and `migrator.command` rendering a list as a single element, e.g. `["sh", "-c", "<script>"]` became `[sh -c <script>]`, so the container failed to start. Both are now rendered as YAML lists and documented in `values.yaml`. A string holding a YAML list, the only form that worked before, still renders unchanged.

‎charts/sourcegraph/README.md‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@ Helm only takes over an existing object that has the
106106
and `meta.helm.sh/release-namespace` annotations, or when installing with
107107
`--take-ownership` (Helm 3.17 or later).
108108

109+
## Zoekt indexer and searchers
110+
111+
Experimental: requires Sourcegraph images that include the Zoekt indexer and
112+
searchers.
113+
114+
The Zoekt indexer and searchers are a separate indexed search fleet. The
115+
`zoekt-indexer` Deployment builds index generations and publishes them through
116+
object storage, and the `zoekt-searcher` StatefulSet downloads and serves them.
117+
They run next to the `indexed-search` StatefulSet, with different workload,
118+
Service, and PVC names.
119+
120+
- `zoektIndexer.enabled` and `zoektSearcher.enabled` render the two services.
121+
- `indexedSearch.enabled` renders the `indexed-search` StatefulSet and its
122+
Services, PodDisruptionBudget, and ServiceAccount. When it is `false`, the
123+
frontend gets empty `INDEXED_SEARCH_SERVERS` and `INDEXED_SEARCH_INDEXER`, so
124+
it stops looking for the removed StatefulSet, unless `frontend.env` sets them.
125+
Kubernetes keeps a StatefulSet's PVCs after the StatefulSet is deleted, so
126+
delete the `data-indexed-search-*` PVCs to free their disks.
127+
128+
The chart does not configure the Zoekt indexer itself. It stays off until
129+
`SRC_ZOEKT_INDEXER_ENABLED` is set, along with settings such as
130+
`SRC_ZOEKT_SEARCHER_ROUTING` and `SRC_ZOEKT_WARM_REPLICAS`, identically in the
131+
`env` of `frontend`, `worker`, `searcher`, `zoektSearcher`, and `zoektIndexer`.
132+
109133
## Configuration Options
110134

111135
Reference the below chart for all available configuration parameters.
@@ -264,6 +288,7 @@ In addition to the documented values, all services also support the following va
264288
| grafana.storageSize | string | `"2Gi"` | PVC Storage Request for `grafana` data volume |
265289
| grafana.storageSubPath | string | `""` | Optional subPath for the `grafana` primary data volume mount |
266290
| indexedSearch.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"readOnlyRootFilesystem":true,"runAsGroup":101,"runAsUser":100}` | Security context for the `zoekt-webserver` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) |
291+
| indexedSearch.enabled | bool | `true` | Enable the `indexed-search` StatefulSet (`zoekt-webserver` and `zoekt-indexserver`) and its Services, PodDisruptionBudget, and ServiceAccount. Set to `false` to remove it after searches have switched to the Zoekt indexer and searchers, see [Zoekt indexer and searchers](#zoekt-indexer-and-searchers). |
267292
| indexedSearch.env | object | the chart will add some default environment values | Environment variables for the `zoekt-webserver` container |
268293
| indexedSearch.image.defaultTag | string | `<appVersion>@sha256:<digest>`, pinned by each release | Docker image tag for the `zoekt-webserver` image |
269294
| indexedSearch.image.name | string | `"indexed-searcher"` | Docker image name for the `zoekt-webserver` image |
@@ -538,3 +563,39 @@ In addition to the documented values, all services also support the following va
538563
| worker.resources | object | `{"limits":{"cpu":"2","memory":"4G"},"requests":{"cpu":"500m","memory":"2G"}}` | Resource requests & limits for the `worker` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) |
539564
| worker.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `worker` |
540565
| worker.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
566+
| zoektIndexer.args | list | `[]` | Arguments for the indexer container |
567+
| zoektIndexer.command | list | `[]` | Command for the indexer container, replacing the image's entrypoint |
568+
| zoektIndexer.enabled | bool | `false` | Enable the `zoekt-indexer` Deployment, which builds indexed search shards and publishes them through object storage for the Zoekt searchers. Experimental: it does nothing until `SRC_ZOEKT_INDEXER_ENABLED` is set. See [Zoekt indexer and searchers](#zoekt-indexer-and-searchers). |
569+
| zoektIndexer.env | object | `{"DEPLOY_TYPE":{"value":"helm"}}` | Environment variables for the `zoekt-indexer` container |
570+
| zoektIndexer.image.defaultTag | string | `"{{ .Chart.AppVersion }}"` | Docker image tag for the `zoekt-indexer` image |
571+
| zoektIndexer.image.name | string | `"zoekt-indexer"` | Docker image name for the `zoekt-indexer` image |
572+
| zoektIndexer.image.repository | string | `""` | Override the global sourcegraph.image.repository for the `zoekt-indexer` image |
573+
| zoektIndexer.image.tag | string | `""` | Override the tag of the `zoekt-indexer` image |
574+
| zoektIndexer.name | string | `"zoekt-indexer"` | Name of the indexer Deployment and its metrics Service |
575+
| zoektIndexer.replicaCount | int | `2` | Number of `zoekt-indexer` pods |
576+
| zoektIndexer.resources | object | `{"limits":{"cpu":"4","memory":"4G"},"requests":{"cpu":"1","memory":"1G"}}` | Resource requests & limits for the `zoekt-indexer` container |
577+
| zoektIndexer.scratch.persistentVolume | bool | `true` | Back each indexer pod's scratch directory, where it fetches repositories and builds shards, with its own PersistentVolumeClaim (a generic ephemeral volume). Kubernetes deletes the claim, and with a `Delete` reclaim policy its disk, when the pod goes away, such as on scale-down or a rollout. Set to `false` to use an `emptyDir` on the node's disk instead, with a matching `ephemeral-storage` request |
578+
| zoektIndexer.scratch.size | string | `"100Gi"` | Size of the scratch volume: the claim's storage request, or the `emptyDir` size limit and `ephemeral-storage` request. Large monorepos need room for a fetch and its shards per concurrent job |
579+
| zoektIndexer.scratch.storageClassName | string | `""` | Storage class of the scratch volume's claim. Its reclaim policy should be `Delete`, so disks go away with their pods. Defaults to `<storageClass.name>-scratch`, which the chart creates like `storageClass` but with the `Delete` reclaim policy, or to the cluster's default storage class if `storageClass.create` is false |
580+
| zoektSearcher.args | list | `[]` | Arguments for the `zoekt-searcher` container |
581+
| zoektSearcher.command | list | `[]` | Command for the `zoekt-searcher` container, replacing the image's entrypoint |
582+
| zoektSearcher.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"readOnlyRootFilesystem":true,"runAsGroup":101,"runAsUser":100}` | Security context for the `zoekt-searcher` and `zoekt-indexer` containers, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) |
583+
| zoektSearcher.enabled | bool | `false` | Enable the `zoekt-searcher` StatefulSet, which downloads and serves the shards the Zoekt indexers publish. Experimental: the frontend searches it only with `SRC_ZOEKT_INDEXER_ENABLED` set. The indexer pods share its ServiceAccount, security contexts, and scheduling settings. See [Zoekt indexer and searchers](#zoekt-indexer-and-searchers). |
584+
| zoektSearcher.env | object | `{"DEPLOY_TYPE":{"value":"helm"}}` | Environment variables for the `zoekt-searcher` container |
585+
| zoektSearcher.image.name | string | `"zoekt-searcher"` | Docker image name for the `zoekt-searcher` image. The tag defaults to the chart's appVersion. |
586+
| zoektSearcher.image.repository | string | `""` | Override the global sourcegraph.image.repository for the `zoekt-searcher` image |
587+
| zoektSearcher.image.tag | string | `""` | Override the tag of the `zoekt-searcher` image |
588+
| zoektSearcher.livenessProbe | object | `{"failureThreshold":10,"initialDelaySeconds":120,"periodSeconds":60,"timeoutSeconds":5}` | Liveness probe tuning for the `zoekt-searcher` container (`/healthz` on port 6070) |
589+
| zoektSearcher.name | string | `"zoekt-searcher"` | Name used by the `zoekt-searcher` StatefulSet, PodDisruptionBudget, and ServiceAccount. Does not affect service names or PVCs. The frontend finds the webservers through the StatefulSet named `zoekt-searcher` (`k8s+rpc://zoekt-searcher:6070?kind=sts`), so if you change it, also list the webservers in `SRC_ZOEKT_SEARCHERS` in `frontend.env`. |
590+
| zoektSearcher.podDisruptionBudget | object | `{}` | Pod disruption budget for `zoekt-searcher`. Configure either `minAvailable` or `maxUnavailable` to enable it. |
591+
| zoektSearcher.podSecurityContext | object | `{"fsGroup":101,"fsGroupChangePolicy":"OnRootMismatch"}` | Security context for the `zoekt-searcher` and `zoekt-indexer` pods, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod) |
592+
| zoektSearcher.readinessProbe | object | `{"failureThreshold":3,"periodSeconds":5,"timeoutSeconds":5}` | Readiness probe tuning for the `zoekt-searcher` container (`/ready` on port 6070) |
593+
| zoektSearcher.replicaCount | int | `2` | Number of `zoekt-searcher` pods |
594+
| zoektSearcher.resources | object | `{"limits":{"cpu":"2","memory":"4G"},"requests":{"cpu":"500m","memory":"2G"}}` | Resource requests & limits for the `zoekt-searcher` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) |
595+
| zoektSearcher.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `zoekt-searcher` and `zoekt-indexer` |
596+
| zoektSearcher.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
597+
| zoektSearcher.storageAnnotations | object | `{}` | Optional annotations to add to the `zoekt-searcher` PVC |
598+
| zoektSearcher.storageClassName | string | `""` | Storage class of the `zoekt-searcher` data volume. Defaults to `storageClass.name`. |
599+
| 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. |
600+
| zoektSearcher.storageSize | string | `"200Gi"` | PVC Storage Request for the `zoekt-searcher` data volume, which caches the generations a webserver serves |
601+
| zoektSearcher.storageSubPath | string | `""` | Optional subPath for the `zoekt-searcher` primary data volume mount |

‎charts/sourcegraph/README.md.gotmpl‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@ Helm only takes over an existing object that has the
106106
and `meta.helm.sh/release-namespace` annotations, or when installing with
107107
`--take-ownership` (Helm 3.17 or later).
108108

109+
## Zoekt indexer and searchers
110+
111+
Experimental: requires Sourcegraph images that include the Zoekt indexer and
112+
searchers.
113+
114+
The Zoekt indexer and searchers are a separate indexed search fleet. The
115+
`zoekt-indexer` Deployment builds index generations and publishes them through
116+
object storage, and the `zoekt-searcher` StatefulSet downloads and serves them.
117+
They run next to the `indexed-search` StatefulSet, with different workload,
118+
Service, and PVC names.
119+
120+
- `zoektIndexer.enabled` and `zoektSearcher.enabled` render the two services.
121+
- `indexedSearch.enabled` renders the `indexed-search` StatefulSet and its
122+
Services, PodDisruptionBudget, and ServiceAccount. When it is `false`, the
123+
frontend gets empty `INDEXED_SEARCH_SERVERS` and `INDEXED_SEARCH_INDEXER`, so
124+
it stops looking for the removed StatefulSet, unless `frontend.env` sets them.
125+
Kubernetes keeps a StatefulSet's PVCs after the StatefulSet is deleted, so
126+
delete the `data-indexed-search-*` PVCs to free their disks.
127+
128+
The chart does not configure the Zoekt indexer itself. It stays off until
129+
`SRC_ZOEKT_INDEXER_ENABLED` is set, along with settings such as
130+
`SRC_ZOEKT_SEARCHER_ROUTING` and `SRC_ZOEKT_WARM_REPLICAS`, identically in the
131+
`env` of `frontend`, `worker`, `searcher`, `zoektSearcher`, and `zoektIndexer`.
132+
109133
## Configuration Options
110134

111135
Reference the below chart for all available configuration parameters.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{{/*
2+
Render the image reference for a Zoekt indexer or searcher image.
3+
Usage: include "sourcegraph.zoekt.image" (list . .Values.zoektSearcher.image)
4+
The tag defaults to the chart appVersion when the image sets no defaultTag.
5+
*/}}
6+
{{- define "sourcegraph.zoekt.image" -}}
7+
{{- $top := index . 0 -}}
8+
{{- $image := index . 1 -}}
9+
{{- $repository := default $top.Values.sourcegraph.image.repository $image.repository -}}
10+
{{- $defaultTag := tpl (toString (default "{{ .Chart.AppVersion }}" $image.defaultTag)) $top -}}
11+
{{- if $top.Values.sourcegraph.image.useGlobalTagAsDefault }}{{ $defaultTag = (tpl $top.Values.sourcegraph.image.defaultTag $top) }}{{ end -}}
12+
{{- $repository }}/{{ $image.name }}:{{ default $defaultTag $image.tag }}
13+
{{- end }}
14+
15+
{{/*
16+
Render empty INDEXED_SEARCH_SERVERS and INDEXED_SEARCH_INDEXER for the frontend when the
17+
indexed-search StatefulSet is not rendered. Without them the frontend falls back to discovering
18+
the indexed-search StatefulSet, which no longer exists. Settings in frontend.env take precedence.
19+
*/}}
20+
{{- define "sourcegraph.indexedSearch.disabledEnv" -}}
21+
{{- if not .Values.indexedSearch.enabled -}}
22+
{{- range $name := list "INDEXED_SEARCH_SERVERS" "INDEXED_SEARCH_INDEXER" }}
23+
{{- if not (hasKey $.Values.frontend.env $name) }}
24+
- name: {{ $name }}
25+
value: ""
26+
{{- end }}
27+
{{- end }}
28+
{{- end -}}
29+
{{- end }}

‎charts/sourcegraph/templates/frontend/sourcegraph-frontend.Deployment.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ spec:
102102
{{- end }}
103103
{{- include "sourcegraph.redisConnection" .| nindent 8 }}
104104
{{- include "sourcegraph.openTelemetryEnv" . | nindent 8 }}
105+
{{- with include "sourcegraph.indexedSearch.disabledEnv" . }}{{ . | nindent 8 }}{{- end }}
105106
terminationMessagePolicy: FallbackToLogsOnError
106107
livenessProbe:
107108
httpGet:

‎charts/sourcegraph/templates/indexed-search/indexed-search.IndexerService.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Values.indexedSearch.enabled -}}
12
apiVersion: v1
23
kind: Service
34
metadata:
@@ -27,3 +28,4 @@ spec:
2728
{{- include "sourcegraph.selectorLabels" (list . .Values.indexedSearch) | nindent 4 }}
2829
app: indexed-search
2930
type: {{ .Values.indexedSearch.serviceType | default "ClusterIP" }}
31+
{{- end }}

‎charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.indexedSearch.podDisruptionBudget }}
1+
{{- if and .Values.indexedSearch.enabled .Values.indexedSearch.podDisruptionBudget }}
22
apiVersion: policy/v1
33
kind: PodDisruptionBudget
44
metadata:

‎charts/sourcegraph/templates/indexed-search/indexed-search.Service.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Values.indexedSearch.enabled -}}
12
apiVersion: v1
23
kind: Service
34
metadata:
@@ -30,3 +31,4 @@ spec:
3031
{{- include "sourcegraph.selectorLabels" (list . .Values.indexedSearch) | nindent 4 }}
3132
app: indexed-search
3233
type: {{ .Values.indexedSearch.serviceType | default "ClusterIP" }}
34+
{{- end }}

‎charts/sourcegraph/templates/indexed-search/indexed-search.ServiceAccount.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.indexedSearch.serviceAccount.create -}}
1+
{{- if and .Values.indexedSearch.enabled .Values.indexedSearch.serviceAccount.create -}}
22
apiVersion: v1
33
kind: ServiceAccount
44
metadata:

‎charts/sourcegraph/templates/indexed-search/indexed-search.StatefulSet.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Values.indexedSearch.enabled -}}
12
apiVersion: apps/v1
23
kind: StatefulSet
34
metadata:
@@ -171,3 +172,4 @@ spec:
171172
requests:
172173
storage: {{ .Values.indexedSearch.storageSize }}
173174
storageClassName: {{ .Values.storageClass.name }}
175+
{{- end }}

0 commit comments

Comments
 (0)