Repository navigation
feat/labels: Apply sourcegraph.labels to all objects in all four charts - #1023
Closed
marcleblanc2 wants to merge 13 commits into
Closed
marcleblanc2 wants to merge 13 commits into
marcleblanc2 wants to merge 13 commits into
Conversation
marcleblanc2
force-pushed
the
marc/labels-every-object
branch
from
November 18, 2026 18:41
a6f223d to
2dacb93
Compare
marcleblanc2
force-pushed
the
marc/labels-every-object
branch
from
November 18, 2026 19:54
2dacb93 to
38c24c0
Compare
marcleblanc2
force-pushed
the
marc/labels-every-object
branch
from
November 18, 2026 20:08
38c24c0 to
5a76434
Compare
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
force-pushed
the
marc/labels-every-object
branch
from
November 18, 2026 20:32
6cda7a2 to
591d864
Compare
marcleblanc2
marked this pull request as ready for review
November 24, 2026 22:30
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
marcleblanc2
force-pushed
the
marc/labels-every-object
branch
from
November 24, 2026 22:51
5dffc4a to
fc111c4
Compare
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
sourcegraph.labelsSolution
All four charts now render on every object:
sourcegraph.labelsdeployandapp.kubernetes.io/component<serviceName>.labelsandexecutor.labelsare now applied more completelyNew:
storageClass.labelspriorityClasses[].labelsprivateDockerRegistry.serviceLabelsNot 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 releasesThe per-pod scratch PVCs of ephemeral volumes (
preciseCodeIntelandsyntacticCodeIntelwithstorageType: pvc, dindexecutor.storage.type: ephemeral) get the same labels as the standalone PVCs, includinghelm.sh/chartandapp.kubernetes.io/versionThe dind executor chart's two PVCs take their own labels: new
executor.storage.labelsfor the scratch PVC, and newprivateDockerRegistry.storageLabelsfor the registry's volume claim template. Both default to empty. Its README has a new "PersistentVolumeClaim labels" sectionThe 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
labeldroprule keeps the new labels off metricsprometheusnow restarts when its config changesFixed along the way:
redisStore.serviceAccount.annotationsis now rendered. It was ignored since 2022, because theredis-storeServiceAccount was the only one missing itThe Jaeger Services keep their endpoints when a user sets their own
app.kubernetes.io/instancepod labelA label key set in
sourcegraph.labelsand in a component's label value (or one the chart sets itself) rendered twice on the same object, also onmain. 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, andkubeconform -strictpassRendered 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
sourcegraphand k8s executor charts, withsourcegraph.labelsset: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
m5on 2026-11-24, with the sameexample.com/teamkey insourcegraph.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
sourcegraphand 5 executor objects had a duplicate key, andkubeconform -strictfailed on themNew heads: 0 duplicate keys, and
kubeconform -strictpasses on both chartsUpgrading 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
jaegerpod'schecksum/jaeger-config, because the ConfigMap's labels are now sorted. The tests now set an overlapping key, and fail on the previous headAmp threads
Changelog
sourcegraph.labels, the standard Helm labels,deploy, andapp.kubernetes.io/componentare now on every object in all Helm chartsstorageClass.labels,priorityClasses[].labels,privateDockerRegistry.serviceLabels, and in the dind chartexecutor.storage.labelsandprivateDockerRegistry.storageLabelsprometheus.existingConfig, add the newlabeldroprule to keep the labels off metricssourcegraph.labelsand in another label value rendering twice on the same object