Skip to content

feat/labels: Add labels to PVCs, ServiceAccounts, and RBAC objects - #1008

Open
marcleblanc2 wants to merge 2 commits into
mainfrom
marc/pvc-serviceaccount-labels
Open

marcleblanc2 wants to merge 2 commits into
mainfrom
marc/pvc-serviceaccount-labels

Conversation

@marcleblanc2

@marcleblanc2 marcleblanc2 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  • A customer migrating from Kustomize requires the ability to add their own labels to parts of our product
  • The standalone PVCs hardcode their labels, and ServiceAccounts and RBAC objects have no label values

Solution

  • <serviceName>.storageLabels for the seven standalone PVCs: blobstore, codeInsightsDB, codeIntelDB, pgsql, prometheus, redisCache, redisStore
  • preciseCodeIntel.storageLabels and syntacticCodeIntel.storageLabels for the per-pod scratch PVC when storageType is pvc
  • Every PVC the sourcegraph chart creates now has a storageLabels value
    • On the StatefulSet PVCs, it applies to new claims only and can't change after install
  • <serviceName>.serviceAccount.labels for every ServiceAccount, and for the RBAC objects of frontend and prometheus
    • sourcegraph.labels and the standard Helm labels now also render on these objects too
  • The README now lists which values label each kind of PVC
    • PVCs that Kubernetes creates from a StatefulSet's volume claim template take only storageLabels, on purpose: Kubernetes rejects changes to those templates
  • Also fixes jaeger.serviceAccount.create: true, which failed to render when a label is applied
  • A key set in both sourcegraph.labels and one of these values renders once, with the component's value; the chart's own labels win over both. Kustomize and kubeconform -strict rejected the duplicate key (Slack report)

Upgrade impact

  • Only labels change, in place, on PVCs, ServiceAccounts, and the prometheus ClusterRole and ClusterRoleBinding

Tested

  • New tests/objectLabels_test.yaml covers every PVC, ServiceAccount, and RBAC template. The two code intel storage tests cover the scratch PVC
  • helm unittest (274 tests), helm lint, helm-docs, and kubeconform -strict pass
  • Rendered against main: only those object kinds differ, and no PVC spec changes
  • Rendered with storageType: pvc: the same output as before until storageLabels is set, then only the scratch PVC's labels differ
  • Upgraded the EKS test instance m5 from main to this head (e167670) on 2026-11-24, with sourcegraph.labels, storageLabels on all seven standalone PVCs, and frontend.serviceAccount.labels set. m5 is a Kustomize install adopted by Helm, with bundled databases, under restricted Pod Security
    • Only labels changed, on the 7 PVCs, 3 ServiceAccounts, the frontend Role and RoleBinding, and the prometheus RoleBinding (m5 sets prometheus.privileged: false)
    • 0 pods replaced, and no object UID, Service IP, or PVC volume changed
    • The labels the PVCs already had from Kustomize stayed on them, on main and on this branch
    • Search and an executor batch spec work afterwards
    • Not on the cluster: storageType: pvc, which m5 doesn't use
  • Duplicate label keys, on m5 on 2026-11-24, with the same example.com/team key in sourcegraph.labels, blobstore.storageLabels, and frontend.serviceAccount.labels:
    • Previous head e167670: 6 objects had a duplicate key, and kubeconform -strict failed on them
    • This head 4e26fac: 2 objects, the frontend Deployment and pgsql StatefulSet, which also have it on main; feat/labels: Apply sourcegraph.labels to all objects in all four charts #1023 fixes those
    • Upgrading from e167670 to 4e26fac changed 0 live objects and replaced 0 pods, so each object keeps the label value Kubernetes applied

Amp threads

Changelog

  • Added <serviceName>.storageLabels and <serviceName>.serviceAccount.labels
  • sourcegraph.labels and the standard Helm labels are now on PVCs, ServiceAccounts, and the prometheus RBAC objects

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

@marcleblanc2
marcleblanc2 added this pull request to stack #1009 November 11, 2026 17:12
@marcleblanc2
marcleblanc2 force-pushed the marc/pvc-serviceaccount-labels branch from 3d258bf to aaffaa9 Compare November 11, 2026 17:45
@marcleblanc2 marcleblanc2 changed the title sourcegraph: add labels to PVCs, ServiceAccounts, and RBAC objects Render sourcegraph.labels on every object, and add storage and ServiceAccount labels Nov 11, 2026
@marcleblanc2
marcleblanc2 force-pushed the marc/pvc-serviceaccount-labels branch from 679ac13 to 7e6b950 Compare November 11, 2026 22:59
Base automatically changed from marc/selector-labels to main November 13, 2026 05:38
marcleblanc2 added a commit that referenced this pull request Nov 13, 2026
Prometheus does not reload a changed ConfigMap by itself, so an upgrade that
keeps the image tag swapped the RBAC resources while the pod kept running
the old scrape configuration.

The annotation, its test, and the changelog entry are the same as in #1008.
@marcleblanc2
marcleblanc2 force-pushed the marc/pvc-serviceaccount-labels branch from 6fd1fe2 to 756d760 Compare November 13, 2026 06:26
@marcleblanc2
marcleblanc2 marked this pull request as draft November 13, 2026 10:14
@marcleblanc2 marcleblanc2 changed the title Render sourcegraph.labels on every object, and add storage and ServiceAccount labels Apply sourcegraph.labels to all objects, and add storage and ServiceAccount labels Nov 18, 2026
@marcleblanc2
marcleblanc2 force-pushed the marc/pvc-serviceaccount-labels branch from 05bb302 to 71215b0 Compare November 18, 2026 18:09
@marcleblanc2 marcleblanc2 changed the title Apply sourcegraph.labels to all objects, and add storage and ServiceAccount labels feat/labels: Add labels to PVCs, ServiceAccounts, and RBAC objects Nov 18, 2026
@marcleblanc2
marcleblanc2 force-pushed the marc/pvc-serviceaccount-labels branch 2 times, most recently from d12bb2f to 42d6937 Compare November 18, 2026 20:08
Render sourcegraph.labels on the standalone PersistentVolumeClaims, every
ServiceAccount, and the prometheus RBAC objects, and add per-component
storageLabels and serviceAccount.labels values, so a release that takes over
objects created outside the chart can keep the labels they already have.

Also fix the jaeger ServiceAccount, which read its name and annotations from
a tracing value that does not exist and failed to render.

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

A key set in both sourcegraph.labels and a component's storageLabels or
serviceAccount.labels rendered twice in the object's labels. Helm keeps the
last one, but Kustomize and kubeconform -strict reject the output.

A new sourcegraph.mergedLabels helper merges the common labels, the
component's labels, and the labels the chart sets itself into one map, in
that order, so a later value wins and each key is rendered once. Renders with
default values are unchanged apart from key order.

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

This branch has not been deployed

No deployments
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.

1 participant