Repository navigation
sourcegraph: render opt-in labels on every object, each key once - #1038
Open
michaellzc wants to merge 7 commits into
Open
michaellzc wants to merge 7 commits into
michaellzc wants to merge 7 commits into
Conversation
sourcegraph.labels is documented as adding labels to all resources, and sourcegraph.serviceLabels to all Services, but the first reached only the workloads and a few other objects, and the second was not used at all. A customer moving from Kustomize needs their labels on every object, and a label key set in two values rendered twice, which Kustomize and kubeconform -strict reject. Each template keeps its own labels as literal lines and renders the user's labels with one helper: sourcegraph.objectLabels (sourcegraph.labels, then <serviceName>.labels) on a component's workloads, ConfigMaps, Secrets, standalone PVCs, ServiceAccounts, RBAC objects, PodDisruptionBudgets, and Ingress; sourcegraph.serviceLabels on Services; sourcegraph.podLabels on pods. They merge the values so each key renders once, and fail the render on a key the chart sets itself, or a pod label that changes a selector label; before, such a key rendered twice and Helm kept the last one. Renders with none of these values set are byte-identical. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20fe9-432c-754e-af86-b9c6a249e1d1
Every other Service, and the otel-collector pods, already have an app label. The otel-collector Service did not, and user labels cannot add it because app is a key the chart sets itself. Amp-Thread-ID: https://ampcode.com/threads/T-01a20fe9-432c-754e-af86-b9c6a249e1d1 Co-authored-by: Amp <amp@ampcode.com>
…rvice frontend.serviceLabels went on both frontend Services, so an install could not label sourcegraph-frontend without labeling sourcegraph-frontend-internal the same way. frontendInternal.serviceLabels, serviceAnnotations, and serviceType now configure the internal Service; annotations and type fall back to frontend.serviceAnnotations and frontend.internalServiceType as before.
Sourcegraph Cloud's controller sets <service>.podLabels app.kubernetes.io/component on every component, and its monitoring selects on those values, some of which differ from the object label (indexed-searcher, syntax-highlighter). The chart does not set that key on pods, so the reserved-key check failed every Cloud render. Pod labels are now checked only against the keys pod templates set: app, deploy, group, type, and worker-replica, plus the selector labels. frontendInternal.serviceLabels now falls back to frontend.serviceLabels, which main renders on sourcegraph-frontend-internal, so existing releases keep those labels. Amp-Thread-ID: https://ampcode.com/threads/T-01a20fe9-432c-754e-af86-b9c6a249e1d1 Co-authored-by: Amp <amp@ampcode.com>
frontendInternal.serviceLabels and serviceAnnotations fell back to the
frontend values whenever they were empty, so the internal Service could
not drop annotations meant for the public one, such as cloud load
balancer annotations. They now default to null, which still falls back,
and {} renders none.
Amp-Thread-ID: https://ampcode.com/threads/T-01a20fe9-432c-754e-af86-b9c6a249e1d1
Co-authored-by: Amp <amp@ampcode.com>
Every other workload takes podSecurityContext, extraVolumes, and extraVolumeMounts; otel-collector did not, so an extraInitContainers container, such as one fetching an exporter API key, had no volume to share with the collector. The pod security context renders only when set, so default renders do not change.
Which objects get the standard Helm labels, user labels, Service labels, and pod labels grew by accident. Write the rules into AGENTS.md and enforce them with two helm-unittest suites that render every template with every optional object enabled, so a new template is checked without being listed. Templates that predate the rules are listed as exceptions. Amp-Thread-ID: https://ampcode.com/threads/T-01a20fe9-432c-754e-af86-b9c6a249e1d1 Co-authored-by: Amp <amp@ampcode.com>
michaellzc
marked this pull request as ready for review
November 26, 2026 03:46
This branch has not been deployed
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.
Customers moving from Kustomize need their own labels on every object the chart renders, so their admission policies accept the install. Today
sourcegraph.labelsreaches only some templates,sourcegraph.serviceLabelsis never read, and overlapping labels render as duplicate keys thatkubeconform -strictand Kustomize reject. This is a smaller alternative to the #1008 stack: existing labels, selectors, and pod templates stay as they are.User labels now come from three helpers. Each merges its values so a key renders once, and fails the render on a key the chart sets itself:
sourcegraph.objectLabels:sourcegraph.labels, then<service>.labels, on every object except Services and pods.sourcegraph.serviceLabels:sourcegraph.serviceLabels, then<service>.serviceLabels, on every Service. Services never getsourcegraph.labels, because Prometheus copies Service labels onto metrics.sourcegraph.podLabels:sourcegraph.podLabels, then<service>.podLabels, on pod templates, after the selector labels. It fails on a label that would change a selector label.The convention around them, now in
AGENTS.mdand enforced bytests/labelConvention*_test.yamlon every rendered object: chart-owned labels stay literal lines in templates; selectors andvolumeClaimTemplatesnever get user labels; the standard Helm labels (sourcegraph.helmLabels) go only on workloads, plus the few templates that already had them.Also:
frontendInternalconfigures thesourcegraph-frontend-internalService separately fromsourcegraph-frontend, the otel-collector Service getsapp: otel-collector, andopenTelemetry.gatewaytakespodSecurityContext,extraVolumes, andextraVolumeMounts.Checklist
Test plan
kubectl diffand server-side dry-run against a Cloud dev instance change only one label,app: otel-collectoron the otel-collector Service. Nothing else changes.volumeClaimTemplates,serviceName) matches, so Helm can adopt it without recreating PVCs or StatefulSets. What still differs is chart-hardcoded, such as port names and probes.Source: https://ampcode.com/threads/T-01a20fe9-432c-754e-af86-b9c6a249e1d1