Repository navigation
fix/labels: Apply label values as documented, and render each key once - #1033
Draft
marcleblanc2 wants to merge 10 commits into
Draft
marcleblanc2 wants to merge 10 commits into
marcleblanc2 wants to merge 10 commits into
Conversation
Kustomize and other strict YAML parsers reject a map that repeats a key. The charts repeat a label or annotation key when it is set in two values, such as sourcegraph.labels and frontend.labels, or in a value and by the chart itself. sourcegraph.uniqueKeys takes the maps of one labels or annotations block, lowest precedence first, and renders each key once with its last value. That is the value Helm and Kubernetes already keep, so installed objects do not change. Lines pass through as written, so the rendered text is the same as before when no key repeats. Nothing calls the helper yet. Each chart gets the same file, like _priorityClassName.tpl. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085
A label key set in two values, such as sourcegraph.labels and frontend.labels, or in a value and by the chart, was rendered twice in the same labels block. Kustomize rejects that. Every labels block that takes labels from more than one place now lists the same items in the same order in sourcegraph.uniqueKeys. The last value of a key still wins, so no object of an installed release changes, and `helm template` renders the same text as before unless a key repeats. helm-unittest fails on a repeated key, as Kustomize does, so the new tests fail without this change. uniqueKeys_everyValue.yaml sets the same keys in every label value, with every optional object enabled. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085
An annotation key set in sourcegraph.podAnnotations and in a component's podAnnotations, or in a value and by the chart, such as prometheus.io/port in serviceAnnotations, was rendered twice in the same annotations block. Every annotations block that takes annotations from more than one place now lists the same items in the same order in sourcegraph.uniqueKeys. As with labels, the last value still wins and `helm template` renders the same text as before unless a key repeats. Three pod templates add a checksum annotation only when the chart manages the config. They build that line in a variable first, because a list item cannot sit inside an `if`. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085
The README says sourcegraph.labels adds labels to all resources, but only the workloads, the redis and jaeger ConfigMaps, the frontend Role and RoleBinding, the StorageClass, and the test pod got them: 31 of 108 objects with everything enabled. Add them to the Services, ServiceAccounts, ConfigMaps, Secrets, PersistentVolumeClaims, PodDisruptionBudgets, PriorityClasses, the Ingress, and the Prometheus RBAC objects. They come first in each block, so a label the chart or another value already sets keeps its value. Not added, and now documented: - Pod templates, which have sourcegraph.podLabels. Adding labels there would restart every pod. - StatefulSet volume claim templates. Kubernetes rejects an upgrade that changes them. - extraResources, which the chart renders as the user wrote them. Nothing changes unless sourcegraph.labels is set. When it is, the bundled Prometheus copies Service labels onto the metrics it scrapes through a Service, as it already does for <serviceName>.serviceLabels, so those metrics gain the labels. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085
The README documents sourcegraph.serviceLabels as extra labels for all Services, but no template read the value, so it did nothing. Add it to all 23 Services, after sourcegraph.labels, so it wins over the labels for every resource. A label the chart or a component's serviceLabels already sets keeps its value. Nothing changes unless sourcegraph.serviceLabels is set, and it had no effect before. As with any Service label, the bundled Prometheus copies these labels onto the metrics it scrapes through the Service. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085
The README documents sourcegraph.podLabels as labels for all pods. Every workload's pod template has them, but the pod that `helm test` creates did not, so a cluster that requires a label on every pod rejects it. The new test also asserts the labels on every workload's pod template, which already had them. Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085 Co-authored-by: Amp <amp@ampcode.com>
The README says sourcegraph.labels adds a global label to all resources, but no template read the value, so it did nothing. Add it to all seven objects: the Deployment, ConfigMap, Secret, Service, ServiceAccount, Role, and RoleBinding. It comes first in each block, so a label the chart or another value already sets keeps its value. The pod template is unchanged; it has sourcegraph.podLabels. Also list the items of the label and annotation blocks that take values from more than one place in sourcegraph.uniqueKeys, so a key set twice is rendered once. `helm template` renders the same text as before unless sourcegraph.labels is set or a key repeats. Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085 Co-authored-by: Amp <amp@ampcode.com>
The README says sourcegraph.labels adds a global label to all resources, but the docker-config ConfigMap and the private-docker-registry Service did not get it. Add it to both, first in the block, so the labels the chart sets keep their values. It is not added to pod templates, which have sourcegraph.podLabels, or to the registry's volume claim template, which Kubernetes does not allow changing. The README now says so. Also list the items of the label and annotation blocks that take values from more than one place in sourcegraph.uniqueKeys, so a key set twice is rendered once. `helm template` renders the same text as before unless sourcegraph.labels is set or a key repeats. Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085 Co-authored-by: Amp <amp@ampcode.com>
List the items of the Job's label and annotation blocks in sourcegraph.uniqueKeys, so a key set in two values, or in a value and by the chart, is rendered once. The last value still wins, and `helm template` renders the same text as before unless a key repeats. sourcegraph.labels already reached the Job, the chart's only object. The commented example values listed serviceLabels and serviceAnnotations, but the chart has no Service. Remove them. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085
Comments in values.yaml, and the README row generated from them: - sourcegraph.selectorLabelsOverride is documented for every component, but jaeger has its own selector helper and ignores it, as it ignores extraSelectorLabels. Changing jaeger's selectors would break upgrades of installed releases, so say what it does instead. - The example component block said labels, podLabels, and serviceLabels add labels to "various resources". Say which resources each reaches, and that jaeger's Services use collector.serviceLabels and query.serviceLabels. No template changes. Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085 Co-authored-by: Amp <amp@ampcode.com>
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.
A customer's clusters reject any resource that lacks their service labels, so they need labels on every resource these charts create. The READMEs say
sourcegraph.labelsdoes that, but it reached 31 of 108 objects in thesourcegraphchart, 0 of 7 insourcegraph-executor/k8s, and 2 of 4 insourcegraph-executor/dind.sourcegraph.serviceLabelsdid nothing.The charts also render a label or annotation key twice when it is set in two values, such as
sourcegraph.labelsandfrontend.labels, or in a value and by the chart. Helm and Kubernetes accept that and keep the last value. Kustomize andkubeconform -strictreject it.This PR makes the charts do what the READMEs say, and render each key once. It adds no values and changes no defaults.
What changes for an installed release
helm templaterenders the same text asmainfor all four charts.mainfor 749 workloads across 46 value sets.sourcegraph.labelsset, these gain the labels: Services, ServiceAccounts, ConfigMaps, Secrets, PersistentVolumeClaims, PodDisruptionBudgets, PriorityClasses, the Ingress, the Prometheus RBAC objects, and every object of the k8s and dind executor charts. The labels come first in each block, so a label the chart or another value already sets keeps its value.sourcegraph.serviceLabelsset, every Service gains the labels. The value had no effect before.<serviceName>.serviceLabels. Theapp,job,instance, andnsmetric labels cannot change: the chart'sapplabel wins on the Service, and Prometheus sets the others after it copies the labels.Review commit by commit
mainhelpers: add sourcegraph.uniqueKeys to each chartsourcegraph: render each label key oncesourcegraph: render each annotation key oncesourcegraph: add sourcegraph.labels to every resourcesourcegraph.labelsis setsourcegraph: add sourcegraph.serviceLabels to every Servicesourcegraph.serviceLabelsis setsourcegraph: add sourcegraph.podLabels to the helm test podsourcegraph.podLabelsis setsourcegraph-executor/k8s: add sourcegraph.labels to every resourcesourcegraph.labelsis set or a key repeatssourcegraph-executor/dind: add sourcegraph.labels to every resourcesourcegraph.labelsis set or a key repeatssourcegraph-migrator: render each label and annotation key oncesourcegraph: document what jaeger and the per-component label values dovalues.yamland one README rowThe helper
sourcegraph.uniqueKeystakes the items of one labels or annotations block, lowest precedence first, and renders each key once with its last value. A block lists the same lines it had before:It passes lines through as written instead of merging maps, so the rendered text is the same as before when no key repeats. Each chart has its own copy in
templates/_helpers/_uniqueKeys.tpl, like_priorityClassName.tpl.Not changed
sourcegraph.labels. They havesourcegraph.podLabels, and adding labels there would restart every pod.sourcegraph.labels. Kubernetes rejects an upgrade that changes them. The READMEs now say so.extraResourcesare rendered as the user wrote them.jaegerselectors. The README sayssourcegraph.selectorLabelsOverrideand<serviceName>.extraSelectorLabelsapply to every component, butjaegerignores them. Making it honour them would change its selector on installed releases, sovalues.yamlnow says what it does.storageLabelsandserviceAccount.labelsvalues stay in feat/labels: Add labels to PVCs, ServiceAccounts, and RBAC objects #1008, which will need a rebase onto this.jaeger.serviceAccount.create: truefails to render onmain, and still does.Tests
examples/*/override.yaml, selector overrides, executor queues) rendered frommainand from this branch with Helm 4.3.1 and 3.9.1. 43 render the same text, apart from whitespace-only linesmainrenders whenselectorLabelsOverrideis set. The other 3 setsourcegraph.labels, and differ only by those labels added tometadata.labels.sourcegraph.labelsreaches 108 of 108 objects insourcegraph, 7 of 7 insourcegraph-executor/k8s, and 5 of 5 insourcegraph-executor/dind.tests/uniqueKeys_everyValue.yaml),kubeconform -strictaccepts 108 of 108 objects. Onmainit rejects 54.kubectl kustomizebuilds that render; onmainit fails.main. The suites forsourcegraph.labels,sourcegraph.serviceLabels, andsourcegraph.podLabelsassert on every template, so a new template that leaves them out fails.scripts/ci/lint.shandscripts/helm-docs.share clean.Design decisions
jaegerselectors), the README says what the chart does.