Skip to content

Commit 3d258bf

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. Amp-Thread-ID: https://ampcode.com/threads/T-c7c725c9-ed68-48e2-9f2d-0b8c31e76050 Co-authored-by: Amp <amp@ampcode.com>
1 parent 7c41209 commit 3d258bf

43 files changed

Lines changed: 543 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
@@ -8,6 +8,8 @@ Use `**BREAKING**:` to denote a breaking change
88

99
## Unreleased
1010

11+
- 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. `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).
12+
- 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.
1113
- 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).
1214
- 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.
1315
- 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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,31 @@ 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.
109+
- `<serviceName>.storageLabels` adds labels to the PersistentVolumeClaim of
110+
`blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`,
111+
`redisCache`, or `redisStore`.
112+
- `<serviceName>.serviceAccount.labels` adds labels to one component's
113+
ServiceAccount, and to the Role, RoleBinding, ClusterRole, and
114+
ClusterRoleBinding of `frontend` and `prometheus`.
115+
116+
```yaml
117+
sourcegraph:
118+
labels:
119+
example.com/project: sourcegraph
120+
blobstore:
121+
storageLabels:
122+
example.com/service: blobstore
123+
frontend:
124+
serviceAccount:
125+
labels:
126+
example.com/service: frontend
127+
```
128+
104129
Helm only takes over an existing object that has the
105130
`app.kubernetes.io/managed-by: Helm` label and the `meta.helm.sh/release-name`
106131
and `meta.helm.sh/release-namespace` annotations, or when installing with
@@ -129,6 +154,7 @@ In addition to the documented values, all services also support the following va
129154
- `<serviceName>.extraSelectorLabels` - add labels to the service's workload selector, pod labels, and Service and PodDisruptionBudget selectors. See [Adopting existing workloads](#adopting-existing-workloads)
130155
- `<serviceName>.serivceAccount.create` - create service account for service
131156
- `<serviceName>.serviceAccount.annotations` - Annotations for the service-specific service account
157+
- `<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`
132158
- `<serviceName>.image.repository` - override the global `sourcegraph.image.repository` (registry or prefix) for this service. Defaults to `sourcegraph.image.repository` when unset.
133159

134160
| Key | Type | Default | Description |
@@ -148,6 +174,7 @@ In addition to the documented values, all services also support the following va
148174
| blobstore.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `blobstore` |
149175
| blobstore.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
150176
| blobstore.storageAnnotations | object | `{}` | Optional annotations to add to the `blobstore` PVC |
177+
| blobstore.storageLabels | object | `{}` | Optional labels to add to the `blobstore` PVC, in addition to `sourcegraph.labels` |
151178
| blobstore.storageSize | string | `"100Gi"` | PVC Storage Request for `blobstore` data volume |
152179
| blobstore.storageSubPath | string | `""` | Optional subPath for the `blobstore` primary data volume mount |
153180
| 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) |
@@ -180,6 +207,7 @@ In addition to the documented values, all services also support the following va
180207
| codeInsightsDB.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `codeinsights-db` |
181208
| codeInsightsDB.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
182209
| codeInsightsDB.storageAnnotations | object | `{}` | Optional annotations to add to the `codeinsights-db` PVC |
210+
| codeInsightsDB.storageLabels | object | `{}` | Optional labels to add to the `codeinsights-db` PVC, in addition to `sourcegraph.labels` |
183211
| codeInsightsDB.storageSize | string | `"200Gi"` | PVC Storage Request for `codeinsights-db` data volume |
184212
| codeInsightsDB.storageSubPath | string | `""` | Optional subPath for the `codeinsights-db` primary data volume mount |
185213
| 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) |
@@ -202,6 +230,7 @@ In addition to the documented values, all services also support the following va
202230
| codeIntelDB.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `codeintel-db` |
203231
| codeIntelDB.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
204232
| codeIntelDB.storageAnnotations | object | `{}` | Optional annotations to add to the `codeintel-db` PVC |
233+
| codeIntelDB.storageLabels | object | `{}` | Optional labels to add to the `codeintel-db` PVC, in addition to `sourcegraph.labels` |
205234
| codeIntelDB.storageSize | string | `"200Gi"` | PVC Storage Request for `codeintel-db` data volume |
206235
| codeIntelDB.storageSubPath | string | `""` | Optional subPath for the `codeintel-db` primary data volume mount |
207236
| extraResources | list | `[]` | Additional resources to include in the rendered manifest. Templates are supported. |
@@ -376,6 +405,7 @@ In addition to the documented values, all services also support the following va
376405
| pgsql.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `pgsql` |
377406
| pgsql.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
378407
| pgsql.storageAnnotations | object | `{}` | Optional annotations to add to the `pgsql` PVC |
408+
| pgsql.storageLabels | object | `{}` | Optional labels to add to the `pgsql` PVC, in addition to `sourcegraph.labels` |
379409
| pgsql.storageSize | string | `"200Gi"` | PVC Storage Request for `pgsql` data volume |
380410
| pgsql.storageSubPath | string | `""` | Optional subPath for the `pgsql` primary data volume mount |
381411
| postgresExporter.image.defaultTag | string | `<appVersion>@sha256:<digest>`, pinned by each release | Docker image tag for the `pgsql-exporter` image |
@@ -409,6 +439,7 @@ In addition to the documented values, all services also support the following va
409439
| prometheus.serviceAccount.create | bool | `true` | Enable creation of ServiceAccount |
410440
| prometheus.serviceAccount.name | string | `"prometheus"` | Name of the ServiceAccount to be created or an existing ServiceAccount |
411441
| prometheus.storageAnnotations | object | `{}` | Optional annotations to add to the `prometheus` PVC |
442+
| prometheus.storageLabels | object | `{}` | Optional labels to add to the `prometheus` PVC, in addition to `sourcegraph.labels` |
412443
| prometheus.storageSize | string | `"200Gi"` | PVC Storage Request for `prometheus` data volume |
413444
| prometheus.storageSubPath | string | `""` | Optional subPath for the `prometheus` primary data volume mount |
414445
| 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`. |
@@ -430,6 +461,7 @@ In addition to the documented values, all services also support the following va
430461
| redisCache.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `redis-cache` |
431462
| redisCache.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
432463
| redisCache.storageAnnotations | object | `{}` | Optional annotations to add to the `redis-cache` PVC |
464+
| redisCache.storageLabels | object | `{}` | Optional labels to add to the `redis-cache` PVC, in addition to `sourcegraph.labels` |
433465
| redisCache.storageSize | string | `"100Gi"` | PVC Storage Request for `redis-cache` data volume |
434466
| redisCache.storageSubPath | string | `""` | Optional subPath for the `redis-cache` primary data volume mount |
435467
| 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) |
@@ -455,6 +487,7 @@ In addition to the documented values, all services also support the following va
455487
| redisStore.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `redis-store` |
456488
| redisStore.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
457489
| redisStore.storageAnnotations | object | `{}` | Optional annotations to add to the `redis-store` PVC |
490+
| redisStore.storageLabels | object | `{}` | Optional labels to add to the `redis-store` PVC, in addition to `sourcegraph.labels` |
458491
| redisStore.storageSize | string | `"100Gi"` | PVC Storage Request for `redis-store` data volume |
459492
| redisStore.storageSubPath | string | `""` | Optional subPath for the `redis-store` primary data volume mount |
460493
| 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. |

