From 71c148a03871463a78a89cee14907ad71ce96e74 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 11 Nov 2026 18:59:45 +0000 Subject: [PATCH 01/18] Render sourcegraph.labels on every object in all four charts Services, ConfigMaps, Secrets, the Ingress, PodDisruptionBudgets, PriorityClasses, and extraResources of the sourcegraph chart did not render sourcegraph.labels. Neither did any object of the sourcegraph-executor-k8s chart, nor the docker-config ConfigMap and private-docker-registry Service of the sourcegraph-executor-dind chart. Prometheus copies Service labels to the metrics it scrapes, so its bundled configuration now drops the chart's standard labels: helm.sh/chart and app.kubernetes.io/version change on every upgrade. Each chart gets a test that renders every template and checks the labels, so a template added later is covered too. Amp-Thread-ID: https://ampcode.com/threads/T-c7c725c9-ed68-48e2-9f2d-0b8c31e76050 Co-authored-by: Amp --- charts/sourcegraph-executor/CHANGELOG.md | 2 + .../executor/docker-daemon.ConfigMap.yaml | 1 + .../private-docker-registry.Service.yaml | 1 + .../dind/tests/labels_test.yaml | 22 ++ .../k8s/templates/executor.ConfigMap.yaml | 1 + .../k8s/templates/executor.Deployment.yaml | 1 + .../k8s/templates/executor.Role.yaml | 1 + .../k8s/templates/executor.RoleBinding.yaml | 1 + .../k8s/templates/executor.Secret.yaml | 2 + .../k8s/templates/executor.Service.yaml | 1 + .../templates/executor.ServiceAccount.yaml | 1 + .../k8s/tests/labels_test.yaml | 21 ++ .../tests/labels_test.yaml | 18 ++ charts/sourcegraph/CHANGELOG.md | 1 + charts/sourcegraph/README.md | 13 +- charts/sourcegraph/README.md.gotmpl | 9 +- .../prometheus-override-k3s.ConfigMap.yaml | 8 + .../blobstore/blobstore.Service.yaml | 1 + .../codeinsights-db.ConfigMap.yaml | 1 + .../codeinsights-db.Secret.yaml | 1 + .../codeinsights-db.Service.yaml | 1 + .../codeintel-db/codeintel-db.ConfigMap.yaml | 1 + .../codeintel-db/codeintel-db.Secret.yaml | 1 + .../codeintel-db/codeintel-db.Service.yaml | 1 + .../sourcegraph/templates/extraResources.yaml | 15 +- ...sourcegraph-frontend-internal.Service.yaml | 1 + .../sourcegraph-frontend.Ingress.yaml | 1 + ...rcegraph-frontend.PodDisruptionBudget.yaml | 2 + .../sourcegraph-frontend.Service.yaml | 1 + .../gitserver.PodDisruptionBudget.yaml | 2 + .../gitserver/gitserver.Service.yaml | 1 + .../templates/grafana/grafana.ConfigMap.yaml | 1 + .../templates/grafana/grafana.Service.yaml | 1 + .../grafana/grafana.pgsql.Secret.yaml | 1 + .../indexed-search.IndexerService.yaml | 1 + .../indexed-search.PodDisruptionBudget.yaml | 2 + .../indexed-search.Service.yaml | 1 + .../jaeger/jaeger-collector.Service.yaml | 2 +- .../jaeger/jaeger-query.Service.yaml | 2 +- .../node-exporter/node-exporter.Service.yaml | 1 + .../otel-collector/otel-agent.ConfigMap.yaml | 1 + .../otel-collector.ConfigMap.yaml | 1 + .../templates/pgsql/pgsql.ConfigMap.yaml | 1 + .../templates/pgsql/pgsql.Secret.yaml | 1 + .../templates/pgsql/pgsql.Service.yaml | 1 + .../worker.PodDisruptionBudget.yaml | 2 + .../precise-code-intel/worker.Service.yaml | 1 + .../sourcegraph/templates/priorityClass.yaml | 2 + .../prometheus/prometheus.ConfigMap.yaml | 9 + .../prometheus/prometheus.Service.yaml | 1 + .../redis-cache.PodDisruptionBudget.yaml | 2 + .../templates/redis/redis-cache.Secret.yaml | 1 + .../templates/redis/redis-cache.Service.yaml | 1 + .../redis-store.PodDisruptionBudget.yaml | 2 + .../templates/redis/redis-store.Secret.yaml | 1 + .../templates/redis/redis-store.Service.yaml | 1 + .../searcher.PodDisruptionBudget.yaml | 2 + .../templates/searcher/searcher.Service.yaml | 1 + .../worker.PodDisruptionBudget.yaml | 2 + .../syntactic-code-intel/worker.Service.yaml | 1 + .../syntect-server.PodDisruptionBudget.yaml | 2 + .../syntect-server.Service.yaml | 1 + .../worker/worker-executors.Service.yaml | 1 + .../worker/worker.PodDisruptionBudget.yaml | 2 + .../templates/worker/worker.Service.yaml | 1 + .../tests/allObjectLabels_test.yaml | 196 ++++++++++++++++++ charts/sourcegraph/values.yaml | 6 +- 67 files changed, 376 insertions(+), 13 deletions(-) create mode 100644 charts/sourcegraph-executor/dind/tests/labels_test.yaml create mode 100644 charts/sourcegraph-executor/k8s/tests/labels_test.yaml create mode 100644 charts/sourcegraph-migrator/tests/labels_test.yaml create mode 100644 charts/sourcegraph/tests/allObjectLabels_test.yaml diff --git a/charts/sourcegraph-executor/CHANGELOG.md b/charts/sourcegraph-executor/CHANGELOG.md index 5e2f4fb18..da22083bf 100644 --- a/charts/sourcegraph-executor/CHANGELOG.md +++ b/charts/sourcegraph-executor/CHANGELOG.md @@ -3,6 +3,8 @@ ## Unreleased +- `sourcegraph.labels` and the charts' standard labels (`helm.sh/chart`, `app.kubernetes.io/name`, `app.kubernetes.io/instance`, `app.kubernetes.io/version`, `app.kubernetes.io/managed-by`) are now rendered on every object the charts create. The `sourcegraph-executor-k8s` chart rendered them on none of its objects (ConfigMap, Deployment, Role, RoleBinding, Secret, Service, ServiceAccount), and the `sourcegraph-executor-dind` chart did not render them on the `docker-config` ConfigMap and the `private-docker-registry` Service. Existing releases gain these labels on upgrade. Labels on these objects can be changed in place, so nothing is recreated or restarted. + ## 8.0.0 * Added a `network-policy` example to the `sourcegraph-executor-k8s` and `sourcegraph-executor-dind` charts, with `CiliumNetworkPolicy` resources which limit Executor and job pods to the frontend API. diff --git a/charts/sourcegraph-executor/dind/templates/executor/docker-daemon.ConfigMap.yaml b/charts/sourcegraph-executor/dind/templates/executor/docker-daemon.ConfigMap.yaml index ecd96f99b..d91dbdcb3 100644 --- a/charts/sourcegraph-executor/dind/templates/executor/docker-daemon.ConfigMap.yaml +++ b/charts/sourcegraph-executor/dind/templates/executor/docker-daemon.ConfigMap.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: ConfigMap metadata: labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: executor deploy: sourcegraph app.kubernetes.io/component: executor diff --git a/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Service.yaml b/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Service.yaml index 356293ca8..b2227b484 100644 --- a/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Service.yaml +++ b/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Service.yaml @@ -7,6 +7,7 @@ metadata: {{- toYaml .Values.privateDockerRegistry.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: private-docker-registry deploy: sourcegraph app.kubernetes.io/component: private-docker-registry diff --git a/charts/sourcegraph-executor/dind/tests/labels_test.yaml b/charts/sourcegraph-executor/dind/tests/labels_test.yaml new file mode 100644 index 000000000..56c29a4ce --- /dev/null +++ b/charts/sourcegraph-executor/dind/tests/labels_test.yaml @@ -0,0 +1,22 @@ +suite: sourcegraph.labels on every object +# No `templates` list, so every template in the chart is rendered, including +# ones added later. The test fails with "no manifest found" for a template that +# renders nothing, so enable a new optional template here. +tests: + - it: should add sourcegraph.labels to every object the chart renders + set: + sourcegraph: + labels: + example.com/installation: production + example.com/project: sourcegraph + executor: + queueName: batches + privateDockerRegistry: + enabled: true + asserts: + - isSubset: + path: metadata.labels + content: + app.kubernetes.io/managed-by: Helm + example.com/installation: production + example.com/project: sourcegraph diff --git a/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml b/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml index 6e773607b..cfd074819 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml @@ -3,6 +3,7 @@ kind: ConfigMap metadata: name: {{ include "executor.name" . }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} {{- include "executor.labels" . | nindent 4 }} data: EXECUTOR_USE_FIRECRACKER: "false" diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml index 1cb35d2c4..9978038b0 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml @@ -6,6 +6,7 @@ metadata: description: Runs a sourcegraph executor kubectl.kubernetes.io/default-container: executor labels: + {{- include "sourcegraph.labels" . | nindent 4 }} {{- include "executor.labels" . | nindent 4 }} {{- if .Values.executor.labels }} {{- toYaml .Values.executor.labels | nindent 4 }} diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Role.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Role.yaml index 7a3d1ef4d..36107636e 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Role.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Role.yaml @@ -4,6 +4,7 @@ kind: Role metadata: name: sg-executor-role labels: + {{- include "sourcegraph.labels" . | nindent 4 }} category: rbac deploy: sourcegraph sourcegraph-resource-requires: cluster-admin diff --git a/charts/sourcegraph-executor/k8s/templates/executor.RoleBinding.yaml b/charts/sourcegraph-executor/k8s/templates/executor.RoleBinding.yaml index f13311c5f..df5814537 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.RoleBinding.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.RoleBinding.yaml @@ -4,6 +4,7 @@ kind: RoleBinding metadata: name: sg-executor-role-binding labels: + {{- include "sourcegraph.labels" . | nindent 4 }} category: rbac deploy: sourcegraph sourcegraph-resource-requires: cluster-admin diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Secret.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Secret.yaml index 669afae55..01fd6e810 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Secret.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Secret.yaml @@ -2,6 +2,8 @@ apiVersion: v1 kind: Secret metadata: + labels: + {{- include "sourcegraph.labels" . | nindent 4 }} name: {{ include "executor.name" . }} type: Opaque data: diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Service.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Service.yaml index 33d841b3b..ed865c0cb 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Service.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Service.yaml @@ -6,6 +6,7 @@ metadata: {{- toYaml .Values.executor.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} {{ include "executor.labels" . | indent 4 }} {{- if .Values.executor.serviceLabels }} {{- toYaml .Values.executor.serviceLabels | nindent 4 }} diff --git a/charts/sourcegraph-executor/k8s/templates/executor.ServiceAccount.yaml b/charts/sourcegraph-executor/k8s/templates/executor.ServiceAccount.yaml index 6a0f44627..1b8d16bd3 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.ServiceAccount.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.ServiceAccount.yaml @@ -4,6 +4,7 @@ kind: ServiceAccount metadata: name: sg-executor labels: + {{- include "sourcegraph.labels" . | nindent 4 }} category: rbac deploy: sourcegraph sourcegraph-resource-requires: cluster-admin diff --git a/charts/sourcegraph-executor/k8s/tests/labels_test.yaml b/charts/sourcegraph-executor/k8s/tests/labels_test.yaml new file mode 100644 index 000000000..c0140b3c3 --- /dev/null +++ b/charts/sourcegraph-executor/k8s/tests/labels_test.yaml @@ -0,0 +1,21 @@ +suite: sourcegraph.labels on every object +# No `templates` list, so every template in the chart is rendered, including +# ones added later. The test fails with "no manifest found" for a template that +# renders nothing, so enable a new optional template here. +tests: + - it: should add sourcegraph.labels to every object the chart renders + set: + sourcegraph: + labels: + example.com/installation: production + example.com/project: sourcegraph + executor: + queueName: batches + configureRbac: true + asserts: + - isSubset: + path: metadata.labels + content: + app.kubernetes.io/managed-by: Helm + example.com/installation: production + example.com/project: sourcegraph diff --git a/charts/sourcegraph-migrator/tests/labels_test.yaml b/charts/sourcegraph-migrator/tests/labels_test.yaml new file mode 100644 index 000000000..57f3df51e --- /dev/null +++ b/charts/sourcegraph-migrator/tests/labels_test.yaml @@ -0,0 +1,18 @@ +suite: sourcegraph.labels on every object +# No `templates` list, so every template in the chart is rendered, including +# ones added later. The test fails with "no manifest found" for a template that +# renders nothing, so enable a new optional template here. +tests: + - it: should add sourcegraph.labels to every object the chart renders + set: + sourcegraph: + labels: + example.com/installation: production + example.com/project: sourcegraph + asserts: + - isSubset: + path: metadata.labels + content: + app.kubernetes.io/managed-by: Helm + example.com/installation: production + example.com/project: sourcegraph diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index cb6d00a3f..2aa411b76 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -10,6 +10,7 @@ Use `**BREAKING**:` to denote a breaking change - Added `frontend.internalServiceAnnotations` and `frontend.internalServiceLabels` for the `sourcegraph-frontend-internal` Service. That Service no longer renders `frontend.serviceAnnotations` and `frontend.serviceLabels`, which now apply to the `sourcegraph-frontend` Service only, so load balancer annotations or a service mesh label set for the external Service no longer land on the internal one. If you relied on them on the internal Service, set the new values. - 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. +- `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 rendered on every object the chart creates: also on Services, ConfigMaps, Secrets, the Ingress, PodDisruptionBudgets, PriorityClasses, and `extraResources`, so existing releases gain these labels on upgrade. Labels that an `extraResources` entry or `serviceLabels` set take precedence. Labels on these objects can be changed in place, so nothing is recreated or restarted. Prometheus copies the labels of a Service to the metrics it scrapes from it, so labels set in `sourcegraph.labels` now appear on those metrics, as `sourcegraph.serviceLabels` and `.serviceLabels` already do. The bundled Prometheus configuration drops the chart's standard labels instead, because `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade; the `otel-collector` metrics, the only ones that had them, lose them. If you set `prometheus.existingConfig`, add the same `labeldrop` rule after each `__meta_kubernetes_service_label_(.+)` `labelmap` rule in your `prometheus.yml`, as in the [k3s example](examples/prometheus/prometheus-override-k3s.ConfigMap.yaml). - Added `storageLabels` on `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, and `redisStore` to label each component's PersistentVolumeClaim, and `.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). - 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. - Added `sourcegraph.selectorLabelsOverride`, `.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). diff --git a/charts/sourcegraph/README.md b/charts/sourcegraph/README.md index b40588790..b758dc816 100644 --- a/charts/sourcegraph/README.md +++ b/charts/sourcegraph/README.md @@ -103,11 +103,14 @@ release: Kubernetes rejects the upgrade. Before installing, compare the Labels on other objects can be changed, so they never block an upgrade, but Helm only manages the labels the chart renders. To render the labels that the -existing PersistentVolumeClaims, ServiceAccounts, and RBAC objects have: +existing objects have: -- `sourcegraph.labels` adds labels to all of them, on every component, except - the PersistentVolumeClaims that Kubernetes creates from a template. See +- `sourcegraph.labels` adds labels to every object the chart renders, on every + component. The PersistentVolumeClaims that Kubernetes creates from a + template are not among them. See [PersistentVolumeClaim labels](#persistentvolumeclaim-labels). +- `sourcegraph.serviceLabels` and `.serviceLabels` add labels to + every Service, or to one component's Services. - `.storageLabels` adds labels to the PersistentVolumeClaim of `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, or `redisStore`. @@ -254,7 +257,7 @@ In addition to the documented values, all services also support the following va | codeIntelDB.storageLabels | object | `{}` | Optional labels to add to the `codeintel-db` PVC, in addition to `sourcegraph.labels` | | codeIntelDB.storageSize | string | `"200Gi"` | PVC Storage Request for `codeintel-db` data volume | | codeIntelDB.storageSubPath | string | `""` | Optional subPath for the `codeintel-db` primary data volume mount | -| extraResources | list | `[]` | Additional resources to include in the rendered manifest. Templates are supported. | +| extraResources | list | `[]` | Additional resources to include in the rendered manifest. Templates are supported. `sourcegraph.labels` and the chart's standard labels are added to each resource; labels the resource sets itself take precedence. | | frontend.command | list | `[]` | Command for the `frontend` container, as a list, replacing the image's entrypoint, e.g. a shell wrapper that exports credentials read from mounted files before starting `frontend`. `frontend.args` (default `["serve"]`) is still passed as the arguments. | | frontend.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"readOnlyRootFilesystem":true,"runAsGroup":101,"runAsUser":100}` | Security context for the `frontend` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) | | frontend.createRoleBinding | bool | `true` | Disable the roleBinding resource for deployment environments blocking RBAC, ex. OpenShift's default "secure" SCC | @@ -539,7 +542,7 @@ In addition to the documented values, all services also support the following va | sourcegraph.image.repository | string | Sourcegraph's public Docker Hub registry | Global docker image registry or prefix | | sourcegraph.image.useGlobalTagAsDefault | bool | `false` | When set to true, sourcegraph.image.defaultTag is used as the default defaultTag for all services, instead of service-specific default defaultTags | | sourcegraph.imagePullSecrets | list | `[]` | Mount named secrets containing docker credentials | -| sourcegraph.labels | object | `{}` | Add extra labels to all resources | +| sourcegraph.labels | object | `{}` | Add extra labels to every object the chart renders, including `extraResources`. Prometheus copies the labels of a Service to the metrics it scrapes from it, so these labels also appear on those metrics. | | sourcegraph.localDevMode | bool | `false` | When true, remove all resource stanzas, allowing the scheduler to best-fit pods. Intended for local development with limited resources. | | sourcegraph.nameOverride | string | `""` | Set a custom name for the app.kubernetes.io/name annotation | | sourcegraph.nodeSelector | object | `{}` | Global NodeSelector, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector) | diff --git a/charts/sourcegraph/README.md.gotmpl b/charts/sourcegraph/README.md.gotmpl index 95c94300f..2f3f3ad7c 100644 --- a/charts/sourcegraph/README.md.gotmpl +++ b/charts/sourcegraph/README.md.gotmpl @@ -103,11 +103,14 @@ release: Kubernetes rejects the upgrade. Before installing, compare the Labels on other objects can be changed, so they never block an upgrade, but Helm only manages the labels the chart renders. To render the labels that the -existing PersistentVolumeClaims, ServiceAccounts, and RBAC objects have: +existing objects have: -- `sourcegraph.labels` adds labels to all of them, on every component, except - the PersistentVolumeClaims that Kubernetes creates from a template. See +- `sourcegraph.labels` adds labels to every object the chart renders, on every + component. The PersistentVolumeClaims that Kubernetes creates from a + template are not among them. See [PersistentVolumeClaim labels](#persistentvolumeclaim-labels). +- `sourcegraph.serviceLabels` and `.serviceLabels` add labels to + every Service, or to one component's Services. - `.storageLabels` adds labels to the PersistentVolumeClaim of `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, or `redisStore`. diff --git a/charts/sourcegraph/examples/prometheus/prometheus-override-k3s.ConfigMap.yaml b/charts/sourcegraph/examples/prometheus/prometheus-override-k3s.ConfigMap.yaml index 5343dee1d..552b5ef93 100644 --- a/charts/sourcegraph/examples/prometheus/prometheus-override-k3s.ConfigMap.yaml +++ b/charts/sourcegraph/examples/prometheus/prometheus-override-k3s.ConfigMap.yaml @@ -98,6 +98,10 @@ data: replacement: $1:$2 - action: labelmap regex: __meta_kubernetes_service_label_(.+) + # Sourcegraph specific customization. Do not copy the chart's standard labels from the Service to every + # metric: `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. + - action: labeldrop + regex: helm_sh_chart|app_kubernetes_io_(name|instance|version|managed_by) - source_labels: [__meta_kubernetes_namespace] action: replace target_label: ns @@ -131,6 +135,10 @@ data: target_label: instance - action: labelmap regex: __meta_kubernetes_service_label_(.+) + # Sourcegraph specific customization. Do not copy the chart's standard labels from the Service to every + # metric: `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. + - action: labeldrop + regex: helm_sh_chart|app_kubernetes_io_(name|instance|version|managed_by) - source_labels: [__meta_kubernetes_service_namespace] target_label: ns - source_labels: [__meta_kubernetes_service_name] diff --git a/charts/sourcegraph/templates/blobstore/blobstore.Service.yaml b/charts/sourcegraph/templates/blobstore/blobstore.Service.yaml index c3c180c4d..5641170ba 100644 --- a/charts/sourcegraph/templates/blobstore/blobstore.Service.yaml +++ b/charts/sourcegraph/templates/blobstore/blobstore.Service.yaml @@ -7,6 +7,7 @@ metadata: {{- toYaml .Values.blobstore.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: blobstore deploy: sourcegraph app.kubernetes.io/component: blobstore diff --git a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ConfigMap.yaml b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ConfigMap.yaml index 428fdf24e..64f2ef3df 100644 --- a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ConfigMap.yaml +++ b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ConfigMap.yaml @@ -8,6 +8,7 @@ metadata: annotations: description: Configuration for Code Insights labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app.kubernetes.io/component: codeinsights-db deploy: sourcegraph name: {{ .Values.codeInsightsDB.name }}-conf diff --git a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml index 650c58e82..946b5c8c8 100644 --- a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml +++ b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml @@ -4,6 +4,7 @@ kind: Secret metadata: name: {{ .Values.codeInsightsDB.name }}-auth labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: codeinsights-db deploy: sourcegraph app.kubernetes.io/component: codeinsights-db diff --git a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Service.yaml b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Service.yaml index 45ff67b0e..4a0a7d0be 100644 --- a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Service.yaml +++ b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Service.yaml @@ -9,6 +9,7 @@ metadata: {{- toYaml .Values.codeInsightsDB.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app.kubernetes.io/component: codeinsights-db app: codeinsights-db deploy: sourcegraph diff --git a/charts/sourcegraph/templates/codeintel-db/codeintel-db.ConfigMap.yaml b/charts/sourcegraph/templates/codeintel-db/codeintel-db.ConfigMap.yaml index d70ffd650..8929204a3 100644 --- a/charts/sourcegraph/templates/codeintel-db/codeintel-db.ConfigMap.yaml +++ b/charts/sourcegraph/templates/codeintel-db/codeintel-db.ConfigMap.yaml @@ -8,6 +8,7 @@ metadata: annotations: description: Configuration for PostgreSQL labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app.kubernetes.io/component: codeintel-db deploy: sourcegraph name: {{ .Values.codeIntelDB.name }}-conf diff --git a/charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml b/charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml index 021a54f0a..47743ab5f 100644 --- a/charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml +++ b/charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml @@ -4,6 +4,7 @@ kind: Secret metadata: name: {{ .Values.codeIntelDB.name }}-auth labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: codeintel-db deploy: sourcegraph app.kubernetes.io/component: codeintel-db diff --git a/charts/sourcegraph/templates/codeintel-db/codeintel-db.Service.yaml b/charts/sourcegraph/templates/codeintel-db/codeintel-db.Service.yaml index a283d4712..79a9698cc 100644 --- a/charts/sourcegraph/templates/codeintel-db/codeintel-db.Service.yaml +++ b/charts/sourcegraph/templates/codeintel-db/codeintel-db.Service.yaml @@ -9,6 +9,7 @@ metadata: {{- toYaml .Values.codeIntelDB.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app.kubernetes.io/component: codeintel-db app: codeintel-db deploy: sourcegraph diff --git a/charts/sourcegraph/templates/extraResources.yaml b/charts/sourcegraph/templates/extraResources.yaml index 00b404d00..a17aa5feb 100644 --- a/charts/sourcegraph/templates/extraResources.yaml +++ b/charts/sourcegraph/templates/extraResources.yaml @@ -1,4 +1,17 @@ +{{- $labels := include "sourcegraph.labels" $ | fromYaml }} {{- range .Values.extraResources }} +{{- $resource := . }} +{{- if kindIs "map" . }} + {{- /* Labels the resource sets itself take precedence over the common labels. */}} + {{- $resource = deepCopy . }} + {{- $metadata := get $resource "metadata" | default dict }} + {{- $resourceLabels := deepCopy $labels }} + {{- range $key, $value := get $metadata "labels" | default dict }} + {{- $_ := set $resourceLabels $key $value }} + {{- end }} + {{- $_ := set $metadata "labels" $resourceLabels }} + {{- $_ := set $resource "metadata" $metadata }} +{{- end }} --- -{{ tpl (. | toYaml) $ }} +{{ tpl ($resource | toYaml) $ }} {{- end }} diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend-internal.Service.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend-internal.Service.yaml index c0ba844bf..0a70e23e7 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend-internal.Service.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend-internal.Service.yaml @@ -6,6 +6,7 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: sourcegraph-frontend deploy: sourcegraph app.kubernetes.io/component: frontend diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Ingress.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Ingress.yaml index 10a9c357e..5c1adbb46 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Ingress.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Ingress.yaml @@ -13,6 +13,7 @@ metadata: {{- toYaml .Values.frontend.ingress.annotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: sourcegraph-frontend deploy: sourcegraph app.kubernetes.io/component: frontend diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.PodDisruptionBudget.yaml index 140088ea8..967599941 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.PodDisruptionBudget.yaml @@ -2,6 +2,8 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: + labels: + {{- include "sourcegraph.labels" . | nindent 4 }} name: sourcegraph-frontend spec: {{- toYaml .Values.frontend.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Service.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Service.yaml index d03e1c555..08494c85b 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Service.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.Service.yaml @@ -8,6 +8,7 @@ metadata: {{- toYaml .Values.frontend.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: sourcegraph-frontend deploy: sourcegraph app.kubernetes.io/component: frontend diff --git a/charts/sourcegraph/templates/gitserver/gitserver.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/gitserver/gitserver.PodDisruptionBudget.yaml index 2a62dcd29..45187f5b1 100644 --- a/charts/sourcegraph/templates/gitserver/gitserver.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/gitserver/gitserver.PodDisruptionBudget.yaml @@ -2,6 +2,8 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: + labels: + {{- include "sourcegraph.labels" . | nindent 4 }} name: {{ .Values.gitserver.name }} spec: {{- toYaml .Values.gitserver.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/gitserver/gitserver.Service.yaml b/charts/sourcegraph/templates/gitserver/gitserver.Service.yaml index 9f8a4ca1c..42466e308 100644 --- a/charts/sourcegraph/templates/gitserver/gitserver.Service.yaml +++ b/charts/sourcegraph/templates/gitserver/gitserver.Service.yaml @@ -10,6 +10,7 @@ metadata: {{- toYaml .Values.gitserver.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} deploy: sourcegraph app.kubernetes.io/component: gitserver type: gitserver diff --git a/charts/sourcegraph/templates/grafana/grafana.ConfigMap.yaml b/charts/sourcegraph/templates/grafana/grafana.ConfigMap.yaml index bcca1df13..82b1047d3 100644 --- a/charts/sourcegraph/templates/grafana/grafana.ConfigMap.yaml +++ b/charts/sourcegraph/templates/grafana/grafana.ConfigMap.yaml @@ -28,6 +28,7 @@ data: kind: ConfigMap metadata: labels: + {{- include "sourcegraph.labels" . | nindent 4 }} deploy: sourcegraph app.kubernetes.io/component: grafana name: {{ .Values.grafana.name }} diff --git a/charts/sourcegraph/templates/grafana/grafana.Service.yaml b/charts/sourcegraph/templates/grafana/grafana.Service.yaml index 0768f7ff6..9f32b9f46 100644 --- a/charts/sourcegraph/templates/grafana/grafana.Service.yaml +++ b/charts/sourcegraph/templates/grafana/grafana.Service.yaml @@ -7,6 +7,7 @@ metadata: {{- toYaml .Values.grafana.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: grafana deploy: sourcegraph app.kubernetes.io/component: grafana diff --git a/charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml b/charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml index ddefc5921..fe5d189e2 100644 --- a/charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml +++ b/charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: Secret metadata: labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: grafana deploy: sourcegraph app.kubernetes.io/component: grafana diff --git a/charts/sourcegraph/templates/indexed-search/indexed-search.IndexerService.yaml b/charts/sourcegraph/templates/indexed-search/indexed-search.IndexerService.yaml index edfed32b8..4f3da7d86 100644 --- a/charts/sourcegraph/templates/indexed-search/indexed-search.IndexerService.yaml +++ b/charts/sourcegraph/templates/indexed-search/indexed-search.IndexerService.yaml @@ -10,6 +10,7 @@ metadata: {{- toYaml .Values.indexedSearch.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: indexed-search-indexer deploy: sourcegraph app.kubernetes.io/component: indexed-search diff --git a/charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml index 7ec274581..6cab4253f 100644 --- a/charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml @@ -2,6 +2,8 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: + labels: + {{- include "sourcegraph.labels" . | nindent 4 }} name: {{ .Values.indexedSearch.name }} spec: {{- toYaml .Values.indexedSearch.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/indexed-search/indexed-search.Service.yaml b/charts/sourcegraph/templates/indexed-search/indexed-search.Service.yaml index 5edffe2a9..e69855f6c 100644 --- a/charts/sourcegraph/templates/indexed-search/indexed-search.Service.yaml +++ b/charts/sourcegraph/templates/indexed-search/indexed-search.Service.yaml @@ -10,6 +10,7 @@ metadata: {{- toYaml .Values.indexedSearch.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: indexed-search deploy: sourcegraph app.kubernetes.io/component: indexed-search diff --git a/charts/sourcegraph/templates/jaeger/jaeger-collector.Service.yaml b/charts/sourcegraph/templates/jaeger/jaeger-collector.Service.yaml index 3665df98e..588601d89 100644 --- a/charts/sourcegraph/templates/jaeger/jaeger-collector.Service.yaml +++ b/charts/sourcegraph/templates/jaeger/jaeger-collector.Service.yaml @@ -7,10 +7,10 @@ metadata: {{- toYaml .Values.jaeger.collector.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.jaeger.labels" . | nindent 4 }} deploy: sourcegraph app.kubernetes.io/component: all-in-one app: jaeger - app.kubernetes.io/name: jaeger {{- if .Values.jaeger.collector.serviceLabels }} {{- toYaml .Values.jaeger.collector.serviceLabels | nindent 4 }} {{- end }} diff --git a/charts/sourcegraph/templates/jaeger/jaeger-query.Service.yaml b/charts/sourcegraph/templates/jaeger/jaeger-query.Service.yaml index cfc9464b2..dfb7e2ef2 100644 --- a/charts/sourcegraph/templates/jaeger/jaeger-query.Service.yaml +++ b/charts/sourcegraph/templates/jaeger/jaeger-query.Service.yaml @@ -7,10 +7,10 @@ metadata: {{- toYaml .Values.jaeger.query.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.jaeger.labels" . | nindent 4 }} deploy: sourcegraph app.kubernetes.io/component: all-in-one app: jaeger - app.kubernetes.io/name: jaeger {{- if .Values.jaeger.query.serviceLabels }} {{- toYaml .Values.jaeger.query.serviceLabels | nindent 4 }} {{- end }} diff --git a/charts/sourcegraph/templates/node-exporter/node-exporter.Service.yaml b/charts/sourcegraph/templates/node-exporter/node-exporter.Service.yaml index b2dd5dabe..8d1297ccc 100644 --- a/charts/sourcegraph/templates/node-exporter/node-exporter.Service.yaml +++ b/charts/sourcegraph/templates/node-exporter/node-exporter.Service.yaml @@ -11,6 +11,7 @@ metadata: {{- toYaml .Values.nodeExporter.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app.kubernetes.io/component: node-exporter app: node-exporter deploy: sourcegraph diff --git a/charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml b/charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml index e4b103289..62234a958 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml @@ -5,6 +5,7 @@ kind: ConfigMap metadata: name: {{ .Values.openTelemetry.agent.name }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} deploy: sourcegraph app.kubernetes.io/component: otel-collector data: diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml index b236ee0bb..b73b64048 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml @@ -7,6 +7,7 @@ kind: ConfigMap metadata: name: {{ .Values.openTelemetry.gateway.name }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} deploy: sourcegraph app.kubernetes.io/component: otel-collector data: diff --git a/charts/sourcegraph/templates/pgsql/pgsql.ConfigMap.yaml b/charts/sourcegraph/templates/pgsql/pgsql.ConfigMap.yaml index 580849390..4b44ca8bf 100644 --- a/charts/sourcegraph/templates/pgsql/pgsql.ConfigMap.yaml +++ b/charts/sourcegraph/templates/pgsql/pgsql.ConfigMap.yaml @@ -8,6 +8,7 @@ metadata: annotations: description: Configuration for PostgreSQL labels: + {{- include "sourcegraph.labels" . | nindent 4 }} deploy: sourcegraph app.kubernetes.io/component: pgsql name: {{ .Values.pgsql.name }}-conf diff --git a/charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml b/charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml index 63ec30eb5..4a1b868f6 100644 --- a/charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml +++ b/charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: Secret metadata: labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: pgsql deploy: sourcegraph app.kubernetes.io/component: pgsql diff --git a/charts/sourcegraph/templates/pgsql/pgsql.Service.yaml b/charts/sourcegraph/templates/pgsql/pgsql.Service.yaml index eed8b3074..cb8a64165 100644 --- a/charts/sourcegraph/templates/pgsql/pgsql.Service.yaml +++ b/charts/sourcegraph/templates/pgsql/pgsql.Service.yaml @@ -9,6 +9,7 @@ metadata: {{- toYaml .Values.pgsql.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: pgsql deploy: sourcegraph app.kubernetes.io/component: pgsql diff --git a/charts/sourcegraph/templates/precise-code-intel/worker.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/precise-code-intel/worker.PodDisruptionBudget.yaml index 535f7f187..daf8d759a 100644 --- a/charts/sourcegraph/templates/precise-code-intel/worker.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/precise-code-intel/worker.PodDisruptionBudget.yaml @@ -2,6 +2,8 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: + labels: + {{- include "sourcegraph.labels" . | nindent 4 }} name: {{ .Values.preciseCodeIntel.name }} spec: {{- toYaml .Values.preciseCodeIntel.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/precise-code-intel/worker.Service.yaml b/charts/sourcegraph/templates/precise-code-intel/worker.Service.yaml index 59f9ed7aa..0f94bd041 100644 --- a/charts/sourcegraph/templates/precise-code-intel/worker.Service.yaml +++ b/charts/sourcegraph/templates/precise-code-intel/worker.Service.yaml @@ -8,6 +8,7 @@ metadata: {{- toYaml .Values.preciseCodeIntel.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: precise-code-intel-worker deploy: sourcegraph app.kubernetes.io/component: precise-code-intel diff --git a/charts/sourcegraph/templates/priorityClass.yaml b/charts/sourcegraph/templates/priorityClass.yaml index 50d5e3829..fb52d5066 100644 --- a/charts/sourcegraph/templates/priorityClass.yaml +++ b/charts/sourcegraph/templates/priorityClass.yaml @@ -2,6 +2,8 @@ apiVersion: scheduling.k8s.io/v1 kind: PriorityClass metadata: + labels: + {{- include "sourcegraph.labels" $ | nindent 4 }} name: {{ $class.name }} value: {{ $class.value }} preemptionPolicy: {{ $class.preemptionPolicy }} diff --git a/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml b/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml index 9d5f789b8..18ff6679b 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: ConfigMap metadata: labels: + {{- include "sourcegraph.labels" . | nindent 4 }} deploy: sourcegraph app.kubernetes.io/component: prometheus name: {{ .Values.prometheus.name }} @@ -160,6 +161,10 @@ data: replacement: $1:$2 - action: labelmap regex: __meta_kubernetes_service_label_(.+) + # Sourcegraph specific customization. Do not copy the chart's standard labels from the Service to every + # metric: `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. + - action: labeldrop + regex: helm_sh_chart|app_kubernetes_io_(name|instance|version|managed_by) - source_labels: [__meta_kubernetes_namespace] action: replace # Sourcegraph specific customization. We want a more convenient to type label. @@ -214,6 +219,10 @@ data: target_label: instance - action: labelmap regex: __meta_kubernetes_service_label_(.+) + # Sourcegraph specific customization. Do not copy the chart's standard labels from the Service to every + # metric: `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. + - action: labeldrop + regex: helm_sh_chart|app_kubernetes_io_(name|instance|version|managed_by) - source_labels: [__meta_kubernetes_service_namespace] # Sourcegraph specific customization. We want a more convenient to type label. # target_label: kubernetes_namespace diff --git a/charts/sourcegraph/templates/prometheus/prometheus.Service.yaml b/charts/sourcegraph/templates/prometheus/prometheus.Service.yaml index 45b7367ac..8b30dd7a5 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.Service.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.Service.yaml @@ -7,6 +7,7 @@ metadata: {{- toYaml .Values.prometheus.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: prometheus deploy: sourcegraph app.kubernetes.io/component: prometheus diff --git a/charts/sourcegraph/templates/redis/redis-cache.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/redis/redis-cache.PodDisruptionBudget.yaml index 0668eac6c..2630e233e 100644 --- a/charts/sourcegraph/templates/redis/redis-cache.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/redis/redis-cache.PodDisruptionBudget.yaml @@ -2,6 +2,8 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: + labels: + {{- include "sourcegraph.labels" . | nindent 4 }} name: {{ .Values.redisCache.name }} spec: {{- toYaml .Values.redisCache.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/redis/redis-cache.Secret.yaml b/charts/sourcegraph/templates/redis/redis-cache.Secret.yaml index 3e2129d22..f6d1db18c 100644 --- a/charts/sourcegraph/templates/redis/redis-cache.Secret.yaml +++ b/charts/sourcegraph/templates/redis/redis-cache.Secret.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: Secret metadata: labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: redis-cache deploy: sourcegraph app.kubernetes.io/component: redis-cache diff --git a/charts/sourcegraph/templates/redis/redis-cache.Service.yaml b/charts/sourcegraph/templates/redis/redis-cache.Service.yaml index a5c7433e7..e9fec4011 100644 --- a/charts/sourcegraph/templates/redis/redis-cache.Service.yaml +++ b/charts/sourcegraph/templates/redis/redis-cache.Service.yaml @@ -9,6 +9,7 @@ metadata: {{- toYaml .Values.redisCache.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: redis-cache deploy: sourcegraph app.kubernetes.io/component: redis diff --git a/charts/sourcegraph/templates/redis/redis-store.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/redis/redis-store.PodDisruptionBudget.yaml index 99cf9f58b..84e4792e0 100644 --- a/charts/sourcegraph/templates/redis/redis-store.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.PodDisruptionBudget.yaml @@ -2,6 +2,8 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: + labels: + {{- include "sourcegraph.labels" . | nindent 4 }} name: {{ .Values.redisStore.name }} spec: {{- toYaml .Values.redisStore.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/redis/redis-store.Secret.yaml b/charts/sourcegraph/templates/redis/redis-store.Secret.yaml index 534fc3779..4fc2ee3b7 100644 --- a/charts/sourcegraph/templates/redis/redis-store.Secret.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.Secret.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: Secret metadata: labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: redis-store deploy: sourcegraph app.kubernetes.io/component: redis-store diff --git a/charts/sourcegraph/templates/redis/redis-store.Service.yaml b/charts/sourcegraph/templates/redis/redis-store.Service.yaml index 120724ead..57a3be48a 100644 --- a/charts/sourcegraph/templates/redis/redis-store.Service.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.Service.yaml @@ -9,6 +9,7 @@ metadata: {{- toYaml .Values.redisStore.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: redis-store deploy: sourcegraph app.kubernetes.io/component: redis diff --git a/charts/sourcegraph/templates/searcher/searcher.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/searcher/searcher.PodDisruptionBudget.yaml index 2683b028c..462428391 100644 --- a/charts/sourcegraph/templates/searcher/searcher.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/searcher/searcher.PodDisruptionBudget.yaml @@ -2,6 +2,8 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: + labels: + {{- include "sourcegraph.labels" . | nindent 4 }} name: {{ .Values.searcher.name }} spec: {{- toYaml .Values.searcher.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/searcher/searcher.Service.yaml b/charts/sourcegraph/templates/searcher/searcher.Service.yaml index 6fc01a7cd..5783ca42f 100644 --- a/charts/sourcegraph/templates/searcher/searcher.Service.yaml +++ b/charts/sourcegraph/templates/searcher/searcher.Service.yaml @@ -8,6 +8,7 @@ metadata: {{- toYaml .Values.searcher.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: searcher deploy: sourcegraph app.kubernetes.io/component: searcher diff --git a/charts/sourcegraph/templates/syntactic-code-intel/worker.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/syntactic-code-intel/worker.PodDisruptionBudget.yaml index 9f62342ad..b6d39710d 100644 --- a/charts/sourcegraph/templates/syntactic-code-intel/worker.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/syntactic-code-intel/worker.PodDisruptionBudget.yaml @@ -2,6 +2,8 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: + labels: + {{- include "sourcegraph.labels" . | nindent 4 }} name: {{ .Values.syntacticCodeIntel.name }} spec: {{- toYaml .Values.syntacticCodeIntel.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/syntactic-code-intel/worker.Service.yaml b/charts/sourcegraph/templates/syntactic-code-intel/worker.Service.yaml index 9a8d54260..e0547a761 100644 --- a/charts/sourcegraph/templates/syntactic-code-intel/worker.Service.yaml +++ b/charts/sourcegraph/templates/syntactic-code-intel/worker.Service.yaml @@ -9,6 +9,7 @@ metadata: {{- toYaml .Values.syntacticCodeIntel.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: syntactic-code-intel-worker deploy: sourcegraph app.kubernetes.io/component: syntactic-code-intel diff --git a/charts/sourcegraph/templates/syntect-server/syntect-server.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/syntect-server/syntect-server.PodDisruptionBudget.yaml index d34cf4bee..006224328 100644 --- a/charts/sourcegraph/templates/syntect-server/syntect-server.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/syntect-server/syntect-server.PodDisruptionBudget.yaml @@ -2,6 +2,8 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: + labels: + {{- include "sourcegraph.labels" . | nindent 4 }} name: {{ .Values.syntectServer.name }} spec: {{- toYaml .Values.syntectServer.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/syntect-server/syntect-server.Service.yaml b/charts/sourcegraph/templates/syntect-server/syntect-server.Service.yaml index dc5eccc7d..a506da44e 100644 --- a/charts/sourcegraph/templates/syntect-server/syntect-server.Service.yaml +++ b/charts/sourcegraph/templates/syntect-server/syntect-server.Service.yaml @@ -8,6 +8,7 @@ metadata: {{- toYaml .Values.syntectServer.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: syntect-server deploy: sourcegraph app.kubernetes.io/component: syntect-server diff --git a/charts/sourcegraph/templates/worker/worker-executors.Service.yaml b/charts/sourcegraph/templates/worker/worker-executors.Service.yaml index a12d9e122..cca238ba1 100644 --- a/charts/sourcegraph/templates/worker/worker-executors.Service.yaml +++ b/charts/sourcegraph/templates/worker/worker-executors.Service.yaml @@ -8,6 +8,7 @@ metadata: {{- toYaml .Values.worker.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: worker deploy: sourcegraph app.kubernetes.io/component: worker diff --git a/charts/sourcegraph/templates/worker/worker.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/worker/worker.PodDisruptionBudget.yaml index cd52d3c6d..a58d99308 100644 --- a/charts/sourcegraph/templates/worker/worker.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/worker/worker.PodDisruptionBudget.yaml @@ -8,6 +8,8 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: + labels: + {{- include "sourcegraph.labels" $top | nindent 4 }} name: {{ $name }} spec: {{- toYaml $top.Values.worker.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/worker/worker.Service.yaml b/charts/sourcegraph/templates/worker/worker.Service.yaml index b5a5ffb12..237cc7d9b 100644 --- a/charts/sourcegraph/templates/worker/worker.Service.yaml +++ b/charts/sourcegraph/templates/worker/worker.Service.yaml @@ -8,6 +8,7 @@ metadata: {{- toYaml .Values.worker.serviceAnnotations | nindent 4 }} {{- end }} labels: + {{- include "sourcegraph.labels" . | nindent 4 }} app: worker deploy: sourcegraph app.kubernetes.io/component: worker diff --git a/charts/sourcegraph/tests/allObjectLabels_test.yaml b/charts/sourcegraph/tests/allObjectLabels_test.yaml new file mode 100644 index 000000000..b6b2da085 --- /dev/null +++ b/charts/sourcegraph/tests/allObjectLabels_test.yaml @@ -0,0 +1,196 @@ +suite: sourcegraph.labels on every object +release: + name: sourcegraph + namespace: sourcegraph +# The chart version is part of the helm.sh/chart label and changes on every +# release, so pin it to compare whole label sets. +chart: + version: 1.2.3 + appVersion: 1.2.3 +# No `templates` list, so every template in the chart is rendered, including +# ones added later. The two excluded manifests are not rendered together with +# the rest and are tested in the second suite of this file. +excludeTemplates: +- NOTES.txt +- otel-collector/otel-collector.ConfigMap.yaml +- prometheus/prometheus.RoleBinding.yaml +tests: +# This test fails with "no manifest found" for a template that renders nothing, +# so enable a new optional template here. +- it: should add sourcegraph.labels to every object the chart renders + set: + sourcegraph.labels: &globalLabels + example.com/installation: production + example.com/project: sourcegraph + storageClass.create: true + sgTestConnection.enabled: true + jaeger.enabled: true + nodeExporter.enabled: true + syntacticCodeIntel.enabled: true + frontend.ingress.enabled: true + redisCache.config.enabled: true + redisStore.config.enabled: true + grafana.auth: + database: grafana + host: pgsql + password: password + port: "5432" + sslmode: disable + user: grafana + worker.replicas: + - jobs: [codeintel-upload-janitor] + frontend.podDisruptionBudget: &podDisruptionBudget + maxUnavailable: 1 + gitserver.podDisruptionBudget: *podDisruptionBudget + indexedSearch.podDisruptionBudget: *podDisruptionBudget + preciseCodeIntel.podDisruptionBudget: *podDisruptionBudget + redisCache.podDisruptionBudget: *podDisruptionBudget + redisStore.podDisruptionBudget: *podDisruptionBudget + searcher.podDisruptionBudget: *podDisruptionBudget + syntacticCodeIntel.podDisruptionBudget: *podDisruptionBudget + syntectServer.podDisruptionBudget: *podDisruptionBudget + worker.podDisruptionBudget: *podDisruptionBudget + blobstore.serviceAccount.create: true + cadvisor.serviceAccount.create: true + codeInsightsDB.serviceAccount.create: true + codeIntelDB.serviceAccount.create: true + frontend.serviceAccount.create: true + gitserver.serviceAccount.create: true + grafana.serviceAccount.create: true + indexedSearch.serviceAccount.create: true + jaeger.serviceAccount.create: true + nodeExporter.serviceAccount.create: true + openTelemetry.agent.serviceAccount.create: true + openTelemetry.gateway.serviceAccount.create: true + pgsql.serviceAccount.create: true + preciseCodeIntel.serviceAccount.create: true + prometheus.serviceAccount.create: true + redisCache.serviceAccount.create: true + redisStore.serviceAccount.create: true + searcher.serviceAccount.create: true + syntacticCodeIntel.serviceAccount.create: true + syntectServer.serviceAccount.create: true + worker.serviceAccount.create: true + priorityClasses: + - name: gitserver-class + value: 1000000 + extraResources: + - apiVersion: networking.k8s.io/v1 + kind: NetworkPolicy + metadata: + name: deny-all + spec: + podSelector: {} + asserts: + - isSubset: + path: metadata.labels + content: &allLabels + helm.sh/chart: sourcegraph-1.2.3 + app.kubernetes.io/version: 1.2.3 + app.kubernetes.io/managed-by: Helm + example.com/installation: production + example.com/project: sourcegraph + +- it: should keep the labels a Service already has + templates: + - frontend/sourcegraph-frontend.Service.yaml + - jaeger/jaeger-query.Service.yaml + set: + sourcegraph.labels: *globalLabels + jaeger.enabled: true + frontend.serviceLabels: + example.com/service: frontend + asserts: + - equal: + path: metadata.labels + value: + helm.sh/chart: sourcegraph-1.2.3 + app.kubernetes.io/name: sourcegraph + app.kubernetes.io/instance: sourcegraph + app.kubernetes.io/version: 1.2.3 + app.kubernetes.io/managed-by: Helm + example.com/installation: production + example.com/project: sourcegraph + example.com/service: frontend + app: sourcegraph-frontend + deploy: sourcegraph + app.kubernetes.io/component: frontend + template: frontend/sourcegraph-frontend.Service.yaml + - equal: + path: metadata.labels + value: + helm.sh/chart: sourcegraph-1.2.3 + app.kubernetes.io/name: jaeger + app.kubernetes.io/version: 1.2.3 + app.kubernetes.io/managed-by: Helm + example.com/installation: production + example.com/project: sourcegraph + app: jaeger + deploy: sourcegraph + app.kubernetes.io/component: all-in-one + template: jaeger/jaeger-query.Service.yaml + +- it: should let an extra resource override sourcegraph.labels with its own labels + template: extraResources.yaml + set: + sourcegraph.labels: *globalLabels + extraResources: + - apiVersion: v1 + kind: ConfigMap + metadata: + name: extra + labels: + example.com/project: extra + example.com/release: "{{ .Release.Name }}" + data: + maxBytes: "1048576" + asserts: + - equal: + path: metadata.labels + value: + helm.sh/chart: sourcegraph-1.2.3 + app.kubernetes.io/name: sourcegraph + app.kubernetes.io/instance: sourcegraph + app.kubernetes.io/version: 1.2.3 + app.kubernetes.io/managed-by: Helm + example.com/installation: production + example.com/project: extra + example.com/release: sourcegraph + +- it: should not copy the chart's version labels from Services to metrics + template: prometheus/prometheus.ConfigMap.yaml + asserts: + - matchRegex: + path: data["prometheus.yml"] + # Both jobs that map Service labels to metric labels drop the chart's labels afterwards. + pattern: (?s)(regex. __meta_kubernetes_service_label_\(\.\+\)\n(\s*#[^\n]*\n)*\s*- action. labeldrop\n\s*regex. helm_sh_chart\|app_kubernetes_io_\(name\|instance\|version\|managed_by\)\n.*){2} +--- +suite: sourcegraph.labels on the objects that replace others +release: + name: sourcegraph + namespace: sourcegraph +chart: + version: 1.2.3 + appVersion: 1.2.3 +templates: +- otel-collector/otel-collector.ConfigMap.yaml +- prometheus/prometheus.RoleBinding.yaml +tests: +- it: should add sourcegraph.labels to the objects that replace others + set: + sourcegraph.labels: + example.com/installation: production + example.com/project: sourcegraph + prometheus.privileged: false + openTelemetry.gateway.config.traces.exporters: + otlp: + endpoint: collector.example.com:4317 + asserts: + - isSubset: + path: metadata.labels + content: + helm.sh/chart: sourcegraph-1.2.3 + app.kubernetes.io/version: 1.2.3 + app.kubernetes.io/managed-by: Helm + example.com/installation: production + example.com/project: sourcegraph diff --git a/charts/sourcegraph/values.yaml b/charts/sourcegraph/values.yaml index 8b68e6b4f..485b2b334 100644 --- a/charts/sourcegraph/values.yaml +++ b/charts/sourcegraph/values.yaml @@ -15,7 +15,8 @@ sourcegraph: useGlobalTagAsDefault: false # -- Mount named secrets containing docker credentials imagePullSecrets: [] - # -- Add extra labels to all resources + # -- Add extra labels to every object the chart renders, including `extraResources`. Prometheus copies the labels of + # a Service to the metrics it scrapes from it, so these labels also appear on those metrics. labels: {} # -- When true, remove all resource stanzas, allowing the scheduler to best-fit pods. Intended for local development with limited resources. localDevMode: false @@ -1605,7 +1606,8 @@ worker: # -- Name of the ServiceAccount to be created or an existing ServiceAccount name: "" -# -- Additional resources to include in the rendered manifest. Templates are supported. +# -- Additional resources to include in the rendered manifest. Templates are supported. `sourcegraph.labels` and the +# chart's standard labels are added to each resource; labels the resource sets itself take precedence. extraResources: [] # -- Additional priorityClasses minimize re-scheduling downtime for StatefulSets. Each StatefulSets might use different priority class. From d31f087863ca34ce080d81900dbd78a71e6e9e39 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 11 Nov 2026 19:13:03 +0000 Subject: [PATCH 02/18] sourcegraph: render redisStore.serviceAccount.annotations The redis-store ServiceAccount was the only one that did not include the annotations helper, so redisStore.serviceAccount.annotations was silently dropped. Amp-Thread-ID: https://ampcode.com/threads/T-c7c725c9-ed68-48e2-9f2d-0b8c31e76050 Co-authored-by: Amp --- charts/sourcegraph/CHANGELOG.md | 1 + .../redis/redis-store.ServiceAccount.yaml | 1 + .../tests/serviceAccountAnnotations_test.yaml | 14 ++++++++++++++ 3 files changed, 16 insertions(+) diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index 2aa411b76..7a656bd67 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -10,6 +10,7 @@ Use `**BREAKING**:` to denote a breaking change - Added `frontend.internalServiceAnnotations` and `frontend.internalServiceLabels` for the `sourcegraph-frontend-internal` Service. That Service no longer renders `frontend.serviceAnnotations` and `frontend.serviceLabels`, which now apply to the `sourcegraph-frontend` Service only, so load balancer annotations or a service mesh label set for the external Service no longer land on the internal one. If you relied on them on the internal Service, set the new values. - 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. +- Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. - `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 rendered on every object the chart creates: also on Services, ConfigMaps, Secrets, the Ingress, PodDisruptionBudgets, PriorityClasses, and `extraResources`, so existing releases gain these labels on upgrade. Labels that an `extraResources` entry or `serviceLabels` set take precedence. Labels on these objects can be changed in place, so nothing is recreated or restarted. Prometheus copies the labels of a Service to the metrics it scrapes from it, so labels set in `sourcegraph.labels` now appear on those metrics, as `sourcegraph.serviceLabels` and `.serviceLabels` already do. The bundled Prometheus configuration drops the chart's standard labels instead, because `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade; the `otel-collector` metrics, the only ones that had them, lose them. If you set `prometheus.existingConfig`, add the same `labeldrop` rule after each `__meta_kubernetes_service_label_(.+)` `labelmap` rule in your `prometheus.yml`, as in the [k3s example](examples/prometheus/prometheus-override-k3s.ConfigMap.yaml). - Added `storageLabels` on `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, and `redisStore` to label each component's PersistentVolumeClaim, and `.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). - 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. diff --git a/charts/sourcegraph/templates/redis/redis-store.ServiceAccount.yaml b/charts/sourcegraph/templates/redis/redis-store.ServiceAccount.yaml index 259207cc7..dd5a2e6be 100644 --- a/charts/sourcegraph/templates/redis/redis-store.ServiceAccount.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.ServiceAccount.yaml @@ -10,5 +10,6 @@ metadata: category: rbac deploy: sourcegraph app.kubernetes.io/component: redis + {{- include "sourcegraph.serviceAccountAnnotations" (list . "redisStore") | trim | nindent 2 }} name: {{ include "sourcegraph.serviceAccountName" (list . "redisStore") }} {{- end }} diff --git a/charts/sourcegraph/tests/serviceAccountAnnotations_test.yaml b/charts/sourcegraph/tests/serviceAccountAnnotations_test.yaml index db5418647..19f2768e9 100644 --- a/charts/sourcegraph/tests/serviceAccountAnnotations_test.yaml +++ b/charts/sourcegraph/tests/serviceAccountAnnotations_test.yaml @@ -48,3 +48,17 @@ tests: value: iam.gke.io/gcp-service-account: sourcegraph@sourcegraph.iam.gserviceaccount.com - matchSnapshot: {} + +- it: should render service account annotations when redisStore.serviceAccount.annotations is defined + set: + redisStore: + serviceAccount: + create: true + annotations: + iam.gke.io/gcp-service-account: sourcegraph@sourcegraph.iam.gserviceaccount.com + template: redis/redis-store.ServiceAccount.yaml + asserts: + - equal: + path: metadata.annotations + value: + iam.gke.io/gcp-service-account: sourcegraph@sourcegraph.iam.gserviceaccount.com From 4bff4dd03da11046abbbe6fa8acedc99be878ca0 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 11 Nov 2026 19:29:14 +0000 Subject: [PATCH 03/18] Add deploy, component, and per-component labels to every object PodDisruptionBudgets, PriorityClasses, the StorageClass, the test Pod, and the k8s executor Secret now have deploy and app.kubernetes.io/component labels, and the jaeger objects have app.kubernetes.io/instance. .labels and executor.labels are also rendered on a component's ConfigMaps, Secrets, and PodDisruptionBudget. Adds storageClass.labels, priorityClasses[].labels, and privateDockerRegistry.serviceLabels (dind). Amp-Thread-ID: https://ampcode.com/threads/T-c7c725c9-ed68-48e2-9f2d-0b8c31e76050 Co-authored-by: Amp --- charts/sourcegraph-executor/CHANGELOG.md | 1 + charts/sourcegraph-executor/dind/README.md | 1 + .../executor/docker-daemon.ConfigMap.yaml | 3 + .../private-docker-registry.Service.yaml | 3 + .../dind/tests/labels_test.yaml | 27 +++ charts/sourcegraph-executor/dind/values.yaml | 2 + .../k8s/templates/executor.ConfigMap.yaml | 5 +- .../k8s/templates/executor.Role.yaml | 3 + .../k8s/templates/executor.RoleBinding.yaml | 3 + .../k8s/templates/executor.Secret.yaml | 4 + .../templates/executor.ServiceAccount.yaml | 3 + .../k8s/tests/labels_test.yaml | 24 +++ .../tests/labels_test.yaml | 11 ++ charts/sourcegraph/CHANGELOG.md | 2 + charts/sourcegraph/README.md | 7 +- charts/sourcegraph/README.md.gotmpl | 2 + charts/sourcegraph/templates/_helpers.tpl | 1 + .../codeinsights-db.ConfigMap.yaml | 3 + .../codeinsights-db.Secret.yaml | 3 + .../codeintel-db/codeintel-db.ConfigMap.yaml | 3 + .../codeintel-db/codeintel-db.Secret.yaml | 3 + .../sourcegraph/templates/extraResources.yaml | 1 + ...rcegraph-frontend.PodDisruptionBudget.yaml | 5 + .../gitserver.PodDisruptionBudget.yaml | 5 + .../templates/grafana/grafana.ConfigMap.yaml | 3 + .../grafana/grafana.pgsql.Secret.yaml | 3 + .../indexed-search.PodDisruptionBudget.yaml | 5 + .../templates/jaeger/jaeger.ConfigMap.yaml | 3 + .../otel-collector/otel-agent.ConfigMap.yaml | 3 + .../otel-collector.ConfigMap.yaml | 3 + .../templates/pgsql/pgsql.ConfigMap.yaml | 3 + .../templates/pgsql/pgsql.Secret.yaml | 3 + .../worker.PodDisruptionBudget.yaml | 5 + .../sourcegraph/templates/priorityClass.yaml | 5 + .../prometheus/prometheus.ConfigMap.yaml | 3 + .../redis-cache.PodDisruptionBudget.yaml | 5 + .../templates/redis/redis-cache.Secret.yaml | 3 + .../redis-store.PodDisruptionBudget.yaml | 5 + .../templates/redis/redis-store.Secret.yaml | 3 + .../searcher.PodDisruptionBudget.yaml | 5 + .../sourcegraph/templates/storageclass.yaml | 4 + .../worker.PodDisruptionBudget.yaml | 5 + .../syntect-server.PodDisruptionBudget.yaml | 5 + .../templates/tests/test-connection.yaml | 2 + .../worker/worker.PodDisruptionBudget.yaml | 5 + .../tests/allObjectLabels_test.yaml | 154 +++++++++++++++++- charts/sourcegraph/values.yaml | 11 +- 47 files changed, 363 insertions(+), 8 deletions(-) diff --git a/charts/sourcegraph-executor/CHANGELOG.md b/charts/sourcegraph-executor/CHANGELOG.md index da22083bf..5cc26836d 100644 --- a/charts/sourcegraph-executor/CHANGELOG.md +++ b/charts/sourcegraph-executor/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased +- Every object the charts create now has the `deploy` and `app.kubernetes.io/component` labels: the `sourcegraph-executor-k8s` Secret did not have them. `executor.labels` is now also rendered on the `sourcegraph-executor-k8s` ConfigMap, Secret, ServiceAccount, Role, and RoleBinding, and on the `sourcegraph-executor-dind` `docker-config` ConfigMap, not only on the Deployment. Added `privateDockerRegistry.serviceLabels` to the `sourcegraph-executor-dind` chart to label the `private-docker-registry` Service. - `sourcegraph.labels` and the charts' standard labels (`helm.sh/chart`, `app.kubernetes.io/name`, `app.kubernetes.io/instance`, `app.kubernetes.io/version`, `app.kubernetes.io/managed-by`) are now rendered on every object the charts create. The `sourcegraph-executor-k8s` chart rendered them on none of its objects (ConfigMap, Deployment, Role, RoleBinding, Secret, Service, ServiceAccount), and the `sourcegraph-executor-dind` chart did not render them on the `docker-config` ConfigMap and the `private-docker-registry` Service. Existing releases gain these labels on upgrade. Labels on these objects can be changed in place, so nothing is recreated or restarted. ## 8.0.0 diff --git a/charts/sourcegraph-executor/dind/README.md b/charts/sourcegraph-executor/dind/README.md index 14bff60a9..29726ab31 100644 --- a/charts/sourcegraph-executor/dind/README.md +++ b/charts/sourcegraph-executor/dind/README.md @@ -90,6 +90,7 @@ In addition to the documented values, the `executor` and `private-docker-registr | privateDockerRegistry.image.registry | string | `"index.docker.io"` | | | privateDockerRegistry.image.repository | string | `"registry"` | | | privateDockerRegistry.image.tag | int | `3` | | +| privateDockerRegistry.serviceLabels | object | `{}` | Add extra labels to the `private-docker-registry` Service | | privateDockerRegistry.storageSize | string | `"10Gi"` | | | queues | list | `[]` | Optional list of queues to deploy as standalone Deployments. When set, the single executor Deployment is not rendered. Each entry supports: name (required) — used as the deployment name suffix (executor-) queueName — sets EXECUTOR_QUEUE_NAME; defaults to name if omitted queueNames — sets EXECUTOR_QUEUE_NAMES (comma-joined); takes precedence over queueName when set replicaCount, resources, env (merged with executor.env, queue overrides) | | sourcegraph.affinity | object | `{}` | Affinity, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity) | diff --git a/charts/sourcegraph-executor/dind/templates/executor/docker-daemon.ConfigMap.yaml b/charts/sourcegraph-executor/dind/templates/executor/docker-daemon.ConfigMap.yaml index d91dbdcb3..6ffb86250 100644 --- a/charts/sourcegraph-executor/dind/templates/executor/docker-daemon.ConfigMap.yaml +++ b/charts/sourcegraph-executor/dind/templates/executor/docker-daemon.ConfigMap.yaml @@ -3,6 +3,9 @@ kind: ConfigMap metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.executor.labels }} + {{- toYaml .Values.executor.labels | nindent 4 }} + {{- end }} app: executor deploy: sourcegraph app.kubernetes.io/component: executor diff --git a/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Service.yaml b/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Service.yaml index b2227b484..cf472ab58 100644 --- a/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Service.yaml +++ b/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Service.yaml @@ -11,6 +11,9 @@ metadata: app: private-docker-registry deploy: sourcegraph app.kubernetes.io/component: private-docker-registry + {{- if .Values.privateDockerRegistry.serviceLabels }} + {{- toYaml .Values.privateDockerRegistry.serviceLabels | nindent 4 }} + {{- end }} name: private-docker-registry spec: ports: diff --git a/charts/sourcegraph-executor/dind/tests/labels_test.yaml b/charts/sourcegraph-executor/dind/tests/labels_test.yaml index 56c29a4ce..236bbcd0c 100644 --- a/charts/sourcegraph-executor/dind/tests/labels_test.yaml +++ b/charts/sourcegraph-executor/dind/tests/labels_test.yaml @@ -18,5 +18,32 @@ tests: path: metadata.labels content: app.kubernetes.io/managed-by: Helm + deploy: sourcegraph example.com/installation: production example.com/project: sourcegraph + - exists: + path: metadata.labels["helm.sh/chart"] + - exists: + path: metadata.labels["app.kubernetes.io/name"] + - exists: + path: metadata.labels["app.kubernetes.io/instance"] + - exists: + path: metadata.labels["app.kubernetes.io/version"] + - exists: + path: metadata.labels["app.kubernetes.io/component"] + - it: should add the labels of a component to every object of it + set: + executor: + queueName: batches + labels: + example.com/service: component + privateDockerRegistry: + enabled: true + labels: + example.com/service: component + serviceLabels: + example.com/service: component + asserts: + - equal: + path: metadata.labels["example.com/service"] + value: component diff --git a/charts/sourcegraph-executor/dind/values.yaml b/charts/sourcegraph-executor/dind/values.yaml index 571ebe624..10b74fae0 100644 --- a/charts/sourcegraph-executor/dind/values.yaml +++ b/charts/sourcegraph-executor/dind/values.yaml @@ -217,6 +217,8 @@ privateDockerRegistry: repository: registry tag: 3 storageSize: 10Gi + # -- Add extra labels to the `private-docker-registry` Service + serviceLabels: {} # -- Extra environment variables to set on the registry container. # Registry can be configured with environment variables using the pattern # REGISTRY_
_ (uppercase). Full reference: diff --git a/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml b/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml index cfd074819..9963cfea1 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml @@ -4,7 +4,10 @@ metadata: name: {{ include "executor.name" . }} labels: {{- include "sourcegraph.labels" . | nindent 4 }} -{{- include "executor.labels" . | nindent 4 }} + {{- include "executor.labels" . | nindent 4 }} + {{- if .Values.executor.labels }} + {{- toYaml .Values.executor.labels | nindent 4 }} + {{- end }} data: EXECUTOR_USE_FIRECRACKER: "false" EXECUTOR_FRONTEND_URL: "{{ .Values.executor.frontendUrl }}" diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Role.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Role.yaml index 36107636e..68caac8a5 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Role.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Role.yaml @@ -5,6 +5,9 @@ metadata: name: sg-executor-role labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.executor.labels }} + {{- toYaml .Values.executor.labels | nindent 4 }} + {{- end }} category: rbac deploy: sourcegraph sourcegraph-resource-requires: cluster-admin diff --git a/charts/sourcegraph-executor/k8s/templates/executor.RoleBinding.yaml b/charts/sourcegraph-executor/k8s/templates/executor.RoleBinding.yaml index df5814537..e7e6f2df7 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.RoleBinding.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.RoleBinding.yaml @@ -5,6 +5,9 @@ metadata: name: sg-executor-role-binding labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.executor.labels }} + {{- toYaml .Values.executor.labels | nindent 4 }} + {{- end }} category: rbac deploy: sourcegraph sourcegraph-resource-requires: cluster-admin diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Secret.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Secret.yaml index 01fd6e810..936b4ea1a 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Secret.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Secret.yaml @@ -4,6 +4,10 @@ kind: Secret metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- include "executor.labels" . | nindent 4 }} + {{- if .Values.executor.labels }} + {{- toYaml .Values.executor.labels | nindent 4 }} + {{- end }} name: {{ include "executor.name" . }} type: Opaque data: diff --git a/charts/sourcegraph-executor/k8s/templates/executor.ServiceAccount.yaml b/charts/sourcegraph-executor/k8s/templates/executor.ServiceAccount.yaml index 1b8d16bd3..39f2a0fb7 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.ServiceAccount.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.ServiceAccount.yaml @@ -5,6 +5,9 @@ metadata: name: sg-executor labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.executor.labels }} + {{- toYaml .Values.executor.labels | nindent 4 }} + {{- end }} category: rbac deploy: sourcegraph sourcegraph-resource-requires: cluster-admin diff --git a/charts/sourcegraph-executor/k8s/tests/labels_test.yaml b/charts/sourcegraph-executor/k8s/tests/labels_test.yaml index c0140b3c3..a627f5f03 100644 --- a/charts/sourcegraph-executor/k8s/tests/labels_test.yaml +++ b/charts/sourcegraph-executor/k8s/tests/labels_test.yaml @@ -17,5 +17,29 @@ tests: path: metadata.labels content: app.kubernetes.io/managed-by: Helm + deploy: sourcegraph example.com/installation: production example.com/project: sourcegraph + - exists: + path: metadata.labels["helm.sh/chart"] + - exists: + path: metadata.labels["app.kubernetes.io/name"] + - exists: + path: metadata.labels["app.kubernetes.io/instance"] + - exists: + path: metadata.labels["app.kubernetes.io/version"] + - exists: + path: metadata.labels["app.kubernetes.io/component"] + - it: should add executor.labels to every object, and serviceLabels to the Service + set: + executor: + queueName: batches + configureRbac: true + labels: + example.com/service: executor + serviceLabels: + example.com/service: executor + asserts: + - equal: + path: metadata.labels["example.com/service"] + value: executor diff --git a/charts/sourcegraph-migrator/tests/labels_test.yaml b/charts/sourcegraph-migrator/tests/labels_test.yaml index 57f3df51e..10fdbe013 100644 --- a/charts/sourcegraph-migrator/tests/labels_test.yaml +++ b/charts/sourcegraph-migrator/tests/labels_test.yaml @@ -14,5 +14,16 @@ tests: path: metadata.labels content: app.kubernetes.io/managed-by: Helm + deploy: sourcegraph example.com/installation: production example.com/project: sourcegraph + - exists: + path: metadata.labels["helm.sh/chart"] + - exists: + path: metadata.labels["app.kubernetes.io/name"] + - exists: + path: metadata.labels["app.kubernetes.io/instance"] + - exists: + path: metadata.labels["app.kubernetes.io/version"] + - exists: + path: metadata.labels["app.kubernetes.io/component"] diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index 7a656bd67..909159b4a 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -10,6 +10,8 @@ Use `**BREAKING**:` to denote a breaking change - Added `frontend.internalServiceAnnotations` and `frontend.internalServiceLabels` for the `sourcegraph-frontend-internal` Service. That Service no longer renders `frontend.serviceAnnotations` and `frontend.serviceLabels`, which now apply to the `sourcegraph-frontend` Service only, so load balancer annotations or a service mesh label set for the external Service no longer land on the internal one. If you relied on them on the internal Service, set the new values. - 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. +- Every object the chart creates now has the `deploy` and `app.kubernetes.io/component` labels. PodDisruptionBudgets get the component of their workload, PriorityClasses get `priority-class`, the StorageClass gets `storage` and keeps `deploy: sourcegraph-storage`, and the `sg-test-connection` Pod gets `test-connection`. `extraResources` get `deploy: sourcegraph` unless they set their own; set `app.kubernetes.io/component` on them yourself. The `jaeger` ConfigMap, Deployment, and Services gain `app.kubernetes.io/instance` and keep `app.kubernetes.io/name: jaeger`, which their selectors use. Labels on these objects can be changed in place; the `jaeger` pod restarts once, because its `checksum/jaeger-config` annotation covers the ConfigMap's labels. +- `.labels` is now also rendered on the component's ConfigMaps, Secrets, and PodDisruptionBudget, not only on its workload, so releases that set it gain these labels on upgrade. Added `storageClass.labels` and a `labels` field on each `priorityClasses` entry. - Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. - `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 rendered on every object the chart creates: also on Services, ConfigMaps, Secrets, the Ingress, PodDisruptionBudgets, PriorityClasses, and `extraResources`, so existing releases gain these labels on upgrade. Labels that an `extraResources` entry or `serviceLabels` set take precedence. Labels on these objects can be changed in place, so nothing is recreated or restarted. Prometheus copies the labels of a Service to the metrics it scrapes from it, so labels set in `sourcegraph.labels` now appear on those metrics, as `sourcegraph.serviceLabels` and `.serviceLabels` already do. The bundled Prometheus configuration drops the chart's standard labels instead, because `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade; the `otel-collector` metrics, the only ones that had them, lose them. If you set `prometheus.existingConfig`, add the same `labeldrop` rule after each `__meta_kubernetes_service_label_(.+)` `labelmap` rule in your `prometheus.yml`, as in the [k3s example](examples/prometheus/prometheus-override-k3s.ConfigMap.yaml). - Added `storageLabels` on `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, and `redisStore` to label each component's PersistentVolumeClaim, and `.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). diff --git a/charts/sourcegraph/README.md b/charts/sourcegraph/README.md index b758dc816..5dd7341a8 100644 --- a/charts/sourcegraph/README.md +++ b/charts/sourcegraph/README.md @@ -109,6 +109,8 @@ existing objects have: component. The PersistentVolumeClaims that Kubernetes creates from a template are not among them. See [PersistentVolumeClaim labels](#persistentvolumeclaim-labels). +- `.labels` adds labels to one component's workload, ConfigMaps, + Secrets, and PodDisruptionBudget. - `sourcegraph.serviceLabels` and `.serviceLabels` add labels to every Service, or to one component's Services. - `.storageLabels` adds labels to the PersistentVolumeClaim of @@ -257,7 +259,7 @@ In addition to the documented values, all services also support the following va | codeIntelDB.storageLabels | object | `{}` | Optional labels to add to the `codeintel-db` PVC, in addition to `sourcegraph.labels` | | codeIntelDB.storageSize | string | `"200Gi"` | PVC Storage Request for `codeintel-db` data volume | | codeIntelDB.storageSubPath | string | `""` | Optional subPath for the `codeintel-db` primary data volume mount | -| extraResources | list | `[]` | Additional resources to include in the rendered manifest. Templates are supported. `sourcegraph.labels` and the chart's standard labels are added to each resource; labels the resource sets itself take precedence. | +| extraResources | list | `[]` | Additional resources to include in the rendered manifest. Templates are supported. `sourcegraph.labels`, the chart's standard labels, and `deploy: sourcegraph` are added to each resource; labels the resource sets itself take precedence. | | frontend.command | list | `[]` | Command for the `frontend` container, as a list, replacing the image's entrypoint, e.g. a shell wrapper that exports credentials read from mounted files before starting `frontend`. `frontend.args` (default `["serve"]`) is still passed as the arguments. | | frontend.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"readOnlyRootFilesystem":true,"runAsGroup":101,"runAsUser":100}` | Security context for the `frontend` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) | | frontend.createRoleBinding | bool | `true` | Disable the roleBinding resource for deployment environments blocking RBAC, ex. OpenShift's default "secure" SCC | @@ -452,7 +454,7 @@ In addition to the documented values, all services also support the following va | 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) | | 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). | | 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. | -| 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" | +| 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" labels: {} | | prometheus.containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"readOnlyRootFilesystem":false,"runAsGroup":100,"runAsUser":100}` | Security context for the `prometheus` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) | | prometheus.createRoleBinding | bool | `true` | Disable the creation of a RoleBinding object, for customers who block all RBAC resource creation | | prometheus.enabled | bool | `true` | Enable `prometheus` (recommended) | @@ -557,6 +559,7 @@ In addition to the documented values, all services also support the following va | sourcegraph.tolerations | list | `[]` | Global Tolerations, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/) | | storageClass.allowedTopologies | list | `[]` | Persistent volumes topology configuration, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/#allowed-topologies) | | storageClass.create | bool | `true` | Enable creation of storageClass. Disable if you have your own existing storage class | +| storageClass.labels | object | `{}` | Add extra labels to the storageClass, in addition to `sourcegraph.labels` | | storageClass.name | string | `"sourcegraph"` | Name of the storageClass. Use to customize to the existing storage class name | | storageClass.parameters | object | `{}` | Extra parameters of storageClass, consult your cloud provider persistent storage documentation | | storageClass.provisioner | string | `"kubernetes.io/gce-pd"` | Name of the storageClass provisioner, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/#provisioner) and consult your cloud provider persistent storage documentation | diff --git a/charts/sourcegraph/README.md.gotmpl b/charts/sourcegraph/README.md.gotmpl index 2f3f3ad7c..25119c561 100644 --- a/charts/sourcegraph/README.md.gotmpl +++ b/charts/sourcegraph/README.md.gotmpl @@ -109,6 +109,8 @@ existing objects have: component. The PersistentVolumeClaims that Kubernetes creates from a template are not among them. See [PersistentVolumeClaim labels](#persistentvolumeclaim-labels). +- `.labels` adds labels to one component's workload, ConfigMaps, + Secrets, and PodDisruptionBudget. - `sourcegraph.serviceLabels` and `.serviceLabels` add labels to every Service, or to one component's Services. - `.storageLabels` adds labels to the PersistentVolumeClaim of diff --git a/charts/sourcegraph/templates/_helpers.tpl b/charts/sourcegraph/templates/_helpers.tpl index 368e956fc..d3ad00f2f 100644 --- a/charts/sourcegraph/templates/_helpers.tpl +++ b/charts/sourcegraph/templates/_helpers.tpl @@ -190,6 +190,7 @@ Jaeger common labels {{- define "sourcegraph.jaeger.labels" -}} helm.sh/chart: {{ include "sourcegraph.chart" . }} {{ include "sourcegraph.jaeger.selectorLabels" . }} +app.kubernetes.io/instance: {{ .Release.Name }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} diff --git a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ConfigMap.yaml b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ConfigMap.yaml index 64f2ef3df..e36447fd7 100644 --- a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ConfigMap.yaml +++ b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.ConfigMap.yaml @@ -9,6 +9,9 @@ metadata: description: Configuration for Code Insights labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.codeInsightsDB.labels }} + {{- toYaml .Values.codeInsightsDB.labels | nindent 4 }} + {{- end }} app.kubernetes.io/component: codeinsights-db deploy: sourcegraph name: {{ .Values.codeInsightsDB.name }}-conf diff --git a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml index 946b5c8c8..5456333e8 100644 --- a/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml +++ b/charts/sourcegraph/templates/codeinsights-db/codeinsights-db.Secret.yaml @@ -5,6 +5,9 @@ metadata: name: {{ .Values.codeInsightsDB.name }}-auth labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.codeInsightsDB.labels }} + {{- toYaml .Values.codeInsightsDB.labels | nindent 4 }} + {{- end }} app: codeinsights-db deploy: sourcegraph app.kubernetes.io/component: codeinsights-db diff --git a/charts/sourcegraph/templates/codeintel-db/codeintel-db.ConfigMap.yaml b/charts/sourcegraph/templates/codeintel-db/codeintel-db.ConfigMap.yaml index 8929204a3..adba5ddaa 100644 --- a/charts/sourcegraph/templates/codeintel-db/codeintel-db.ConfigMap.yaml +++ b/charts/sourcegraph/templates/codeintel-db/codeintel-db.ConfigMap.yaml @@ -9,6 +9,9 @@ metadata: description: Configuration for PostgreSQL labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.codeIntelDB.labels }} + {{- toYaml .Values.codeIntelDB.labels | nindent 4 }} + {{- end }} app.kubernetes.io/component: codeintel-db deploy: sourcegraph name: {{ .Values.codeIntelDB.name }}-conf diff --git a/charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml b/charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml index 47743ab5f..19aba9ec0 100644 --- a/charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml +++ b/charts/sourcegraph/templates/codeintel-db/codeintel-db.Secret.yaml @@ -5,6 +5,9 @@ metadata: name: {{ .Values.codeIntelDB.name }}-auth labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.codeIntelDB.labels }} + {{- toYaml .Values.codeIntelDB.labels | nindent 4 }} + {{- end }} app: codeintel-db deploy: sourcegraph app.kubernetes.io/component: codeintel-db diff --git a/charts/sourcegraph/templates/extraResources.yaml b/charts/sourcegraph/templates/extraResources.yaml index a17aa5feb..65b16e154 100644 --- a/charts/sourcegraph/templates/extraResources.yaml +++ b/charts/sourcegraph/templates/extraResources.yaml @@ -1,4 +1,5 @@ {{- $labels := include "sourcegraph.labels" $ | fromYaml }} +{{- $_ := set $labels "deploy" "sourcegraph" }} {{- range .Values.extraResources }} {{- $resource := . }} {{- if kindIs "map" . }} diff --git a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.PodDisruptionBudget.yaml index 967599941..4de9d3abb 100644 --- a/charts/sourcegraph/templates/frontend/sourcegraph-frontend.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/frontend/sourcegraph-frontend.PodDisruptionBudget.yaml @@ -4,6 +4,11 @@ kind: PodDisruptionBudget metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.frontend.labels }} + {{- toYaml .Values.frontend.labels | nindent 4 }} + {{- end }} + deploy: sourcegraph + app.kubernetes.io/component: frontend name: sourcegraph-frontend spec: {{- toYaml .Values.frontend.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/gitserver/gitserver.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/gitserver/gitserver.PodDisruptionBudget.yaml index 45187f5b1..74e4f945c 100644 --- a/charts/sourcegraph/templates/gitserver/gitserver.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/gitserver/gitserver.PodDisruptionBudget.yaml @@ -4,6 +4,11 @@ kind: PodDisruptionBudget metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.gitserver.labels }} + {{- toYaml .Values.gitserver.labels | nindent 4 }} + {{- end }} + deploy: sourcegraph + app.kubernetes.io/component: gitserver name: {{ .Values.gitserver.name }} spec: {{- toYaml .Values.gitserver.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/grafana/grafana.ConfigMap.yaml b/charts/sourcegraph/templates/grafana/grafana.ConfigMap.yaml index 82b1047d3..cea554d44 100644 --- a/charts/sourcegraph/templates/grafana/grafana.ConfigMap.yaml +++ b/charts/sourcegraph/templates/grafana/grafana.ConfigMap.yaml @@ -29,6 +29,9 @@ kind: ConfigMap metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.grafana.labels }} + {{- toYaml .Values.grafana.labels | nindent 4 }} + {{- end }} deploy: sourcegraph app.kubernetes.io/component: grafana name: {{ .Values.grafana.name }} diff --git a/charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml b/charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml index fe5d189e2..96ad14866 100644 --- a/charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml +++ b/charts/sourcegraph/templates/grafana/grafana.pgsql.Secret.yaml @@ -4,6 +4,9 @@ kind: Secret metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.grafana.labels }} + {{- toYaml .Values.grafana.labels | nindent 4 }} + {{- end }} app: grafana deploy: sourcegraph app.kubernetes.io/component: grafana diff --git a/charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml index 6cab4253f..00f9d2594 100644 --- a/charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/indexed-search/indexed-search.PodDisruptionBudget.yaml @@ -4,6 +4,11 @@ kind: PodDisruptionBudget metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.indexedSearch.labels }} + {{- toYaml .Values.indexedSearch.labels | nindent 4 }} + {{- end }} + deploy: sourcegraph + app.kubernetes.io/component: indexed-search name: {{ .Values.indexedSearch.name }} spec: {{- toYaml .Values.indexedSearch.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/jaeger/jaeger.ConfigMap.yaml b/charts/sourcegraph/templates/jaeger/jaeger.ConfigMap.yaml index 7e2a388cf..168d482d8 100644 --- a/charts/sourcegraph/templates/jaeger/jaeger.ConfigMap.yaml +++ b/charts/sourcegraph/templates/jaeger/jaeger.ConfigMap.yaml @@ -4,6 +4,9 @@ kind: ConfigMap metadata: labels: {{- include "sourcegraph.jaeger.labels" . | nindent 4 }} + {{- if .Values.jaeger.labels }} + {{- toYaml .Values.jaeger.labels | nindent 4 }} + {{- end }} deploy: sourcegraph app.kubernetes.io/component: all-in-one app: jaeger diff --git a/charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml b/charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml index 62234a958..4f67eb4e3 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-agent.ConfigMap.yaml @@ -6,6 +6,9 @@ metadata: name: {{ .Values.openTelemetry.agent.name }} labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.openTelemetry.agent.labels }} + {{- toYaml .Values.openTelemetry.agent.labels | nindent 4 }} + {{- end }} deploy: sourcegraph app.kubernetes.io/component: otel-collector data: diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml index b73b64048..6151ae49d 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml @@ -8,6 +8,9 @@ metadata: name: {{ .Values.openTelemetry.gateway.name }} labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.openTelemetry.gateway.labels }} + {{- toYaml .Values.openTelemetry.gateway.labels | nindent 4 }} + {{- end }} deploy: sourcegraph app.kubernetes.io/component: otel-collector data: diff --git a/charts/sourcegraph/templates/pgsql/pgsql.ConfigMap.yaml b/charts/sourcegraph/templates/pgsql/pgsql.ConfigMap.yaml index 4b44ca8bf..f4ea8ad8d 100644 --- a/charts/sourcegraph/templates/pgsql/pgsql.ConfigMap.yaml +++ b/charts/sourcegraph/templates/pgsql/pgsql.ConfigMap.yaml @@ -9,6 +9,9 @@ metadata: description: Configuration for PostgreSQL labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.pgsql.labels }} + {{- toYaml .Values.pgsql.labels | nindent 4 }} + {{- end }} deploy: sourcegraph app.kubernetes.io/component: pgsql name: {{ .Values.pgsql.name }}-conf diff --git a/charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml b/charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml index 4a1b868f6..4d6972d29 100644 --- a/charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml +++ b/charts/sourcegraph/templates/pgsql/pgsql.Secret.yaml @@ -4,6 +4,9 @@ kind: Secret metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.pgsql.labels }} + {{- toYaml .Values.pgsql.labels | nindent 4 }} + {{- end }} app: pgsql deploy: sourcegraph app.kubernetes.io/component: pgsql diff --git a/charts/sourcegraph/templates/precise-code-intel/worker.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/precise-code-intel/worker.PodDisruptionBudget.yaml index daf8d759a..6b5701265 100644 --- a/charts/sourcegraph/templates/precise-code-intel/worker.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/precise-code-intel/worker.PodDisruptionBudget.yaml @@ -4,6 +4,11 @@ kind: PodDisruptionBudget metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.preciseCodeIntel.labels }} + {{- toYaml .Values.preciseCodeIntel.labels | nindent 4 }} + {{- end }} + deploy: sourcegraph + app.kubernetes.io/component: precise-code-intel name: {{ .Values.preciseCodeIntel.name }} spec: {{- toYaml .Values.preciseCodeIntel.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/priorityClass.yaml b/charts/sourcegraph/templates/priorityClass.yaml index fb52d5066..194908530 100644 --- a/charts/sourcegraph/templates/priorityClass.yaml +++ b/charts/sourcegraph/templates/priorityClass.yaml @@ -4,6 +4,11 @@ kind: PriorityClass metadata: labels: {{- include "sourcegraph.labels" $ | nindent 4 }} + {{- with $class.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + deploy: sourcegraph + app.kubernetes.io/component: priority-class name: {{ $class.name }} value: {{ $class.value }} preemptionPolicy: {{ $class.preemptionPolicy }} diff --git a/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml b/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml index 18ff6679b..1746e18df 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml @@ -4,6 +4,9 @@ kind: ConfigMap metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.prometheus.labels }} + {{- toYaml .Values.prometheus.labels | nindent 4 }} + {{- end }} deploy: sourcegraph app.kubernetes.io/component: prometheus name: {{ .Values.prometheus.name }} diff --git a/charts/sourcegraph/templates/redis/redis-cache.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/redis/redis-cache.PodDisruptionBudget.yaml index 2630e233e..d7a93ecee 100644 --- a/charts/sourcegraph/templates/redis/redis-cache.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/redis/redis-cache.PodDisruptionBudget.yaml @@ -4,6 +4,11 @@ kind: PodDisruptionBudget metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.redisCache.labels }} + {{- toYaml .Values.redisCache.labels | nindent 4 }} + {{- end }} + deploy: sourcegraph + app.kubernetes.io/component: redis name: {{ .Values.redisCache.name }} spec: {{- toYaml .Values.redisCache.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/redis/redis-cache.Secret.yaml b/charts/sourcegraph/templates/redis/redis-cache.Secret.yaml index f6d1db18c..d9ce1ea2f 100644 --- a/charts/sourcegraph/templates/redis/redis-cache.Secret.yaml +++ b/charts/sourcegraph/templates/redis/redis-cache.Secret.yaml @@ -4,6 +4,9 @@ kind: Secret metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.redisCache.labels }} + {{- toYaml .Values.redisCache.labels | nindent 4 }} + {{- end }} app: redis-cache deploy: sourcegraph app.kubernetes.io/component: redis-cache diff --git a/charts/sourcegraph/templates/redis/redis-store.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/redis/redis-store.PodDisruptionBudget.yaml index 84e4792e0..cd975b958 100644 --- a/charts/sourcegraph/templates/redis/redis-store.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.PodDisruptionBudget.yaml @@ -4,6 +4,11 @@ kind: PodDisruptionBudget metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.redisStore.labels }} + {{- toYaml .Values.redisStore.labels | nindent 4 }} + {{- end }} + deploy: sourcegraph + app.kubernetes.io/component: redis name: {{ .Values.redisStore.name }} spec: {{- toYaml .Values.redisStore.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/redis/redis-store.Secret.yaml b/charts/sourcegraph/templates/redis/redis-store.Secret.yaml index 4fc2ee3b7..4f15cf014 100644 --- a/charts/sourcegraph/templates/redis/redis-store.Secret.yaml +++ b/charts/sourcegraph/templates/redis/redis-store.Secret.yaml @@ -4,6 +4,9 @@ kind: Secret metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.redisStore.labels }} + {{- toYaml .Values.redisStore.labels | nindent 4 }} + {{- end }} app: redis-store deploy: sourcegraph app.kubernetes.io/component: redis-store diff --git a/charts/sourcegraph/templates/searcher/searcher.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/searcher/searcher.PodDisruptionBudget.yaml index 462428391..952e4e85d 100644 --- a/charts/sourcegraph/templates/searcher/searcher.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/searcher/searcher.PodDisruptionBudget.yaml @@ -4,6 +4,11 @@ kind: PodDisruptionBudget metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.searcher.labels }} + {{- toYaml .Values.searcher.labels | nindent 4 }} + {{- end }} + deploy: sourcegraph + app.kubernetes.io/component: searcher name: {{ .Values.searcher.name }} spec: {{- toYaml .Values.searcher.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/storageclass.yaml b/charts/sourcegraph/templates/storageclass.yaml index a3af7c53d..3c2231ac9 100644 --- a/charts/sourcegraph/templates/storageclass.yaml +++ b/charts/sourcegraph/templates/storageclass.yaml @@ -5,7 +5,11 @@ metadata: name: {{ .Values.storageClass.name }} labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- with .Values.storageClass.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} deploy: sourcegraph-storage + app.kubernetes.io/component: storage {{- if .Values.storageClass.annotations}} annotations: {{- toYaml .Values.storageClass.annotations | nindent 4 }} diff --git a/charts/sourcegraph/templates/syntactic-code-intel/worker.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/syntactic-code-intel/worker.PodDisruptionBudget.yaml index b6d39710d..0951155aa 100644 --- a/charts/sourcegraph/templates/syntactic-code-intel/worker.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/syntactic-code-intel/worker.PodDisruptionBudget.yaml @@ -4,6 +4,11 @@ kind: PodDisruptionBudget metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.syntacticCodeIntel.labels }} + {{- toYaml .Values.syntacticCodeIntel.labels | nindent 4 }} + {{- end }} + deploy: sourcegraph + app.kubernetes.io/component: syntactic-code-intel name: {{ .Values.syntacticCodeIntel.name }} spec: {{- toYaml .Values.syntacticCodeIntel.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/syntect-server/syntect-server.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/syntect-server/syntect-server.PodDisruptionBudget.yaml index 006224328..00e8975e3 100644 --- a/charts/sourcegraph/templates/syntect-server/syntect-server.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/syntect-server/syntect-server.PodDisruptionBudget.yaml @@ -4,6 +4,11 @@ kind: PodDisruptionBudget metadata: labels: {{- include "sourcegraph.labels" . | nindent 4 }} + {{- if .Values.syntectServer.labels }} + {{- toYaml .Values.syntectServer.labels | nindent 4 }} + {{- end }} + deploy: sourcegraph + app.kubernetes.io/component: syntect-server name: {{ .Values.syntectServer.name }} spec: {{- toYaml .Values.syntectServer.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/templates/tests/test-connection.yaml b/charts/sourcegraph/templates/tests/test-connection.yaml index 3aafe14f7..73a24f217 100644 --- a/charts/sourcegraph/templates/tests/test-connection.yaml +++ b/charts/sourcegraph/templates/tests/test-connection.yaml @@ -6,6 +6,8 @@ metadata: "helm.sh/hook": test labels: {{- include "sourcegraph.labels" . | nindent 4 }} + deploy: sourcegraph + app.kubernetes.io/component: test-connection name: "sg-test-connection" spec: containers: diff --git a/charts/sourcegraph/templates/worker/worker.PodDisruptionBudget.yaml b/charts/sourcegraph/templates/worker/worker.PodDisruptionBudget.yaml index a58d99308..004c65e59 100644 --- a/charts/sourcegraph/templates/worker/worker.PodDisruptionBudget.yaml +++ b/charts/sourcegraph/templates/worker/worker.PodDisruptionBudget.yaml @@ -10,6 +10,11 @@ kind: PodDisruptionBudget metadata: 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: {{- toYaml $top.Values.worker.podDisruptionBudget | nindent 2 }} diff --git a/charts/sourcegraph/tests/allObjectLabels_test.yaml b/charts/sourcegraph/tests/allObjectLabels_test.yaml index b6b2da085..0116544b7 100644 --- a/charts/sourcegraph/tests/allObjectLabels_test.yaml +++ b/charts/sourcegraph/tests/allObjectLabels_test.yaml @@ -1,4 +1,4 @@ -suite: sourcegraph.labels on every object +suite: labels on every object release: name: sourcegraph namespace: sourcegraph @@ -17,7 +17,7 @@ excludeTemplates: tests: # This test fails with "no manifest found" for a template that renders nothing, # so enable a new optional template here. -- it: should add sourcegraph.labels to every object the chart renders +- it: should add sourcegraph.labels and the chart's labels to every object the chart renders set: sourcegraph.labels: &globalLabels example.com/installation: production @@ -79,6 +79,9 @@ tests: kind: NetworkPolicy metadata: name: deny-all + # The chart cannot know which component an extra resource belongs to. + labels: + app.kubernetes.io/component: network-policy spec: podSelector: {} asserts: @@ -86,10 +89,144 @@ tests: path: metadata.labels content: &allLabels helm.sh/chart: sourcegraph-1.2.3 + app.kubernetes.io/instance: sourcegraph app.kubernetes.io/version: 1.2.3 app.kubernetes.io/managed-by: Helm example.com/installation: production example.com/project: sourcegraph + # The values differ per object: jaeger is named `jaeger`, and the StorageClass is `deploy: sourcegraph-storage`. + - exists: + path: metadata.labels["app.kubernetes.io/name"] + - exists: + path: metadata.labels.deploy + - exists: + path: metadata.labels["app.kubernetes.io/component"] + +- it: should add a component's labels to its ConfigMaps, Secrets, and PodDisruptionBudget + templates: + - codeinsights-db/codeinsights-db.ConfigMap.yaml + - codeinsights-db/codeinsights-db.Secret.yaml + - codeintel-db/codeintel-db.ConfigMap.yaml + - codeintel-db/codeintel-db.Secret.yaml + - frontend/sourcegraph-frontend.PodDisruptionBudget.yaml + - gitserver/gitserver.PodDisruptionBudget.yaml + - grafana/grafana.ConfigMap.yaml + - grafana/grafana.pgsql.Secret.yaml + - indexed-search/indexed-search.PodDisruptionBudget.yaml + - jaeger/jaeger.ConfigMap.yaml + - otel-collector/otel-agent.ConfigMap.yaml + - pgsql/pgsql.ConfigMap.yaml + - pgsql/pgsql.Secret.yaml + - precise-code-intel/worker.PodDisruptionBudget.yaml + - prometheus/prometheus.ConfigMap.yaml + - redis/redis-cache.ConfigMap.yaml + - redis/redis-cache.PodDisruptionBudget.yaml + - redis/redis-cache.Secret.yaml + - redis/redis-store.ConfigMap.yaml + - redis/redis-store.PodDisruptionBudget.yaml + - redis/redis-store.Secret.yaml + - searcher/searcher.PodDisruptionBudget.yaml + - syntactic-code-intel/worker.PodDisruptionBudget.yaml + - syntect-server/syntect-server.PodDisruptionBudget.yaml + - worker/worker.PodDisruptionBudget.yaml + set: + codeInsightsDB.labels: &componentLabels + example.com/service: component + codeIntelDB.labels: *componentLabels + frontend.labels: *componentLabels + gitserver.labels: *componentLabels + grafana.labels: *componentLabels + indexedSearch.labels: *componentLabels + jaeger.labels: *componentLabels + openTelemetry.agent.labels: *componentLabels + pgsql.labels: *componentLabels + preciseCodeIntel.labels: *componentLabels + prometheus.labels: *componentLabels + redisCache.labels: *componentLabels + redisStore.labels: *componentLabels + searcher.labels: *componentLabels + syntacticCodeIntel.labels: *componentLabels + syntectServer.labels: *componentLabels + worker.labels: *componentLabels + jaeger.enabled: true + syntacticCodeIntel.enabled: true + redisCache.config.enabled: true + redisStore.config.enabled: true + grafana.auth: + database: grafana + host: pgsql + password: password + port: "5432" + sslmode: disable + user: grafana + worker.replicas: + - jobs: [codeintel-upload-janitor] + frontend.podDisruptionBudget: *podDisruptionBudget + gitserver.podDisruptionBudget: *podDisruptionBudget + indexedSearch.podDisruptionBudget: *podDisruptionBudget + preciseCodeIntel.podDisruptionBudget: *podDisruptionBudget + redisCache.podDisruptionBudget: *podDisruptionBudget + redisStore.podDisruptionBudget: *podDisruptionBudget + searcher.podDisruptionBudget: *podDisruptionBudget + syntacticCodeIntel.podDisruptionBudget: *podDisruptionBudget + syntectServer.podDisruptionBudget: *podDisruptionBudget + worker.podDisruptionBudget: *podDisruptionBudget + asserts: + - isSubset: + path: metadata.labels + content: + example.com/service: component + +- it: should label a PodDisruptionBudget with the component of its workload + templates: + - redis/redis-store.Deployment.yaml + - redis/redis-store.PodDisruptionBudget.yaml + - syntactic-code-intel/worker.Deployment.yaml + - syntactic-code-intel/worker.PodDisruptionBudget.yaml + set: + syntacticCodeIntel.enabled: true + redisStore.podDisruptionBudget: *podDisruptionBudget + syntacticCodeIntel.podDisruptionBudget: *podDisruptionBudget + asserts: + - equal: + path: metadata.labels["app.kubernetes.io/component"] + value: redis + template: redis/redis-store.Deployment.yaml + - equal: + path: metadata.labels["app.kubernetes.io/component"] + value: redis + template: redis/redis-store.PodDisruptionBudget.yaml + - equal: + path: metadata.labels["app.kubernetes.io/component"] + value: syntactic-code-intel + template: syntactic-code-intel/worker.Deployment.yaml + - equal: + path: metadata.labels["app.kubernetes.io/component"] + value: syntactic-code-intel + template: syntactic-code-intel/worker.PodDisruptionBudget.yaml + +- it: should add the labels of a priority class and of the storage class + templates: + - priorityClass.yaml + - storageclass.yaml + set: + storageClass.create: true + storageClass.labels: + example.com/service: storage + priorityClasses: + - name: gitserver-class + value: 1000000 + labels: + example.com/service: gitserver + asserts: + - equal: + path: metadata.labels["example.com/service"] + value: gitserver + template: priorityClass.yaml + - equal: + path: metadata.labels["example.com/service"] + value: storage + template: storageclass.yaml - it: should keep the labels a Service already has templates: @@ -121,6 +258,7 @@ tests: value: helm.sh/chart: sourcegraph-1.2.3 app.kubernetes.io/name: jaeger + app.kubernetes.io/instance: sourcegraph app.kubernetes.io/version: 1.2.3 app.kubernetes.io/managed-by: Helm example.com/installation: production @@ -156,6 +294,7 @@ tests: example.com/installation: production example.com/project: extra example.com/release: sourcegraph + deploy: sourcegraph - it: should not copy the chart's version labels from Services to metrics template: prometheus/prometheus.ConfigMap.yaml @@ -185,12 +324,23 @@ tests: openTelemetry.gateway.config.traces.exporters: otlp: endpoint: collector.example.com:4317 + openTelemetry.gateway.labels: + example.com/service: otel-collector asserts: - isSubset: path: metadata.labels content: helm.sh/chart: sourcegraph-1.2.3 + app.kubernetes.io/instance: sourcegraph app.kubernetes.io/version: 1.2.3 app.kubernetes.io/managed-by: Helm example.com/installation: production example.com/project: sourcegraph + - exists: + path: metadata.labels.deploy + - exists: + path: metadata.labels["app.kubernetes.io/component"] + - equal: + path: metadata.labels["example.com/service"] + value: otel-collector + template: otel-collector/otel-collector.ConfigMap.yaml diff --git a/charts/sourcegraph/values.yaml b/charts/sourcegraph/values.yaml index 485b2b334..bbfa93c99 100644 --- a/charts/sourcegraph/values.yaml +++ b/charts/sourcegraph/values.yaml @@ -71,7 +71,8 @@ sourcegraph: # # Override the global sourcegraph.image.repository on a service-specific basis # repository: # -# # Add additional labels and annotations to various resources +# # Add additional labels and annotations to various resources. +# # `labels` is added to the component's workload, ConfigMaps, Secrets, and PodDisruptionBudget # labels: {} # podLabels: {} # podAnnotations: {} @@ -1418,6 +1419,8 @@ storageClass: # -- Extra parameters of storageClass, # consult your cloud provider persistent storage documentation parameters: {} + # -- Add extra labels to the storageClass, in addition to `sourcegraph.labels` + labels: {} # -- Persistent volumes topology configuration, # learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/#allowed-topologies) allowedTopologies: [] @@ -1606,8 +1609,9 @@ worker: # -- Name of the ServiceAccount to be created or an existing ServiceAccount name: "" -# -- Additional resources to include in the rendered manifest. Templates are supported. `sourcegraph.labels` and the -# chart's standard labels are added to each resource; labels the resource sets itself take precedence. +# -- Additional resources to include in the rendered manifest. Templates are supported. `sourcegraph.labels`, the +# chart's standard labels, and `deploy: sourcegraph` are added to each resource; labels the resource sets itself take +# precedence. extraResources: [] # -- Additional priorityClasses minimize re-scheduling downtime for StatefulSets. Each StatefulSets might use different priority class. @@ -1617,6 +1621,7 @@ extraResources: [] # value: 100 # preemptionPolicy: Never # description: "gitserver priority class" +# labels: {} priorityClasses: [] # -- Enable the busybox connection test after deployment From 56deff2383fc07db158e8923ee2797fe607353e7 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 11 Nov 2026 19:39:07 +0000 Subject: [PATCH 04/18] Keep sourcegraph.labels off metrics and label the otel-collector Service with its app The bundled Prometheus copies Service labels to the metrics it scrapes. Now that every Service has sourcegraph.labels, the labeldrop rule also drops those keys, so the labels of Service-scraped metrics stay as they are on main. The rule no longer drops app.kubernetes.io/managed-by: Helm adds that label to every object it installs, so the metrics already had it. The otel-collector Service had no app label, unlike every other scraped Service, so its metrics had no app and job labels and the dashboard's up{app=~".*otel-collector"} panel and alert had no data. Amp-Thread-ID: https://ampcode.com/threads/T-c7c725c9-ed68-48e2-9f2d-0b8c31e76050 Co-authored-by: Amp --- charts/sourcegraph/CHANGELOG.md | 3 +- charts/sourcegraph/README.md | 5 +-- charts/sourcegraph/README.md.gotmpl | 3 +- .../prometheus-override-k3s.ConfigMap.yaml | 16 ++++--- charts/sourcegraph/templates/_helpers.tpl | 23 ++++++++++ .../otel-collector.Service.yaml | 1 + .../prometheus/prometheus.ConfigMap.yaml | 12 +++--- .../tests/allObjectLabels_test.yaml | 43 ++++++++++++++++--- charts/sourcegraph/values.yaml | 4 +- 9 files changed, 84 insertions(+), 26 deletions(-) diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index 909159b4a..08fb06eb9 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -10,10 +10,11 @@ Use `**BREAKING**:` to denote a breaking change - Added `frontend.internalServiceAnnotations` and `frontend.internalServiceLabels` for the `sourcegraph-frontend-internal` Service. That Service no longer renders `frontend.serviceAnnotations` and `frontend.serviceLabels`, which now apply to the `sourcegraph-frontend` Service only, so load balancer annotations or a service mesh label set for the external Service no longer land on the internal one. If you relied on them on the internal Service, set the new values. - 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. +- Fixed the `otel-collector` Service missing the `app` label that every other scraped Service has. Its metrics had no `app` and `job` labels, so the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, had no data. Its metrics now have `app="otel-collector"` and `job="otel-collector"`. - Every object the chart creates now has the `deploy` and `app.kubernetes.io/component` labels. PodDisruptionBudgets get the component of their workload, PriorityClasses get `priority-class`, the StorageClass gets `storage` and keeps `deploy: sourcegraph-storage`, and the `sg-test-connection` Pod gets `test-connection`. `extraResources` get `deploy: sourcegraph` unless they set their own; set `app.kubernetes.io/component` on them yourself. The `jaeger` ConfigMap, Deployment, and Services gain `app.kubernetes.io/instance` and keep `app.kubernetes.io/name: jaeger`, which their selectors use. Labels on these objects can be changed in place; the `jaeger` pod restarts once, because its `checksum/jaeger-config` annotation covers the ConfigMap's labels. - `.labels` is now also rendered on the component's ConfigMaps, Secrets, and PodDisruptionBudget, not only on its workload, so releases that set it gain these labels on upgrade. Added `storageClass.labels` and a `labels` field on each `priorityClasses` entry. - Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. -- `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 rendered on every object the chart creates: also on Services, ConfigMaps, Secrets, the Ingress, PodDisruptionBudgets, PriorityClasses, and `extraResources`, so existing releases gain these labels on upgrade. Labels that an `extraResources` entry or `serviceLabels` set take precedence. Labels on these objects can be changed in place, so nothing is recreated or restarted. Prometheus copies the labels of a Service to the metrics it scrapes from it, so labels set in `sourcegraph.labels` now appear on those metrics, as `sourcegraph.serviceLabels` and `.serviceLabels` already do. The bundled Prometheus configuration drops the chart's standard labels instead, because `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade; the `otel-collector` metrics, the only ones that had them, lose them. If you set `prometheus.existingConfig`, add the same `labeldrop` rule after each `__meta_kubernetes_service_label_(.+)` `labelmap` rule in your `prometheus.yml`, as in the [k3s example](examples/prometheus/prometheus-override-k3s.ConfigMap.yaml). +- `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 rendered on every object the chart creates: also on Services, ConfigMaps, Secrets, the Ingress, PodDisruptionBudgets, PriorityClasses, and `extraResources`, so existing releases gain these labels on upgrade. Labels that an `extraResources` entry or `serviceLabels` set take precedence. Labels on these objects can be changed in place, so nothing is recreated or restarted. Prometheus copies the labels of a Service to the metrics it scrapes from it, so the bundled Prometheus configuration now drops `helm.sh/chart`, `app.kubernetes.io/name`, `app.kubernetes.io/instance`, `app.kubernetes.io/version`, and the keys of `sourcegraph.labels`, which keeps the labels of those metrics as they were. `app.kubernetes.io/managed-by` stays on them: Helm already added it to every Service. Only the `otel-collector` metrics lose labels, because its Service already had these. To add a label to the metrics of a Service, set it in `.serviceLabels`, with a key that is not in `sourcegraph.labels`. Prometheus reads its configuration when it starts, so restart the `prometheus` Deployment after an upgrade that does not replace its pod. If you set `prometheus.existingConfig`, add the same `labeldrop` rule after each `__meta_kubernetes_service_label_(.+)` `labelmap` rule in your `prometheus.yml`, as in the [k3s example](examples/prometheus/prometheus-override-k3s.ConfigMap.yaml), and append the keys of `sourcegraph.labels` to its regex. - Added `storageLabels` on `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, and `redisStore` to label each component's PersistentVolumeClaim, and `.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). - 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. - Added `sourcegraph.selectorLabelsOverride`, `.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). diff --git a/charts/sourcegraph/README.md b/charts/sourcegraph/README.md index 5dd7341a8..e599d14bf 100644 --- a/charts/sourcegraph/README.md +++ b/charts/sourcegraph/README.md @@ -111,8 +111,7 @@ existing objects have: [PersistentVolumeClaim labels](#persistentvolumeclaim-labels). - `.labels` adds labels to one component's workload, ConfigMaps, Secrets, and PodDisruptionBudget. -- `sourcegraph.serviceLabels` and `.serviceLabels` add labels to - every Service, or to one component's Services. +- `.serviceLabels` adds labels to one component's Services. - `.storageLabels` adds labels to the PersistentVolumeClaim of `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, or `redisStore`. @@ -544,7 +543,7 @@ In addition to the documented values, all services also support the following va | sourcegraph.image.repository | string | Sourcegraph's public Docker Hub registry | Global docker image registry or prefix | | sourcegraph.image.useGlobalTagAsDefault | bool | `false` | When set to true, sourcegraph.image.defaultTag is used as the default defaultTag for all services, instead of service-specific default defaultTags | | sourcegraph.imagePullSecrets | list | `[]` | Mount named secrets containing docker credentials | -| sourcegraph.labels | object | `{}` | Add extra labels to every object the chart renders, including `extraResources`. Prometheus copies the labels of a Service to the metrics it scrapes from it, so these labels also appear on those metrics. | +| sourcegraph.labels | object | `{}` | Add extra labels to every object the chart renders, including `extraResources`. The bundled Prometheus does not copy these labels from a Service to the metrics it scrapes from it; use `.serviceLabels` for that. | | sourcegraph.localDevMode | bool | `false` | When true, remove all resource stanzas, allowing the scheduler to best-fit pods. Intended for local development with limited resources. | | sourcegraph.nameOverride | string | `""` | Set a custom name for the app.kubernetes.io/name annotation | | sourcegraph.nodeSelector | object | `{}` | Global NodeSelector, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector) | diff --git a/charts/sourcegraph/README.md.gotmpl b/charts/sourcegraph/README.md.gotmpl index 25119c561..d4fd87164 100644 --- a/charts/sourcegraph/README.md.gotmpl +++ b/charts/sourcegraph/README.md.gotmpl @@ -111,8 +111,7 @@ existing objects have: [PersistentVolumeClaim labels](#persistentvolumeclaim-labels). - `.labels` adds labels to one component's workload, ConfigMaps, Secrets, and PodDisruptionBudget. -- `sourcegraph.serviceLabels` and `.serviceLabels` add labels to - every Service, or to one component's Services. +- `.serviceLabels` adds labels to one component's Services. - `.storageLabels` adds labels to the PersistentVolumeClaim of `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, or `redisStore`. diff --git a/charts/sourcegraph/examples/prometheus/prometheus-override-k3s.ConfigMap.yaml b/charts/sourcegraph/examples/prometheus/prometheus-override-k3s.ConfigMap.yaml index 552b5ef93..45e68abe3 100644 --- a/charts/sourcegraph/examples/prometheus/prometheus-override-k3s.ConfigMap.yaml +++ b/charts/sourcegraph/examples/prometheus/prometheus-override-k3s.ConfigMap.yaml @@ -98,10 +98,12 @@ data: replacement: $1:$2 - action: labelmap regex: __meta_kubernetes_service_label_(.+) - # Sourcegraph specific customization. Do not copy the chart's standard labels from the Service to every - # metric: `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. + # Sourcegraph specific customization. Do not copy the labels the chart adds to every Service to every + # metric: `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. If you set + # `sourcegraph.labels`, append its keys, with `_` for every character that is not a letter, digit, or `_`, + # e.g. `|example_com_project` for `example.com/project`. - action: labeldrop - regex: helm_sh_chart|app_kubernetes_io_(name|instance|version|managed_by) + regex: helm_sh_chart|app_kubernetes_io_(name|instance|version) - source_labels: [__meta_kubernetes_namespace] action: replace target_label: ns @@ -135,10 +137,12 @@ data: target_label: instance - action: labelmap regex: __meta_kubernetes_service_label_(.+) - # Sourcegraph specific customization. Do not copy the chart's standard labels from the Service to every - # metric: `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. + # Sourcegraph specific customization. Do not copy the labels the chart adds to every Service to every + # metric: `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. If you set + # `sourcegraph.labels`, append its keys, with `_` for every character that is not a letter, digit, or `_`, + # e.g. `|example_com_project` for `example.com/project`. - action: labeldrop - regex: helm_sh_chart|app_kubernetes_io_(name|instance|version|managed_by) + regex: helm_sh_chart|app_kubernetes_io_(name|instance|version) - source_labels: [__meta_kubernetes_service_namespace] target_label: ns - source_labels: [__meta_kubernetes_service_name] diff --git a/charts/sourcegraph/templates/_helpers.tpl b/charts/sourcegraph/templates/_helpers.tpl index d3ad00f2f..b62a144b5 100644 --- a/charts/sourcegraph/templates/_helpers.tpl +++ b/charts/sourcegraph/templates/_helpers.tpl @@ -28,6 +28,29 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end }} {{- end }} +{{/* +Regex of the Service labels that the bundled Prometheus must not copy to the +metrics it scrapes: the labels this chart adds to every Service and the keys of +`sourcegraph.labels`, spelled as Prometheus spells them, with `_` for every +character outside `[a-zA-Z0-9_]`. This keeps the labels of those metrics as +they were before the chart labelled its Services. + +Labels that were already on Services are kept: the ones the chart sets, such as +`app`, which dashboards and alerts query, and `app.kubernetes.io/managed-by`, +which Helm adds to every object it installs. +*/}} +{{- define "sourcegraph.prometheus.droppedServiceLabels" -}} +{{- $names := list "helm_sh_chart" "app_kubernetes_io_(name|instance|version)" -}} +{{- $kept := list "app" "deploy" "type" "app_kubernetes_io_component" "app_kubernetes_io_managed_by" "sourcegraph_resource_requires" -}} +{{- range $key := keys (.Values.sourcegraph.labels | default dict) | sortAlpha -}} +{{- $name := regexReplaceAll "[^a-zA-Z0-9_]" $key "_" -}} +{{- if not (has $name $kept) -}} +{{- $names = append $names $name -}} +{{- end -}} +{{- end -}} +{{- $names | uniq | join "|" -}} +{{- end }} + {{/* Selector labels, shared by a component's workload selector, pod labels, and Service and PodDisruptionBudget selectors, so they cannot drift apart. diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.Service.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.Service.yaml index 9b5e03bc8..bb321fdf6 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.Service.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.Service.yaml @@ -10,6 +10,7 @@ metadata: {{- end }} labels: {{- include "sourcegraph.labels" . | nindent 4 }} + app: otel-collector {{- if .Values.openTelemetry.gateway.serviceLabels }} {{- toYaml .Values.openTelemetry.gateway.serviceLabels | nindent 4 }} {{- end }} diff --git a/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml b/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml index 1746e18df..88e7a8821 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.ConfigMap.yaml @@ -164,10 +164,10 @@ data: replacement: $1:$2 - action: labelmap regex: __meta_kubernetes_service_label_(.+) - # Sourcegraph specific customization. Do not copy the chart's standard labels from the Service to every - # metric: `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. + # Sourcegraph specific customization. Do not copy the labels the chart adds to every Service, or + # `sourcegraph.labels`, to every metric: `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. - action: labeldrop - regex: helm_sh_chart|app_kubernetes_io_(name|instance|version|managed_by) + regex: {{ include "sourcegraph.prometheus.droppedServiceLabels" . }} - source_labels: [__meta_kubernetes_namespace] action: replace # Sourcegraph specific customization. We want a more convenient to type label. @@ -222,10 +222,10 @@ data: target_label: instance - action: labelmap regex: __meta_kubernetes_service_label_(.+) - # Sourcegraph specific customization. Do not copy the chart's standard labels from the Service to every - # metric: `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. + # Sourcegraph specific customization. Do not copy the labels the chart adds to every Service, or + # `sourcegraph.labels`, to every metric: `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. - action: labeldrop - regex: helm_sh_chart|app_kubernetes_io_(name|instance|version|managed_by) + regex: {{ include "sourcegraph.prometheus.droppedServiceLabels" . }} - source_labels: [__meta_kubernetes_service_namespace] # Sourcegraph specific customization. We want a more convenient to type label. # target_label: kubernetes_namespace diff --git a/charts/sourcegraph/tests/allObjectLabels_test.yaml b/charts/sourcegraph/tests/allObjectLabels_test.yaml index 0116544b7..efc05cbf9 100644 --- a/charts/sourcegraph/tests/allObjectLabels_test.yaml +++ b/charts/sourcegraph/tests/allObjectLabels_test.yaml @@ -296,13 +296,14 @@ tests: example.com/release: sourcegraph deploy: sourcegraph -- it: should not copy the chart's version labels from Services to metrics - template: prometheus/prometheus.ConfigMap.yaml +# Prometheus derives the `app` and `job` labels of a Service's metrics from its +# `app` label, and the "pods available" alert queries `up{app=~".*otel-collector"}`. +- it: should label the otel-collector Service with its app, like every other scraped Service + template: otel-collector/otel-collector.Service.yaml asserts: - - matchRegex: - path: data["prometheus.yml"] - # Both jobs that map Service labels to metric labels drop the chart's labels afterwards. - pattern: (?s)(regex. __meta_kubernetes_service_label_\(\.\+\)\n(\s*#[^\n]*\n)*\s*- action. labeldrop\n\s*regex. helm_sh_chart\|app_kubernetes_io_\(name\|instance\|version\|managed_by\)\n.*){2} + - equal: + path: metadata.labels.app + value: otel-collector --- suite: sourcegraph.labels on the objects that replace others release: @@ -344,3 +345,33 @@ tests: path: metadata.labels["example.com/service"] value: otel-collector template: otel-collector/otel-collector.ConfigMap.yaml +--- +suite: Service labels that Prometheus does not copy to metrics +templates: +- prometheus/prometheus.ConfigMap.yaml +tests: +# The dashboards and alerts were written for metrics without these labels, and +# `helm.sh/chart` and `app.kubernetes.io/version` change on every upgrade. +- it: should not copy the labels the chart adds to every Service to metrics + asserts: + - matchRegex: + path: data["prometheus.yml"] + # Both jobs that map Service labels to metric labels drop the chart's labels afterwards. + # `app.kubernetes.io/managed-by` is not dropped: Helm adds it to every object it installs, + # so the metrics already had it. + pattern: (?s)(regex. __meta_kubernetes_service_label_\(\.\+\)\n(\s*#[^\n]*\n)*\s*- action. labeldrop\n\s*regex. helm_sh_chart\|app_kubernetes_io_\(name\|instance\|version\)\n.*){2} + +- it: should not copy sourcegraph.labels from Services to metrics + set: + sourcegraph.labels: + team: platform + example.com/project: sourcegraph + cost-center: "1234" + # Labels the chart sets on Services stay on metrics: `job` is derived from `app`. + app: sourcegraph + type: internal + asserts: + - matchRegex: + path: data["prometheus.yml"] + # Prometheus replaces every character of a label key outside [a-zA-Z0-9_] with `_`. + pattern: (?s)(regex. __meta_kubernetes_service_label_\(\.\+\)\n(\s*#[^\n]*\n)*\s*- action. labeldrop\n\s*regex. helm_sh_chart\|app_kubernetes_io_\(name\|instance\|version\)\|cost_center\|example_com_project\|team\n.*){2} diff --git a/charts/sourcegraph/values.yaml b/charts/sourcegraph/values.yaml index bbfa93c99..3bc6cda5e 100644 --- a/charts/sourcegraph/values.yaml +++ b/charts/sourcegraph/values.yaml @@ -15,8 +15,8 @@ sourcegraph: useGlobalTagAsDefault: false # -- Mount named secrets containing docker credentials imagePullSecrets: [] - # -- Add extra labels to every object the chart renders, including `extraResources`. Prometheus copies the labels of - # a Service to the metrics it scrapes from it, so these labels also appear on those metrics. + # -- Add extra labels to every object the chart renders, including `extraResources`. The bundled Prometheus does not + # copy these labels from a Service to the metrics it scrapes from it; use `.serviceLabels` for that. labels: {} # -- When true, remove all resource stanzas, allowing the scheduler to best-fit pods. Intended for local development with limited resources. localDevMode: false From ccc11d464c9827443a437ab60e4301317a85f577 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 11 Nov 2026 19:59:02 +0000 Subject: [PATCH 05/18] otel-collector: serve the collector's own metrics on all interfaces The image's logging.yaml, and the ConfigMap the chart renders for custom exporters, left the collector's metrics on 127.0.0.1:8888, where Prometheus cannot scrape them. With the app label the Service gained, up was 0 and the pods available alert fired instead of showing no data. Pass the telemetry readers setting as a second --config to the default command, and add it to the rendered ConfigMap. jaeger.yaml already has it. Amp-Thread-ID: https://ampcode.com/threads/T-c7c725c9-ed68-48e2-9f2d-0b8c31e76050 Co-authored-by: Amp --- charts/sourcegraph/CHANGELOG.md | 2 +- charts/sourcegraph/templates/_helpers.tpl | 13 +++++++++++++ .../otel-collector/otel-collector.ConfigMap.yaml | 5 +++++ .../otel-collector/otel-collector.Deployment.yaml | 2 ++ .../sourcegraph/tests/otelCollectorJaeger_test.yaml | 12 +++++++++++- 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index 08fb06eb9..857c496d8 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -10,7 +10,7 @@ Use `**BREAKING**:` to denote a breaking change - Added `frontend.internalServiceAnnotations` and `frontend.internalServiceLabels` for the `sourcegraph-frontend-internal` Service. That Service no longer renders `frontend.serviceAnnotations` and `frontend.serviceLabels`, which now apply to the `sourcegraph-frontend` Service only, so load balancer annotations or a service mesh label set for the external Service no longer land on the internal one. If you relied on them on the internal Service, set the new values. - 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. -- Fixed the `otel-collector` Service missing the `app` label that every other scraped Service has. Its metrics had no `app` and `job` labels, so the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, had no data. Its metrics now have `app="otel-collector"` and `job="otel-collector"`. +- Fixed the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, having no data. The `otel-collector` Service was missing the `app` label that every other scraped Service has, so its metrics had no `app` and `job` labels. They now have `app="otel-collector"` and `job="otel-collector"`. The collector also served its own metrics on 127.0.0.1 only, unless `jaeger.enabled` was set, so Prometheus could not scrape them. It now serves them on all interfaces, port 8888: the default command passes the setting as a second `--config` argument, which restarts the `otel-collector` pod once, and the ConfigMap rendered for `openTelemetry.gateway.config.traces.exporters` includes it. The pod does not restart when only that ConfigMap changes, so restart the `otel-collector` Deployment after an upgrade that does not replace its pod. If you set `openTelemetry.gateway.command` with your own configuration file, add `service.telemetry.metrics.readers` to it, as in the chart's `otel-collector` ConfigMap. Until the metrics can be scraped, the alert fires. - Every object the chart creates now has the `deploy` and `app.kubernetes.io/component` labels. PodDisruptionBudgets get the component of their workload, PriorityClasses get `priority-class`, the StorageClass gets `storage` and keeps `deploy: sourcegraph-storage`, and the `sg-test-connection` Pod gets `test-connection`. `extraResources` get `deploy: sourcegraph` unless they set their own; set `app.kubernetes.io/component` on them yourself. The `jaeger` ConfigMap, Deployment, and Services gain `app.kubernetes.io/instance` and keep `app.kubernetes.io/name: jaeger`, which their selectors use. Labels on these objects can be changed in place; the `jaeger` pod restarts once, because its `checksum/jaeger-config` annotation covers the ConfigMap's labels. - `.labels` is now also rendered on the component's ConfigMaps, Secrets, and PodDisruptionBudget, not only on its workload, so releases that set it gain these labels on upgrade. Added `storageClass.labels` and a `labels` field on each `priorityClasses` entry. - Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. diff --git a/charts/sourcegraph/templates/_helpers.tpl b/charts/sourcegraph/templates/_helpers.tpl index b62a144b5..abaefef3b 100644 --- a/charts/sourcegraph/templates/_helpers.tpl +++ b/charts/sourcegraph/templates/_helpers.tpl @@ -51,6 +51,19 @@ which Helm adds to every object it installs. {{- $names | uniq | join "|" -}} {{- end }} +{{/* +The `service.telemetry.metrics.readers` setting of `otel-collector`, as a YAML +flow sequence. It serves the collector's own metrics on all interfaces, port +8888, where Prometheus scrapes them. The collector defaults to 127.0.0.1, which +other pods cannot reach. Without the type and unit suffixes the metric names are +the ones the bundled dashboard queries, e.g. `otelcol_receiver_accepted_spans`. + +The image's `jaeger.yaml` already has this setting. Its `logging.yaml` does not. +*/}} +{{- define "sourcegraph.otelCollector.metricsReaders" -}} +[{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}] +{{- end }} + {{/* Selector labels, shared by a component's workload selector, pod labels, and Service and PodDisruptionBudget selectors, so they cannot drift apart. diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml index 6151ae49d..1e4e64812 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml @@ -39,6 +39,11 @@ data: endpoint: "localhost:55679" service: + telemetry: + metrics: + # Serve the collector's own metrics on all interfaces, for Prometheus to scrape. + # The collector defaults to 127.0.0.1. + readers: {{ include "sourcegraph.otelCollector.metricsReaders" . }} extensions: - health_check - zpages diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml index c25b8e5cf..ef3fa6146 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml @@ -56,6 +56,8 @@ spec: - "/bin/otelcol-sourcegraph" {{- if and (not .Values.openTelemetry.gateway.config.traces.exporters) (not .Values.jaeger.enabled) }} # default config: enable logging exporter - "--config=/etc/otel-collector/configs/logging.yaml" + # logging.yaml serves the collector's own metrics on 127.0.0.1 only, where Prometheus cannot scrape them. + - {{ printf "--config=yaml:service::telemetry::metrics::readers: %s" (include "sourcegraph.otelCollector.metricsReaders" .) | quote }} {{- else if .Values.jaeger.enabled }} # use bundled config to connect to bundled jaeger - "--config=/etc/otel-collector/configs/jaeger.yaml" {{- else }} # use config defined by customer in values.yaml diff --git a/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml b/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml index a9ae2a3c0..fddcbbba2 100644 --- a/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml +++ b/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml @@ -4,9 +4,14 @@ tests: - it: should use the logging exporter when Jaeger is disabled and no exporter has been set template: otel-collector/otel-collector.Deployment.yaml asserts: + # The second --config serves the collector's own metrics on all interfaces: logging.yaml + # leaves them on 127.0.0.1, where Prometheus cannot scrape them. - equal: path: spec.template.spec.containers[0].command - value: [ "/bin/otelcol-sourcegraph", "--config=/etc/otel-collector/configs/logging.yaml" ] + value: + - "/bin/otelcol-sourcegraph" + - "--config=/etc/otel-collector/configs/logging.yaml" + - '--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]' - isEmpty: path: spec.template.spec.containers[0].volumeMounts - isEmpty: @@ -68,6 +73,11 @@ tests: path: data["config.yaml"] pattern: "endpoint: otlp.service.com:443" # check if element of config is substituted correctly template: otel-collector/otel-collector.ConfigMap.yaml + - matchRegex: + path: data["config.yaml"] + # the collector's own metrics are served on all interfaces, for Prometheus to scrape + pattern: 'service:\n telemetry:\n metrics:\n(\s*#.*\n)*\s*readers: \[\{pull: \{exporter: \{prometheus: \{host: "0\.0\.0\.0", port: 8888, ' + template: otel-collector/otel-collector.ConfigMap.yaml - it: should fail if a configuration is provided and jaeger is enabled template: otel-collector/otel-collector.ConfigMap.yaml set: From 967bb94a874e9d8bdb5a3e0c652465ea814e7829 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:21:55 +0000 Subject: [PATCH 06/18] otel-collector: document what a replacement command needs for its metrics to be scraped openTelemetry.gateway.command replaces the default command, so it does not get the argument that serves the collector's metrics on all interfaces. Amp-Thread-ID: https://ampcode.com/threads/T-c7c725c9-ed68-48e2-9f2d-0b8c31e76050 Co-authored-by: Amp --- charts/sourcegraph/CHANGELOG.md | 2 +- charts/sourcegraph/README.md | 2 +- charts/sourcegraph/values.yaml | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index 857c496d8..2fecdbbef 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -10,7 +10,7 @@ Use `**BREAKING**:` to denote a breaking change - Added `frontend.internalServiceAnnotations` and `frontend.internalServiceLabels` for the `sourcegraph-frontend-internal` Service. That Service no longer renders `frontend.serviceAnnotations` and `frontend.serviceLabels`, which now apply to the `sourcegraph-frontend` Service only, so load balancer annotations or a service mesh label set for the external Service no longer land on the internal one. If you relied on them on the internal Service, set the new values. - 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. -- Fixed the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, having no data. The `otel-collector` Service was missing the `app` label that every other scraped Service has, so its metrics had no `app` and `job` labels. They now have `app="otel-collector"` and `job="otel-collector"`. The collector also served its own metrics on 127.0.0.1 only, unless `jaeger.enabled` was set, so Prometheus could not scrape them. It now serves them on all interfaces, port 8888: the default command passes the setting as a second `--config` argument, which restarts the `otel-collector` pod once, and the ConfigMap rendered for `openTelemetry.gateway.config.traces.exporters` includes it. The pod does not restart when only that ConfigMap changes, so restart the `otel-collector` Deployment after an upgrade that does not replace its pod. If you set `openTelemetry.gateway.command` with your own configuration file, add `service.telemetry.metrics.readers` to it, as in the chart's `otel-collector` ConfigMap. Until the metrics can be scraped, the alert fires. +- Fixed the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, having no data. The `otel-collector` Service was missing the `app` label that every other scraped Service has, so its metrics had no `app` and `job` labels. They now have `app="otel-collector"` and `job="otel-collector"`. The collector also served its own metrics on 127.0.0.1 only, unless `jaeger.enabled` was set, so Prometheus could not scrape them. It now serves them on all interfaces, port 8888: the default command passes the setting as a second `--config` argument, which restarts the `otel-collector` pod once, and the ConfigMap rendered for `openTelemetry.gateway.config.traces.exporters` includes it. The pod does not restart when only that ConfigMap changes, so restart the `otel-collector` Deployment after an upgrade that does not replace its pod. A command set in `openTelemetry.gateway.command` replaces the default one, so it does not get the argument. If it runs `/etc/otel-collector/config.yaml` or the image's `jaeger.yaml`, it needs no change. If it runs the image's `logging.yaml`, add the argument `--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]` after its `--config`. If it runs your own configuration file, set `service.telemetry.metrics.readers` to that list in the file. Until the metrics can be scraped, the alert fires. - Every object the chart creates now has the `deploy` and `app.kubernetes.io/component` labels. PodDisruptionBudgets get the component of their workload, PriorityClasses get `priority-class`, the StorageClass gets `storage` and keeps `deploy: sourcegraph-storage`, and the `sg-test-connection` Pod gets `test-connection`. `extraResources` get `deploy: sourcegraph` unless they set their own; set `app.kubernetes.io/component` on them yourself. The `jaeger` ConfigMap, Deployment, and Services gain `app.kubernetes.io/instance` and keep `app.kubernetes.io/name: jaeger`, which their selectors use. Labels on these objects can be changed in place; the `jaeger` pod restarts once, because its `checksum/jaeger-config` annotation covers the ConfigMap's labels. - `.labels` is now also rendered on the component's ConfigMaps, Secrets, and PodDisruptionBudget, not only on its workload, so releases that set it gain these labels on upgrade. Added `storageClass.labels` and a `labels` field on each `priorityClasses` entry. - Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. diff --git a/charts/sourcegraph/README.md b/charts/sourcegraph/README.md index e599d14bf..0a6e0e824 100644 --- a/charts/sourcegraph/README.md +++ b/charts/sourcegraph/README.md @@ -398,7 +398,7 @@ In addition to the documented values, all services also support the following va | openTelemetry.agent.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `otel-agent` | | openTelemetry.agent.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount | | openTelemetry.enabled | bool | `true` | | -| openTelemetry.gateway.command | list | `[]` | Command for the `otel-collector` container, as a list, replacing the chart's `/bin/otelcol-sourcegraph --config=` command, including the `--config` flag the chart selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file. `openTelemetry.gateway.args` is still passed as the arguments. | +| openTelemetry.gateway.command | list | `[]` | Command for the `otel-collector` container, as a list, replacing the chart's `/bin/otelcol-sourcegraph --config=` command, including the `--config` flag the chart selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file. `openTelemetry.gateway.args` is still passed as the arguments. The default command makes the collector serve its own metrics on all interfaces, where Prometheus scrapes them. A command that runs `/etc/otel-collector/config.yaml`, rendered from `config.traces.exporters`, or the image's `jaeger.yaml` does too. A command that runs the image's `logging.yaml` must also pass the second argument of the default command, `--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]`, and your own configuration file must set `service.telemetry.metrics.readers` to that list. Otherwise Prometheus cannot scrape the collector and its "pods available" alert fires. | | openTelemetry.gateway.config.traces.exporters | object | `{}` | Define where traces should be exported to. Read how to configure different backends in the [OpenTelemetry documentation](https://opentelemetry.io/docs/collector/configuration/#exporters) | | openTelemetry.gateway.config.traces.exportersTlsSecretName | string | `""` | Define the name of a preexisting secret containing TLS certificates for exporters, which will be mounted under "/tls". Read more about TLS configuration of exporters in the [OpenTelemetry Collector documentation](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configtls/README.md) | | openTelemetry.gateway.config.traces.processors | object | `{}` | Define trace processors. Read how to configure sampling in the [OpenTelemetry documentation](https://docs.sourcegraph.com/admin/observability/opentelemetry#sampling-traces) | diff --git a/charts/sourcegraph/values.yaml b/charts/sourcegraph/values.yaml index 3bc6cda5e..6de420c8b 100644 --- a/charts/sourcegraph/values.yaml +++ b/charts/sourcegraph/values.yaml @@ -762,6 +762,13 @@ openTelemetry: # `/bin/otelcol-sourcegraph --config=` command, including the `--config` flag the chart # selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file. # `openTelemetry.gateway.args` is still passed as the arguments. + # The default command makes the collector serve its own metrics on all interfaces, where Prometheus + # scrapes them. A command that runs `/etc/otel-collector/config.yaml`, rendered from + # `config.traces.exporters`, or the image's `jaeger.yaml` does too. A command that runs the image's + # `logging.yaml` must also pass the second argument of the default command, + # `--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]`, + # and your own configuration file must set `service.telemetry.metrics.readers` to that list. + # Otherwise Prometheus cannot scrape the collector and its "pods available" alert fires. command: [] # -- Resource requests & limits for the `otel-collector` container, # learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) From 67af08ee1aa2c86313cbedd26ed61a1716477bc0 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 11 Nov 2026 13:19:50 -0600 Subject: [PATCH 07/18] sourcegraph: restart prometheus when its configuration changes --- charts/sourcegraph/CHANGELOG.md | 1 + .../prometheus/prometheus.Deployment.yaml | 4 +++ .../tests/prometheusConfigChecksum_test.yaml | 26 +++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 charts/sourcegraph/tests/prometheusConfigChecksum_test.yaml diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index 2fecdbbef..936993610 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -14,6 +14,7 @@ Use `**BREAKING**:` to denote a breaking change - Every object the chart creates now has the `deploy` and `app.kubernetes.io/component` labels. PodDisruptionBudgets get the component of their workload, PriorityClasses get `priority-class`, the StorageClass gets `storage` and keeps `deploy: sourcegraph-storage`, and the `sg-test-connection` Pod gets `test-connection`. `extraResources` get `deploy: sourcegraph` unless they set their own; set `app.kubernetes.io/component` on them yourself. The `jaeger` ConfigMap, Deployment, and Services gain `app.kubernetes.io/instance` and keep `app.kubernetes.io/name: jaeger`, which their selectors use. Labels on these objects can be changed in place; the `jaeger` pod restarts once, because its `checksum/jaeger-config` annotation covers the ConfigMap's labels. - `.labels` is now also rendered on the component's ConfigMaps, Secrets, and PodDisruptionBudget, not only on its workload, so releases that set it gain these labels on upgrade. Added `storageClass.labels` and a `labels` field on each `priorityClasses` entry. - Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. +- The `prometheus` pod now restarts when an upgrade changes the chart's `prometheus.yml`, through a `checksum/prometheus-config` pod annotation. Prometheus does not reload a changed ConfigMap by itself, so such a change took effect only at the pod's next restart. The annotation is not set with `prometheus.existingConfig`: restart the pod yourself after changing your own ConfigMap. - `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 rendered on every object the chart creates: also on Services, ConfigMaps, Secrets, the Ingress, PodDisruptionBudgets, PriorityClasses, and `extraResources`, so existing releases gain these labels on upgrade. Labels that an `extraResources` entry or `serviceLabels` set take precedence. Labels on these objects can be changed in place, so nothing is recreated or restarted. Prometheus copies the labels of a Service to the metrics it scrapes from it, so the bundled Prometheus configuration now drops `helm.sh/chart`, `app.kubernetes.io/name`, `app.kubernetes.io/instance`, `app.kubernetes.io/version`, and the keys of `sourcegraph.labels`, which keeps the labels of those metrics as they were. `app.kubernetes.io/managed-by` stays on them: Helm already added it to every Service. Only the `otel-collector` metrics lose labels, because its Service already had these. To add a label to the metrics of a Service, set it in `.serviceLabels`, with a key that is not in `sourcegraph.labels`. Prometheus reads its configuration when it starts, so restart the `prometheus` Deployment after an upgrade that does not replace its pod. If you set `prometheus.existingConfig`, add the same `labeldrop` rule after each `__meta_kubernetes_service_label_(.+)` `labelmap` rule in your `prometheus.yml`, as in the [k3s example](examples/prometheus/prometheus-override-k3s.ConfigMap.yaml), and append the keys of `sourcegraph.labels` to its regex. - Added `storageLabels` on `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, and `redisStore` to label each component's PersistentVolumeClaim, and `.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). - 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. diff --git a/charts/sourcegraph/templates/prometheus/prometheus.Deployment.yaml b/charts/sourcegraph/templates/prometheus/prometheus.Deployment.yaml index f9044e9e1..c7a2862ae 100644 --- a/charts/sourcegraph/templates/prometheus/prometheus.Deployment.yaml +++ b/charts/sourcegraph/templates/prometheus/prometheus.Deployment.yaml @@ -26,6 +26,10 @@ spec: metadata: annotations: kubectl.kubernetes.io/default-container: prometheus + {{- if not .Values.prometheus.existingConfig }} + {{- /* Prometheus does not reload a changed ConfigMap by itself. The ConfigMap's labels are left out of the hash. */}} + checksum/prometheus-config: {{ (include (print $.Template.BasePath "/prometheus/prometheus.ConfigMap.yaml") . | fromYaml).data | toJson | sha256sum }} + {{- end }} {{- if .Values.sourcegraph.podAnnotations }} {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} {{- end }} diff --git a/charts/sourcegraph/tests/prometheusConfigChecksum_test.yaml b/charts/sourcegraph/tests/prometheusConfigChecksum_test.yaml new file mode 100644 index 000000000..d51af9373 --- /dev/null +++ b/charts/sourcegraph/tests/prometheusConfigChecksum_test.yaml @@ -0,0 +1,26 @@ +--- +suite: prometheusConfigChecksum +# The ConfigMap template is listed so the Deployment's checksum annotation can +# include it. +templates: +- prometheus/prometheus.Deployment.yaml +- prometheus/prometheus.ConfigMap.yaml +tests: +- it: should restart prometheus when the chart's configuration changes + template: prometheus/prometheus.Deployment.yaml + asserts: + - matchRegex: + path: spec.template.metadata.annotations["checksum/prometheus-config"] + pattern: ^[0-9a-f]{64}$ + # The hash of `null`, which is what an unreadable ConfigMap would hash to + - notEqual: + path: spec.template.metadata.annotations["checksum/prometheus-config"] + value: 74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +- it: should drop the checksum annotation with an existing ConfigMap + template: prometheus/prometheus.Deployment.yaml + set: + prometheus: + existingConfig: my-prometheus-config + asserts: + - notExists: + path: spec.template.metadata.annotations["checksum/prometheus-config"] From 597b7ab382c001c75fae9caaf15a337e39b2e9ce Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 11 Nov 2026 16:12:13 -0600 Subject: [PATCH 08/18] Add the common labels to pods and keep them off all scraped metrics Pod templates now get `sourcegraph.labels`, the chart's standard labels, and `app.kubernetes.io/component`, as every other object does. One helper, `sourcegraph.podLabels`, merges them with `sourcegraph.podLabels`, the component's `podLabels`, and the selector labels, so each key is rendered once and a selector label always wins. The Prometheus `labeldrop` rule now also drops `app.kubernetes.io/managed-by` and also applies to the `kubernetes-pods` job, so Helm and `helm template | kubectl apply` installs get the same metric labels. No bundled dashboard or alert queries the dropped labels. The changelog no longer asks for a manual Prometheus restart: the `checksum/prometheus-config` annotation restarts it. Amp-Thread-ID: https://ampcode.com/threads/T-01a1cc03-93a7-7445-8f1f-3dd7123272bf Co-authored-by: Amp --- charts/sourcegraph-executor/CHANGELOG.md | 2 +- .../dind/templates/_helpers.tpl | 23 +++++--- .../private-docker-registry.Statefulset.yaml | 9 +-- .../dind/tests/labels_test.yaml | 58 +++++++++++++++++++ .../k8s/templates/_helpers.tpl | 15 +++++ .../k8s/templates/executor.Deployment.yaml | 8 +-- .../k8s/tests/labels_test.yaml | 28 +++++++++ .../templates/_helpers.tpl | 15 +++++ .../migrator/sourcegraph-migrator.Job.yaml | 9 +-- .../tests/labels_test.yaml | 26 +++++++++ charts/sourcegraph/CHANGELOG.md | 6 +- .../prometheus-override-k3s.ConfigMap.yaml | 14 +++-- charts/sourcegraph/templates/_helpers.tpl | 38 ++++++++---- charts/sourcegraph/templates/_worker.tpl | 9 +-- .../blobstore/blobstore.Deployment.yaml | 9 +-- .../cadvisor/cadvisor.DaemonSet.yaml | 9 +-- .../codeinsights-db.StatefulSet.yaml | 9 +-- .../codeintel-db.StatefulSet.yaml | 9 +-- .../sourcegraph-frontend.Deployment.yaml | 9 +-- .../gitserver/gitserver.StatefulSet.yaml | 9 +-- .../grafana/grafana.StatefulSet.yaml | 9 +-- .../indexed-search.StatefulSet.yaml | 9 +-- .../templates/jaeger/jaeger.Deployment.yaml | 10 +--- .../node-exporter.DaemonSet.yaml | 9 +-- .../otel-collector/otel-agent.DaemonSet.yaml | 9 +-- .../otel-collector.Deployment.yaml | 9 +-- .../templates/pgsql/pgsql.StatefulSet.yaml | 9 +-- .../precise-code-intel/worker.Deployment.yaml | 9 +-- .../prometheus/prometheus.ConfigMap.yaml | 12 ++-- .../prometheus/prometheus.Deployment.yaml | 9 +-- .../redis/redis-cache.Deployment.yaml | 9 +-- .../redis/redis-store.Deployment.yaml | 9 +-- .../searcher/searcher.StatefulSet.yaml | 9 +-- .../worker.Deployment.yaml | 9 +-- .../syntect-server.Deployment.yaml | 9 +-- .../tests/allObjectLabels_test.yaml | 20 +++---- .../tests/selectorLabels_test.yaml | 55 ++++++++++++++++-- 37 files changed, 313 insertions(+), 215 deletions(-) diff --git a/charts/sourcegraph-executor/CHANGELOG.md b/charts/sourcegraph-executor/CHANGELOG.md index 5cc26836d..f652c1dbf 100644 --- a/charts/sourcegraph-executor/CHANGELOG.md +++ b/charts/sourcegraph-executor/CHANGELOG.md @@ -4,7 +4,7 @@ ## Unreleased - Every object the charts create now has the `deploy` and `app.kubernetes.io/component` labels: the `sourcegraph-executor-k8s` Secret did not have them. `executor.labels` is now also rendered on the `sourcegraph-executor-k8s` ConfigMap, Secret, ServiceAccount, Role, and RoleBinding, and on the `sourcegraph-executor-dind` `docker-config` ConfigMap, not only on the Deployment. Added `privateDockerRegistry.serviceLabels` to the `sourcegraph-executor-dind` chart to label the `private-docker-registry` Service. -- `sourcegraph.labels` and the charts' standard labels (`helm.sh/chart`, `app.kubernetes.io/name`, `app.kubernetes.io/instance`, `app.kubernetes.io/version`, `app.kubernetes.io/managed-by`) are now rendered on every object the charts create. The `sourcegraph-executor-k8s` chart rendered them on none of its objects (ConfigMap, Deployment, Role, RoleBinding, Secret, Service, ServiceAccount), and the `sourcegraph-executor-dind` chart did not render them on the `docker-config` ConfigMap and the `private-docker-registry` Service. Existing releases gain these labels on upgrade. Labels on these objects can be changed in place, so nothing is recreated or restarted. +- `sourcegraph.labels` and the charts' standard labels (`helm.sh/chart`, `app.kubernetes.io/name`, `app.kubernetes.io/instance`, `app.kubernetes.io/version`, `app.kubernetes.io/managed-by`) are now rendered on every object the charts create. The `sourcegraph-executor-k8s` chart rendered them on none of its objects (ConfigMap, Deployment, Role, RoleBinding, Secret, Service, ServiceAccount), and the `sourcegraph-executor-dind` chart did not render them on the `docker-config` ConfigMap and the `private-docker-registry` Service. Pods get them too, and the `private-docker-registry` pod gains `app.kubernetes.io/component`. Existing releases gain these labels on upgrade. No object is recreated. Every pod restarts on this upgrade, and from now on whenever the chart version changes, because `helm.sh/chart` and `app.kubernetes.io/version` are pod labels. ## 8.0.0 diff --git a/charts/sourcegraph-executor/dind/templates/_helpers.tpl b/charts/sourcegraph-executor/dind/templates/_helpers.tpl index 8b87b5d24..aec7e5345 100644 --- a/charts/sourcegraph-executor/dind/templates/_helpers.tpl +++ b/charts/sourcegraph-executor/dind/templates/_helpers.tpl @@ -35,6 +35,21 @@ app.kubernetes.io/name: {{ include "sourcegraph.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} +{{/* +Labels of a pod template: the common labels, then sourcegraph.podLabels, then +the component's podLabels, then the selector labels. The later one wins when a +key is set more than once, so each key is rendered once and the selector always +matches the pods. + +{{ include "sourcegraph.podLabels" (list . .Values.executor) }} +*/}} +{{- define "sourcegraph.podLabels" -}} +{{- $top := index . 0 -}} +{{- $component := index . 1 -}} +{{- $labels := include "sourcegraph.labels" $top | fromYaml -}} +{{- mergeOverwrite $labels ($top.Values.sourcegraph.podLabels | default dict) ($component.podLabels | default dict) (include "sourcegraph.selectorLabels" $top | fromYaml) | toYaml -}} +{{- end }} + {{/* Create the name of the service account to use */}} @@ -169,13 +184,7 @@ spec: {{- toYaml $r.Values.executor.podAnnotations | nindent 8 }} {{- end }} labels: - {{- include "sourcegraph.selectorLabels" $r | nindent 8 }} - {{- if $r.Values.sourcegraph.podLabels }} - {{- toYaml $r.Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if $r.Values.executor.podLabels }} - {{- toYaml $r.Values.executor.podLabels | nindent 8 }} - {{- end }} + {{- include "sourcegraph.podLabels" (list $r $r.Values.executor) | nindent 8 }} app: {{ .name }} deploy: sourcegraph sourcegraph-resource-requires: no-cluster-admin diff --git a/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Statefulset.yaml b/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Statefulset.yaml index 71f3194e8..84fcae9f3 100644 --- a/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Statefulset.yaml +++ b/charts/sourcegraph-executor/dind/templates/private-docker-registry/private-docker-registry.Statefulset.yaml @@ -30,15 +30,10 @@ spec: {{- toYaml .Values.privateDockerRegistry.podAnnotations | nindent 8 }} {{- end }} labels: - {{- include "sourcegraph.selectorLabels" . | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.privateDockerRegistry.podLabels }} - {{- toYaml .Values.privateDockerRegistry.podLabels | nindent 8 }} - {{- end }} + {{- include "sourcegraph.podLabels" (list . .Values.privateDockerRegistry) | nindent 8 }} deploy: sourcegraph app: private-docker-registry + app.kubernetes.io/component: private-docker-registry spec: containers: - name: private-docker-registry diff --git a/charts/sourcegraph-executor/dind/tests/labels_test.yaml b/charts/sourcegraph-executor/dind/tests/labels_test.yaml index 236bbcd0c..88dc1d0e5 100644 --- a/charts/sourcegraph-executor/dind/tests/labels_test.yaml +++ b/charts/sourcegraph-executor/dind/tests/labels_test.yaml @@ -47,3 +47,61 @@ tests: - equal: path: metadata.labels["example.com/service"] value: component + - it: should add sourcegraph.labels and the chart's labels to the pod template, and let the selector labels win + template: executor/executor.Deployment.yaml + set: + sourcegraph: + labels: + example.com/project: sourcegraph + podLabels: + example.com/project: pods + # A selector label: a different value would stop the selector from matching the pods. + app.kubernetes.io/instance: other + executor: + queueName: batches + asserts: + - isSubset: + path: spec.template.metadata.labels + content: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + deploy: sourcegraph + example.com/project: pods + - exists: + path: spec.template.metadata.labels["helm.sh/chart"] + - exists: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + - exists: + path: spec.template.metadata.labels["app.kubernetes.io/version"] + - exists: + path: spec.template.metadata.labels["app.kubernetes.io/component"] + - it: should add sourcegraph.labels and the chart's labels to the pod template, and let the selector labels win + template: private-docker-registry/private-docker-registry.Statefulset.yaml + set: + sourcegraph: + labels: + example.com/project: sourcegraph + podLabels: + example.com/project: pods + # A selector label: a different value would stop the selector from matching the pods. + app.kubernetes.io/instance: other + executor: + queueName: batches + privateDockerRegistry: + enabled: true + asserts: + - isSubset: + path: spec.template.metadata.labels + content: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + deploy: sourcegraph + example.com/project: pods + - exists: + path: spec.template.metadata.labels["helm.sh/chart"] + - exists: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + - exists: + path: spec.template.metadata.labels["app.kubernetes.io/version"] + - exists: + path: spec.template.metadata.labels["app.kubernetes.io/component"] diff --git a/charts/sourcegraph-executor/k8s/templates/_helpers.tpl b/charts/sourcegraph-executor/k8s/templates/_helpers.tpl index 70f75b28c..168ac8114 100644 --- a/charts/sourcegraph-executor/k8s/templates/_helpers.tpl +++ b/charts/sourcegraph-executor/k8s/templates/_helpers.tpl @@ -35,6 +35,21 @@ app.kubernetes.io/name: {{ include "sourcegraph.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} +{{/* +Labels of a pod template: the common labels, then sourcegraph.podLabels, then +the component's podLabels, then the selector labels. The later one wins when a +key is set more than once, so each key is rendered once and the selector always +matches the pods. + +{{ include "sourcegraph.podLabels" (list . .Values.executor) }} +*/}} +{{- define "sourcegraph.podLabels" -}} +{{- $top := index . 0 -}} +{{- $component := index . 1 -}} +{{- $labels := include "sourcegraph.labels" $top | fromYaml -}} +{{- mergeOverwrite $labels ($top.Values.sourcegraph.podLabels | default dict) ($component.podLabels | default dict) (include "sourcegraph.selectorLabels" $top | fromYaml) | toYaml -}} +{{- end }} + {{/* Create the name of the service account to use */}} diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml index 9978038b0..a001db219 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml @@ -38,13 +38,7 @@ spec: {{- toYaml .Values.executor.podAnnotations | nindent 8 }} {{- end }} labels: - {{- include "sourcegraph.selectorLabels" . | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.executor.podLabels }} - {{- toYaml .Values.executor.podLabels | nindent 8 }} - {{- end }} + {{- include "sourcegraph.podLabels" (list . .Values.executor) | nindent 8 }} {{- include "executor.labels" . | nindent 8 }} spec: securityContext: diff --git a/charts/sourcegraph-executor/k8s/tests/labels_test.yaml b/charts/sourcegraph-executor/k8s/tests/labels_test.yaml index a627f5f03..33d00deaf 100644 --- a/charts/sourcegraph-executor/k8s/tests/labels_test.yaml +++ b/charts/sourcegraph-executor/k8s/tests/labels_test.yaml @@ -43,3 +43,31 @@ tests: - equal: path: metadata.labels["example.com/service"] value: executor + - it: should add sourcegraph.labels and the chart's labels to the pod template, and let the selector labels win + template: executor.Deployment.yaml + set: + sourcegraph: + labels: + example.com/project: sourcegraph + podLabels: + example.com/project: pods + # A selector label: a different value would stop the selector from matching the pods. + app.kubernetes.io/instance: other + executor: + queueName: batches + asserts: + - isSubset: + path: spec.template.metadata.labels + content: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + deploy: sourcegraph + example.com/project: pods + - exists: + path: spec.template.metadata.labels["helm.sh/chart"] + - exists: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + - exists: + path: spec.template.metadata.labels["app.kubernetes.io/version"] + - exists: + path: spec.template.metadata.labels["app.kubernetes.io/component"] diff --git a/charts/sourcegraph-migrator/templates/_helpers.tpl b/charts/sourcegraph-migrator/templates/_helpers.tpl index f6ce9b36d..a438403b4 100644 --- a/charts/sourcegraph-migrator/templates/_helpers.tpl +++ b/charts/sourcegraph-migrator/templates/_helpers.tpl @@ -35,6 +35,21 @@ app.kubernetes.io/name: {{ include "sourcegraph.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} +{{/* +Labels of a pod template: the common labels, then sourcegraph.podLabels, then +the component's podLabels, then the selector labels. The later one wins when a +key is set more than once, so each key is rendered once and the selector always +matches the pods. + +{{ include "sourcegraph.podLabels" (list . .Values.migrator) }} +*/}} +{{- define "sourcegraph.podLabels" -}} +{{- $top := index . 0 -}} +{{- $component := index . 1 -}} +{{- $labels := include "sourcegraph.labels" $top | fromYaml -}} +{{- mergeOverwrite $labels ($top.Values.sourcegraph.podLabels | default dict) ($component.podLabels | default dict) (include "sourcegraph.selectorLabels" $top | fromYaml) | toYaml -}} +{{- end }} + {{/* Create the name of the service account to use */}} diff --git a/charts/sourcegraph-migrator/templates/migrator/sourcegraph-migrator.Job.yaml b/charts/sourcegraph-migrator/templates/migrator/sourcegraph-migrator.Job.yaml index c77ec3b33..4e41b3a28 100644 --- a/charts/sourcegraph-migrator/templates/migrator/sourcegraph-migrator.Job.yaml +++ b/charts/sourcegraph-migrator/templates/migrator/sourcegraph-migrator.Job.yaml @@ -24,15 +24,10 @@ spec: {{- toYaml .Values.migrator.podAnnotations | nindent 8 }} {{- end }} labels: - {{- include "sourcegraph.selectorLabels" . | nindent 8 }} - {{- if .Values.sourcegraph.podLabels }} - {{- toYaml .Values.sourcegraph.podLabels | nindent 8 }} - {{- end }} - {{- if .Values.migrator.podLabels }} - {{- toYaml .Values.migrator.podLabels | nindent 8 }} - {{- end }} + {{- include "sourcegraph.podLabels" (list . .Values.migrator) | nindent 8 }} job: migrator deploy: sourcegraph + app.kubernetes.io/component: migrator spec: containers: - name: migrator diff --git a/charts/sourcegraph-migrator/tests/labels_test.yaml b/charts/sourcegraph-migrator/tests/labels_test.yaml index 10fdbe013..dea0a7ed4 100644 --- a/charts/sourcegraph-migrator/tests/labels_test.yaml +++ b/charts/sourcegraph-migrator/tests/labels_test.yaml @@ -27,3 +27,29 @@ tests: path: metadata.labels["app.kubernetes.io/version"] - exists: path: metadata.labels["app.kubernetes.io/component"] + - it: should add sourcegraph.labels and the chart's labels to the pod template, and let the selector labels win + template: migrator/sourcegraph-migrator.Job.yaml + set: + sourcegraph: + labels: + example.com/project: sourcegraph + podLabels: + example.com/project: pods + # A selector label: a different value would stop the selector from matching the pods. + app.kubernetes.io/instance: other + asserts: + - isSubset: + path: spec.template.metadata.labels + content: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + deploy: sourcegraph + example.com/project: pods + - exists: + path: spec.template.metadata.labels["helm.sh/chart"] + - exists: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + - exists: + path: spec.template.metadata.labels["app.kubernetes.io/version"] + - exists: + path: spec.template.metadata.labels["app.kubernetes.io/component"] diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index 936993610..601c38dc5 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -14,9 +14,9 @@ Use `**BREAKING**:` to denote a breaking change - Every object the chart creates now has the `deploy` and `app.kubernetes.io/component` labels. PodDisruptionBudgets get the component of their workload, PriorityClasses get `priority-class`, the StorageClass gets `storage` and keeps `deploy: sourcegraph-storage`, and the `sg-test-connection` Pod gets `test-connection`. `extraResources` get `deploy: sourcegraph` unless they set their own; set `app.kubernetes.io/component` on them yourself. The `jaeger` ConfigMap, Deployment, and Services gain `app.kubernetes.io/instance` and keep `app.kubernetes.io/name: jaeger`, which their selectors use. Labels on these objects can be changed in place; the `jaeger` pod restarts once, because its `checksum/jaeger-config` annotation covers the ConfigMap's labels. - `.labels` is now also rendered on the component's ConfigMaps, Secrets, and PodDisruptionBudget, not only on its workload, so releases that set it gain these labels on upgrade. Added `storageClass.labels` and a `labels` field on each `priorityClasses` entry. - Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. -- The `prometheus` pod now restarts when an upgrade changes the chart's `prometheus.yml`, through a `checksum/prometheus-config` pod annotation. Prometheus does not reload a changed ConfigMap by itself, so such a change took effect only at the pod's next restart. The annotation is not set with `prometheus.existingConfig`: restart the pod yourself after changing your own ConfigMap. -- `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 rendered on every object the chart creates: also on Services, ConfigMaps, Secrets, the Ingress, PodDisruptionBudgets, PriorityClasses, and `extraResources`, so existing releases gain these labels on upgrade. Labels that an `extraResources` entry or `serviceLabels` set take precedence. Labels on these objects can be changed in place, so nothing is recreated or restarted. Prometheus copies the labels of a Service to the metrics it scrapes from it, so the bundled Prometheus configuration now drops `helm.sh/chart`, `app.kubernetes.io/name`, `app.kubernetes.io/instance`, `app.kubernetes.io/version`, and the keys of `sourcegraph.labels`, which keeps the labels of those metrics as they were. `app.kubernetes.io/managed-by` stays on them: Helm already added it to every Service. Only the `otel-collector` metrics lose labels, because its Service already had these. To add a label to the metrics of a Service, set it in `.serviceLabels`, with a key that is not in `sourcegraph.labels`. Prometheus reads its configuration when it starts, so restart the `prometheus` Deployment after an upgrade that does not replace its pod. If you set `prometheus.existingConfig`, add the same `labeldrop` rule after each `__meta_kubernetes_service_label_(.+)` `labelmap` rule in your `prometheus.yml`, as in the [k3s example](examples/prometheus/prometheus-override-k3s.ConfigMap.yaml), and append the keys of `sourcegraph.labels` to its regex. -- Added `storageLabels` on `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, and `redisStore` to label each component's PersistentVolumeClaim, and `.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). +- The `prometheus` pod now restarts when an upgrade changes the chart's `prometheus.yml`, through a `checksum/prometheus-config` pod annotation. Prometheus does not reload a changed ConfigMap by itself, so such a change took effect only at the pod's next restart. The annotation is not set with `prometheus.existingConfig`. +- `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 rendered on every object the chart creates: also on pods, Services, ConfigMaps, Secrets, the Ingress, PodDisruptionBudgets, PriorityClasses, and `extraResources`, so existing releases gain these labels on upgrade. Pods also gain `app.kubernetes.io/component`. Labels that an `extraResources` entry, `serviceLabels`, or `podLabels` set take precedence, except that `podLabels` cannot change a selector label. No object is recreated. Every pod restarts on this upgrade, and from now on whenever the chart version changes, because `helm.sh/chart` and `app.kubernetes.io/version` are pod labels. Prometheus copies the labels of a Service or pod to the metrics it scrapes from it, so the bundled Prometheus configuration now drops the five standard labels and the keys of `sourcegraph.labels`. No bundled dashboard or alert queries them. Metrics lose `app_kubernetes_io_managed_by`, which Helm added to every Service, `otel-collector` metrics lose the other standard labels, which its Service already had, and `cadvisor` and `jaeger` metrics, scraped from pods, lose `app_kubernetes_io_name` and `app_kubernetes_io_instance` and gain `app_kubernetes_io_component`. To add a label to the metrics of a Service, set it in `.serviceLabels`, with a key that is not in `sourcegraph.labels`. If you set `prometheus.existingConfig`, add the same `labeldrop` rule after each `__meta_kubernetes_service_label_(.+)` and `__meta_kubernetes_pod_label_(.+)` `labelmap` rule in your `prometheus.yml`, as in the [k3s example](examples/prometheus/prometheus-override-k3s.ConfigMap.yaml), and append the keys of `sourcegraph.labels` to its regex. +- Added `storageLabels` on `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, and `redisStore` to label each component's PersistentVolumeClaim, and `.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 none is recreated. See [Adopting existing workloads](README.md#adopting-existing-workloads). - 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. - Added `sourcegraph.selectorLabelsOverride`, `.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). - Fixed `frontend.command` and `migrator.command` rendering a list as a single element, e.g. `["sh", "-c", "