Skip to content

Commit e167670

Browse files
sourcegraph: add labels to PVCs, ServiceAccounts, and RBAC objects
Render sourcegraph.labels on the standalone PersistentVolumeClaims, every ServiceAccount, and the prometheus RBAC objects, and add per-component storageLabels and serviceAccount.labels values, so a release that takes over objects created outside the chart can keep the labels they already have. Also fix the jaeger ServiceAccount, which read its name and annotations from a tracing value that does not exist and failed to render. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1902b-ece9-725c-863d-3e2bba35ee1d
1 parent 6315f79 commit e167670

47 files changed

Lines changed: 682 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎charts/sourcegraph/CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Use `**BREAKING**:` to denote a breaking change
99
## Unreleased
1010

1111
- 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.
12+
- Added `storageLabels` on `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, and `redisStore` to label each component's PersistentVolumeClaim, and `<serviceName>.serviceAccount.labels` to label a component's ServiceAccount and, for `frontend` and `prometheus`, its Role, RoleBinding, ClusterRole, and ClusterRoleBinding. Also added `storageLabels` on `preciseCodeIntel` and `syntacticCodeIntel`, to label the per-pod `/tmp` scratch PersistentVolumeClaim when `storageType` is `pvc`; they default to empty, so no pod restarts. `sourcegraph.labels` and the chart's standard labels (`helm.sh/chart`, `app.kubernetes.io/name`, `app.kubernetes.io/instance`, `app.kubernetes.io/version`, `app.kubernetes.io/managed-by`) are now also rendered on these PersistentVolumeClaims, on every ServiceAccount, and on the `prometheus` RBAC objects, as they already are on every workload and on the `frontend` Role and RoleBinding, so existing releases gain these labels on upgrade. Labels on these objects can be changed in place, so nothing is recreated or restarted. See [Adopting existing workloads](README.md#adopting-existing-workloads).
13+
- Fixed the `jaeger` ServiceAccount failing to render with `jaeger.serviceAccount.create: true`. Its name and annotations were read from a `tracing` value that does not exist, and are now read from `jaeger.serviceAccount`, as the `jaeger` Deployment's `serviceAccountName` already was.
1214
- 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).
1315
- 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.
1416
- Added `openTelemetry.gateway.command` to replace the `otel-collector` container's command, e.g. with a shell wrapper that exports an exporter API key read from a mounted file

‎charts/sourcegraph/README.md‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,59 @@ Set these values on the first install and never change them on an installed
101101
release: Kubernetes rejects the upgrade. Before installing, compare the
102102
`helm template` output with `kubectl get -o yaml` for each workload.
103103

104+
Labels on other objects can be changed, so they never block an upgrade, but
105+
Helm only manages the labels the chart renders. To render the labels that the
106+
existing PersistentVolumeClaims, ServiceAccounts, and RBAC objects have:
107+
108+
- `sourcegraph.labels` adds labels to all of them, on every component, except
109+
the PersistentVolumeClaims that Kubernetes creates from a template. See
110+
[PersistentVolumeClaim labels](#persistentvolumeclaim-labels).
111+
- `<serviceName>.storageLabels` adds labels to the PersistentVolumeClaim of
112+
`blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`,
113+
`redisCache`, or `redisStore`.
114+
- `<serviceName>.serviceAccount.labels` adds labels to one component's
115+
ServiceAccount, and to the Role, RoleBinding, ClusterRole, and
116+
ClusterRoleBinding of `frontend` and `prometheus`.
117+
118+
```yaml
119+
sourcegraph:
120+
labels:
121+
example.com/project: sourcegraph
122+
blobstore:
123+
storageLabels:
124+
example.com/service: blobstore
125+
frontend:
126+
serviceAccount:
127+
labels:
128+
example.com/service: frontend
129+
```
130+
104131
Helm only takes over an existing object that has the
105132
`app.kubernetes.io/managed-by: Helm` label and the `meta.helm.sh/release-name`
106133
and `meta.helm.sh/release-namespace` annotations, or when installing with
107134
`--take-ownership` (Helm 3.17 or later).
108135

136+
### PersistentVolumeClaim labels
137+
138+
The values that label a PersistentVolumeClaim depend on what creates it:
139+
140+
| Created by | Components | `<serviceName>.storageLabels` | `sourcegraph.labels` and the chart's standard labels |
141+
| --- | --- | --- | --- |
142+
| The chart, as its own object | `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, `redisStore` | Yes | Yes |
143+
| Kubernetes, from a StatefulSet's volume claim template | `gitserver`, `grafana`, `indexedSearch`, `searcher` | Yes, at install only | No |
144+
| Kubernetes, from a pod's ephemeral volume, when `storageType` is `pvc` | `preciseCodeIntel`, `syntacticCodeIntel` | Yes; changing them restarts the pods | No |
145+
146+
A StatefulSet's volume claim templates get neither `sourcegraph.labels` nor the
147+
standard labels on purpose. Kubernetes rejects any change to them, so a chart
148+
version that added these labels would fail the upgrade of existing releases,
149+
and `helm.sh/chart` changes with every chart version.
150+
151+
Kubernetes copies a template's labels to a PersistentVolumeClaim only when it
152+
creates the claim, and never updates a claim that exists. Helm does not manage
153+
these claims either. Label an existing StatefulSet claim with
154+
`kubectl label pvc`. An ephemeral volume's claim is deleted and created again
155+
with its pod, so it always has the labels the chart renders.
156+
109157
## Configuration Options
110158