‎charts/sourcegraph/README.md.gotmpl‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,31 @@ 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.
109+
- `<serviceName>.storageLabels` adds labels to the PersistentVolumeClaim of
110+
`blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`,
111+
`redisCache`, or `redisStore`.
112+
- `<serviceName>.serviceAccount.labels` adds labels to one component's
113+
ServiceAccount, and to the Role, RoleBinding, ClusterRole, and
114+
ClusterRoleBinding of `frontend` and `prometheus`.
115+
116+
```yaml
117+
sourcegraph:
118+
labels:
119+
example.com/project: sourcegraph
120+
blobstore:
121+
storageLabels:
122+
example.com/service: blobstore
123+
frontend:
124+
serviceAccount:
125+
labels:
126+
example.com/service: frontend
127+
```
128+
104129
Helm only takes over an existing object that has the
105130
`app.kubernetes.io/managed-by: Helm` label and the `meta.helm.sh/release-name`
106131
and `meta.helm.sh/release-namespace` annotations, or when installing with
@@ -129,6 +154,7 @@ In addition to the documented values, all services also support the following va
129154
- `<serviceName>.extraSelectorLabels` - add labels to the service's workload selector, pod labels, and Service and PodDisruptionBudget selectors. See [Adopting existing workloads](#adopting-existing-workloads)
130155
- `<serviceName>.serivceAccount.create` - create service account for service
131156
- `<serviceName>.serviceAccount.annotations` - Annotations for the service-specific service account
157+
- `<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`
132158
- `<serviceName>.image.repository` - override the global `sourcegraph.image.repository` (registry or prefix) for this service. Defaults to `sourcegraph.image.repository` when unset.
133159

