Skip to content

feat/labels: Apply sourcegraph.labels to all objects in all four charts - #1023

Closed
marcleblanc2 wants to merge 13 commits into
marc/frontend-internal-service-labelsfrom
marc/labels-every-object
Closed

marcleblanc2 wants to merge 13 commits into
marc/frontend-internal-service-labelsfrom
marc/labels-every-object

Conversation

@marcleblanc2

@marcleblanc2 marcleblanc2 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  • Services, ConfigMaps, Secrets, the Ingress, and pods don't render sourcegraph.labels

Solution

  • All four charts now render on every object:

    • sourcegraph.labels
    • The standard Helm labels deploy and app.kubernetes.io/component
  • <serviceName>.labels and executor.labels are now applied more completely

  • New:

    • storageClass.labels
    • priorityClasses[].labels
    • privateDockerRegistry.serviceLabels
  • Not labelled, on purpose: PVCs that Kubernetes creates from a StatefulSet's volume claim template still get only <serviceName>.storageLabels. Kubernetes rejects changes to those templates, so adding labels would fail the upgrade of existing releases

  • The per-pod scratch PVCs of ephemeral volumes (preciseCodeIntel and syntacticCodeIntel with storageType: pvc, dind executor.storage.type: ephemeral) get the same labels as the standalone PVCs, including helm.sh/chart and app.kubernetes.io/version

  • The dind executor chart's two PVCs take their own labels: new executor.storage.labels for the scratch PVC, and new privateDockerRegistry.storageLabels for the registry's volume claim template. Both default to empty. Its README has a new "PersistentVolumeClaim labels" section

  • The README's PersistentVolumeClaim labels table, added in feat/labels: Add labels to PVCs, ServiceAccounts, and RBAC objects #1008, lists which values label each kind of PVC

  • A Prometheus labeldrop rule keeps the new labels off metrics

  • prometheus now restarts when its config changes

  • Fixed along the way:

    • redisStore.serviceAccount.annotations is now rendered. It was ignored since 2022, because the redis-store ServiceAccount was the only one missing it

    • The Jaeger Services keep their endpoints when a user sets their own app.kubernetes.io/instance pod label

    • A label key set in sourcegraph.labels and in a component's label value (or one the chart sets itself) rendered twice on the same object, also on main. Every label block now renders each key once, keeping the value Kubernetes applied (Slack report)