111159
Reference the below chart for all available configuration parameters.
@@ -129,6 +177,7 @@ In addition to the documented values, all services also support the following va
129177
- `<serviceName>.extraSelectorLabels` - add labels to the service's workload selector, pod labels, and Service and PodDisruptionBudget selectors. See [Adopting existing workloads](#adopting-existing-workloads)
130178
- `<serviceName>.serivceAccount.create` - create service account for service
131179
- `<serviceName>.serviceAccount.annotations` - Annotations for the service-specific service account
180+
- `<serviceName>.serviceAccount.labels` - Labels for the service-specific service account, and for the Role, RoleBinding, ClusterRole, and ClusterRoleBinding of `frontend` and `prometheus`, in addition to `sourcegraph.labels`
132181
- `<serviceName>.image.repository` - override the global `sourcegraph.image.repository` (registry or prefix) for this service. Defaults to `sourcegraph.image.repository` when unset.
133182

134183
| Key | Type | Default | Description |
@@ -146,6 +195,7 @@ In addition to the documented values, all services also support the following va
146195
| blobstore.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `blobstore` |
147196
| blobstore.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
148197
| blobstore.storageAnnotations | object | `{}` | Optional annotations to add to the `blobstore` PVC |
198+
| blobstore.storageLabels | object | `{}` | Optional labels to add to the `blobstore` PVC, in addition to `sourcegraph.labels` |
149199
| blobstore.storageSize | string | `"100Gi"` | PVC Storage Request for `blobstore` data volume |
150200
| blobstore.storageSubPath | string | `""` | Optional subPath for the `blobstore` primary data volume mount |
151201
| cadvisor.containerSecurityContext | object | `{"privileged":true}` | Security context for the `cadvisor` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) |
@@ -178,6 +228,7 @@ In addition to the documented values, all services also support the following va
178228
| codeInsightsDB.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `codeinsights-db` |
179229
| codeInsightsDB.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
180230
| codeInsightsDB.storageAnnotations | object | `{}` | Optional annotations to add to the `codeinsights-db` PVC |
231+
| codeInsightsDB.storageLabels | object | `{}` | Optional labels to add to the `codeinsights-db` PVC, in addition to `sourcegraph.labels` |
181232
| codeInsightsDB.storageSize | string | `"200Gi"` | PVC Storage Request for `codeinsights-db` data volume |
182233
| codeInsightsDB.storageSubPath | string | `""` | Optional subPath for the `codeinsights-db` primary data volume mount |
183234
| codeIntelDB.additionalConfig | string | `""` | Additional PostgreSQL configuration. This will override or extend our default configuration. Notes: This is expecting a multiline string. Learn more from our [recommended PostgreSQL configuration](https://docs.sourcegraph.com/admin/config/postgres-conf) and [PostgreSQL documentation](https://www.postgresql.org/docs/12/config-setting.html) |
@@ -200,6 +251,7 @@ In addition to the documented values, all services also support the following va
200251
| codeIntelDB.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `codeintel-db` |
201252
| codeIntelDB.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
202253
| codeIntelDB.storageAnnotations | object | `{}` | Optional annotations to add to the `codeintel-db` PVC |
254+
| codeIntelDB.storageLabels | object | `{}` | Optional labels to add to the `codeintel-db` PVC, in addition to `sourcegraph.labels` |
203255
| codeIntelDB.storageSize | string | `"200Gi"` | PVC Storage Request for `codeintel-db` data volume |
204256
| codeIntelDB.storageSubPath | string | `""` | Optional subPath for the `codeintel-db` primary data volume mount |
205257
| extraResources | list | `[]` | Additional resources to include in the rendered manifest. Templates are supported. |
@@ -374,6 +426,7 @@ In addition to the documented values, all services also support the following va
374426
| pgsql.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `pgsql` |
375427
| pgsql.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
376428
| pgsql.storageAnnotations | object | `{}` | Optional annotations to add to the `pgsql` PVC |
429+
| pgsql.storageLabels | object | `{}` | Optional labels to add to the `pgsql` PVC, in addition to `sourcegraph.labels` |
377430
| pgsql.storageSize | string | `"200Gi"` | PVC Storage Request for `pgsql` data volume |
378431
| pgsql.storageSubPath | string | `""` | Optional subPath for the `pgsql` primary data volume mount |
379432
| postgresExporter.image.defaultTag | string | `<appVersion>@sha256:<digest>`, pinned by each release | Docker image tag for the `pgsql-exporter` image |
@@ -391,6 +444,7 @@ In addition to the documented values, all services also support the following va
391444
| preciseCodeIntel.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `precise-code-intel-worker` |
392445
| preciseCodeIntel.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
393446
| preciseCodeIntel.storageClassName | string | `""` | StorageClass for the `/tmp` scratch PVC when storageType is `pvc`. Empty uses the cluster default class. The claim is per-pod and discarded with the pod, so this class must use `reclaimPolicy: Delete`; `storageClass` is `Retain` for stateful data and is not used here. |
447+
| preciseCodeIntel.storageLabels | object | `{}` | Labels to add to the `/tmp` scratch PVC when storageType is `pvc`. Changing them restarts the pods. See [PersistentVolumeClaim labels](#persistentvolumeclaim-labels) |
394448
| preciseCodeIntel.storageSize | string | `""` | Size of the `/tmp` scratch volume. Required when storageType is `pvc`. When storageType is `emptyDir` this sets `sizeLimit` (optional, leave empty for unlimited). |
395449
| preciseCodeIntel.storageType | string | `"emptyDir"` | Backing store for the `/tmp` scratch volume, used for large SCIP upload processing. One of: emptyDir, pvc. emptyDir: node ephemeral storage, i.e. the node boot disk. pvc: per-pod PVC, discarded with the pod. The pod `fsGroup` defaults to the container `runAsGroup` so the non-root worker can write to the volume; set `podSecurityContext.fsGroup` to override it. |
396450
| priorityClasses | list | `[]` | Additional priorityClasses minimize re-scheduling downtime for StatefulSets. Each StatefulSets might use different priority class. learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#priorityclass) Sample class definition: - name: gitserver-class value: 100 preemptionPolicy: Never description: "gitserver priority class" |
@@ -407,6 +461,7 @@ In addition to the documented values, all services also support the following va
407461
| prometheus.serviceAccount.create | bool | `true` | Enable creation of ServiceAccount |
408462
| prometheus.serviceAccount.name | string | `"prometheus"` | Name of the ServiceAccount to be created or an existing ServiceAccount |
409463
| prometheus.storageAnnotations | object | `{}` | Optional annotations to add to the `prometheus` PVC |
464+
| prometheus.storageLabels | object | `{}` | Optional labels to add to the `prometheus` PVC, in addition to `sourcegraph.labels` |
410465
| prometheus.storageSize | string | `"200Gi"` | PVC Storage Request for `prometheus` data volume |
411466
| prometheus.storageSubPath | string | `""` | Optional subPath for the `prometheus` primary data volume mount |
412467
| redisCache.config.additionalConfig | string | `""` | Additional raw redis directives appended to the vendored `redis-cache` config. Notes: This is expecting a multiline string. It renders into a ConfigMap in plaintext, so do not put secrets such as `requirepass` here or in `existingConfig` (also a ConfigMap). For secrets, set `config.enabled: false` and mount a Secret using `extraVolumeMounts`. |
@@ -428,6 +483,7 @@ In addition to the documented values, all services also support the following va
428483
| redisCache.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `redis-cache` |
429484
| redisCache.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
430485
| redisCache.storageAnnotations | object | `{}` | Optional annotations to add to the `redis-cache` PVC |
486+
| redisCache.storageLabels | object | `{}` | Optional labels to add to the `redis-cache` PVC, in addition to `sourcegraph.labels` |
431487
| redisCache.storageSize | string | `"100Gi"` | PVC Storage Request for `redis-cache` data volume |
432488
| redisCache.storageSubPath | string | `""` | Optional subPath for the `redis-cache` primary data volume mount |
433489
| redisExporter.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"readOnlyRootFilesystem":true,"runAsGroup":1000,"runAsUser":999}` | Security context for the `redis-exporter` sidecar container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) |
@@ -453,6 +509,7 @@ In addition to the documented values, all services also support the following va
453509
| redisStore.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `redis-store` |
454510
| redisStore.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
455511
| redisStore.storageAnnotations | object | `{}` | Optional annotations to add to the `redis-store` PVC |
512+
| redisStore.storageLabels | object | `{}` | Optional labels to add to the `redis-store` PVC, in addition to `sourcegraph.labels` |
456513
| redisStore.storageSize | string | `"100Gi"` | PVC Storage Request for `redis-store` data volume |
457514
| redisStore.storageSubPath | string | `""` | Optional subPath for the `redis-store` primary data volume mount |
458515
| searcher.autoCacheSize | bool | `false` | When enabled, omit the `SEARCHER_CACHE_SIZE_MB` and `SYMBOLS_CACHE_SIZE_MB` env vars so `searcher` auto-sizes its cache to ~45% of the live cache volume. This tracks PVC expansion automatically, whereas the hardcoded env vars are frozen to the initial `storageSize` and do not follow later disk growth. |
@@ -512,6 +569,7 @@ In addition to the documented values, all services also support the following va
512569
| syntacticCodeIntel.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `syntactic-code-intel-worker` |
513570
| syntacticCodeIntel.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
514571
| syntacticCodeIntel.storageClassName | string | `""` | StorageClass for the `/tmp` scratch PVC when storageType is `pvc`. Empty uses the cluster default class. The claim is per-pod and discarded with the pod, so this class must use `reclaimPolicy: Delete`; `storageClass` is `Retain` for stateful data and is not used here. |
572+
| syntacticCodeIntel.storageLabels | object | `{}` | Labels to add to the `/tmp` scratch PVC when storageType is `pvc`. Changing them restarts the pods. See [PersistentVolumeClaim labels](#persistentvolumeclaim-labels) |
515573
| syntacticCodeIntel.storageSize | string | `""` | Size of the `/tmp` scratch volume. Required when storageType is `pvc`. When storageType is `emptyDir` this sets `sizeLimit` (optional, leave empty for unlimited). |
516574
| syntacticCodeIntel.storageType | string | `"emptyDir"` | Backing store for the `/tmp` scratch volume, used for indexing. One of: emptyDir, pvc. emptyDir: node ephemeral storage, i.e. the node boot disk. pvc: per-pod PVC, discarded with the pod. The pod `fsGroup` defaults to the container `runAsGroup` so the non-root worker can write to the volume; set `podSecurityContext.fsGroup` to override it. |
517575
| syntectServer.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"readOnlyRootFilesystem":true,"runAsGroup":101,"runAsUser":100}` | Security context for the `syntect-server` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) |

0 commit comments

Comments
 (0)