134160
{{ template "chart.valuesTable" . }}

‎charts/sourcegraph/templates/_helpers.tpl‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ annotations:
126126
{{- end }}
127127
{{- end }}
128128

129+
{{/*
130+
The labels set in <serviceName>.serviceAccount.labels, rendered on the
131+
component's ServiceAccount and on its Role, RoleBinding, ClusterRole, and
132+
ClusterRoleBinding, if it has any. Empty by default.
133+
134+
Takes the same arguments as "sourcegraph.serviceAccountName".
135+
*/}}
136+
{{- define "sourcegraph.serviceAccountLabels" -}}
137+
{{- $top := index . 0 }}
138+
{{- if hasKey $top "Values" -}}
139+
{{- $top = index $top "Values" -}}
140+
{{- end -}}
141+
{{- $service := index . 1 }}
142+
{{- with (index $top $service "serviceAccount" "labels") }}
143+
{{- toYaml . }}
144+
{{- end }}
145+
{{- end }}
146+
129147
{{/*
130148
Create the docker image reference and allow it to be overridden on a per-service basis
131149
Default tags are toggled between a global and service-specific setting by the

‎charts/sourcegraph/templates/blobstore/blobstore.PersistentVolumeClaim.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ apiVersion: v1
33
kind: PersistentVolumeClaim
44
metadata:
55
labels:
6+
{{- include "sourcegraph.labels" . | nindent 4 }}
7+
{{- with .Values.blobstore.storageLabels }}
8+
{{- toYaml . | nindent 4 }}
9+
{{- end }}
610
deploy: sourcegraph
711
app.kubernetes.io/component: blobstore
812
{{- if .Values.blobstore.storageAnnotations }}

‎charts/sourcegraph/templates/blobstore/blobstore.ServiceAccount.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ apiVersion: v1
33
kind: ServiceAccount
44
metadata:
55
labels:
6+
{{- include "sourcegraph.labels" . | nindent 4 }}
7+
{{- with include "sourcegraph.serviceAccountLabels" (list . "blobstore") }}
8+
{{- . | nindent 4 }}
9+
{{- end }}
610
category: rbac
711
deploy: sourcegraph
812
app.kubernetes.io/component: blobstore

‎charts/sourcegraph/templates/cadvisor/cadvisor.ServiceAccount.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ apiVersion: v1
33
kind: ServiceAccount
44
metadata:
55
labels:
6+
{{- include "sourcegraph.labels" . | nindent 4 }}
7+
{{- with include "sourcegraph.serviceAccountLabels" (list . "cadvisor") }}
8+
{{- . | nindent 4 }}
9+
{{- end }}
610
app: cadvisor
711
category: rbac
812
deploy: sourcegraph

‎charts/sourcegraph/templates/codeinsights-db/codeinsights-db.PersistentVolumeClaim.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ apiVersion: v1
33
kind: PersistentVolumeClaim
44
metadata:
55
labels:
6+
{{- include "sourcegraph.labels" . | nindent 4 }}
7+
{{- with .Values.codeInsightsDB.storageLabels }}
8+
{{- toYaml . | nindent 4 }}
9+
{{- end }}
610
app.kubernetes.io/component: codeinsights-db
711
deploy: sourcegraph
812
{{- if .Values.codeInsightsDB.storageAnnotations }}

‎charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ServiceAccount.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ apiVersion: v1
33
kind: ServiceAccount
44
metadata:
55
labels:
6+
{{- include "sourcegraph.labels" . | nindent 4 }}
7+
{{- with include "sourcegraph.serviceAccountLabels" (list . "codeInsightsDB") }}
8+
{{- . | nindent 4 }}
9+
{{- end }}
610
category: rbac
711
deploy: sourcegraph
812
app.kubernetes.io/component: codeinsights-db

‎charts/sourcegraph/templates/codeintel-db/codeintel-db.PersistentVolumeClaim.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ apiVersion: v1
33
kind: PersistentVolumeClaim
44
metadata:
55
labels:
6+
{{- include "sourcegraph.labels" . | nindent 4 }}
7+
{{- with .Values.codeIntelDB.storageLabels }}
8+
{{- toYaml . | nindent 4 }}
9+
{{- end }}
610
app.kubernetes.io/component: codeintel-db
711
deploy: sourcegraph
812
{{- if .Values.codeIntelDB.storageAnnotations }}

0 commit comments

Comments
 (0)