Tested

  • New tests render every template, and fail on any object missing the labels

  • helm unittest (292, 11, 10, and 13 tests), helm lint, helm-docs, and kubeconform -strict pass

  • Rendered against feat/frontend: Add separate annotations and labels for the frontend-internal Service #1022 with Jaeger, OpenTelemetry, and node-exporter on: the same 85 objects, and no selector, volume claim template, or PVC spec changes

  • Deployed on my test instance with the sourcegraph and k8s executor charts, with sourcegraph.labels set:

    • The live objects that changed: labels on 57 objects (every Service, ConfigMap, Secret, workload, and the Ingress, plus the executor's objects), 19 of them pod templates

    • Every running pod with a changed template was replaced once. No object UID, Service IP, or PVC volume changed, and the PVCs made from volume claim templates kept their labels

    • Search and an executor batch spec work afterwards

  • Duplicate label keys, on m5 on 2026-11-24, with the same example.com/team key in sourcegraph.labels, executor.labels, and several component values, deploying the top of the stack (fix/otel-collector: Scrape the collector's own metrics, and restart it on config changes #1030):

    • Previous heads: 9 sourcegraph and 5 executor objects had a duplicate key, and kubeconform -strict failed on them

    • New heads: 0 duplicate keys, and kubeconform -strict passes on both charts

    • Upgrading from the previous heads to the new ones changed 0 live objects and replaced 0 pods

    • Search and an executor batch spec work afterwards

  • Rendered all four charts against the previous head: the same objects, except the jaeger pod's checksum/jaeger-config, because the ConfigMap's labels are now sorted. The tests now set an overlapping key, and fail on the previous head

Amp threads

Changelog

  • sourcegraph.labels, the standard Helm labels, deploy, and app.kubernetes.io/component are now on every object in all Helm charts
  • New: storageClass.labels, priorityClasses[].labels, privateDockerRegistry.serviceLabels, and in the dind chart executor.storage.labels and privateDockerRegistry.storageLabels
  • With prometheus.existingConfig, add the new labeldrop rule to keep the labels off metrics
  • Fixed a label key set in sourcegraph.labels and in another label value rendering twice on the same object

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

marcleblanc2 and others added 3 commits November 18, 2026 14:31
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 <amp@ampcode.com>
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 <amp@ampcode.com>
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.
<serviceName>.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 <amp@ampcode.com>
@marcleblanc2
marcleblanc2 force-pushed the marc/labels-every-object branch from 6cda7a2 to 591d864 Compare November 18, 2026 20:32
@marcleblanc2
marcleblanc2 marked this pull request as ready for review November 24, 2026 22:30
@marcleblanc2
marcleblanc2 requested a review from a team November 24, 2026 22:30
marcleblanc2 and others added 10 commits November 24, 2026 17:48
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.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085
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 <amp@ampcode.com>
helm.sh/chart and app.kubernetes.io/version change with every chart version. As pod labels they changed every pod template, so every pod restarted whenever the chart version changed, even when nothing else did. On main no pod template depends on the chart version.

Pod templates in all four charts now get the common labels without these two. The other objects keep them.

This also updates the pod label snapshots of the selector labels golden test: every pod gains app.kubernetes.io/managed-by and app.kubernetes.io/component, and no selector, volume claim template, or existing pod label changes.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1cc03-93a7-7445-8f1f-3dd7123272bf
Co-authored-by: Amp <amp@ampcode.com>
Each chart's label defines, with their comments, move unchanged out of
_helpers.tpl, next to the other one-topic helper files. Renders are
byte-identical.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d360-e0b4-71d1-8ded-2e4851b93a8d
Co-authored-by: Amp <amp@ampcode.com>
The jaeger-collector and jaeger-query Services select on
app.kubernetes.io/instance: <release name>. main pins that label on the
jaeger pod. Once the pod also renders sourcegraph.podLabels and
jaeger.podLabels, a value for that label in either replaced the release
name, and both Services lost their endpoints.

Merge the release name last, and test that the pod keeps every label the
Services select on.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1902b-ece9-725c-863d-3e2bba35ee1d
executor.storage.labels labels the scratch PersistentVolumeClaim that is
created when executor.storage.type is ephemeral, as storageLabels does for
the PersistentVolumeClaims of the sourcegraph chart. It defaults to empty,
so existing releases render the same pods.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1902b-ece9-725c-863d-3e2bba35ee1d
…VC labels

privateDockerRegistry.storageLabels adds labels to the cache volume claim
template of the private-docker-registry StatefulSet, the last
PersistentVolumeClaim in the four charts that had no label value. It
defaults to empty, so existing releases render the same template.

The README now says which values label each PersistentVolumeClaim of the
chart, and that the registry's cannot change on an installed release.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1902b-ece9-725c-863d-3e2bba35ee1d
The scratch PersistentVolumeClaim of preciseCodeIntel and syntacticCodeIntel
(storageType: pvc) and of the dind executor (executor.storage.type:
ephemeral) now gets sourcegraph.labels, the standard Helm labels, deploy, and
app.kubernetes.io/component, as the standalone PersistentVolumeClaims do, in
addition to its own storageLabels or executor.storage.labels.

These labels are part of the pod template and include the chart version, so
with those settings the pods restart whenever the chart version changes.
Default renders are unchanged: the default volume is an emptyDir.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1902b-ece9-725c-863d-3e2bba35ee1d
The dind chart's executor.deployment moves to
_helpers/_executorDeployment.tpl, with its comment and otherwise unchanged.
No _helpers.tpl gains a line on this branch any more: every helper it adds
or changes is in a one-topic file under _helpers/. Renders are
byte-identical.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085
@michaellzc

Copy link
Copy Markdown
Member

this change is scary. unless there's specific use case. I prefer we do not touch it. there could be something relying on them implicitly.

@michaellzc michaellzc closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants