[helm][kuberay-operator] Don't emit empty ServiceMonitor labels; rename selector -> additionalLabels#4979
Merged
kevin85421 merged 3 commits intoJul 7, 2026
Conversation
…ename selector -> additionalLabels
The ServiceMonitor template always rendered a `labels:` key even when no
labels were configured. With the default empty value this produced an
empty `metadata.labels`, which does not match the object Kubernetes
stores, causing ArgoCD to report the resource as OutOfSync. Wrap the
`labels:` key in `{{- with }}` so it is only emitted when labels are set.
Also rename `metrics.serviceMonitor.selector` to
`metrics.serviceMonitor.additionalLabels`. The value populates the
ServiceMonitor's `metadata.labels`, not a selector, and the old name
collided conceptually with the template's real `spec.selector`. The new
name matches the convention used by other charts (e.g.
kube-prometheus-stack) and makes it clear these labels exist so Prometheus
can discover the ServiceMonitor via its `serviceMonitorSelector`.
BREAKING CHANGE: users setting `metrics.serviceMonitor.selector` must
switch to `metrics.serviceMonitor.additionalLabels`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Cover that the ServiceMonitor is only rendered when enabled, that metadata.labels is omitted when no additionalLabels are set (the ArgoCD OutOfSync fix), that additionalLabels populate metadata.labels, and the namespace defaulting/override behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
rueian
approved these changes
Jul 7, 2026
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.
Why are these changes needed?
Two fixes to
helm-chart/kuberay-operator/templates/servicemonitor.yaml:1. Don't emit an empty
labels:blockThe template unconditionally rendered a
labels:key:With the default (empty) value, this produced an empty
metadata.labels, which doesn't match what Kubernetes actually stores on the object. As a result ArgoCD reports the ServiceMonitor asOutOfSync. Thelabels:key is now wrapped in{{- with }}so it's only emitted when labels are actually configured.2. Rename
selector→additionalLabels.Values.metrics.serviceMonitor.selectorpopulates the ServiceMonitor'smetadata.labels— it is not a selector. The name was confusing because:spec.selector(which selects the Service to scrape).The value exists so that Prometheus can discover this ServiceMonitor via its
serviceMonitorSelector(e.g.release: prometheusfor kube-prometheus-stack).additionalLabelsmatches the convention used by other charts (e.g. kube-prometheus-stack) and describes what the field actually does.Warning
Breaking change: users setting
metrics.serviceMonitor.selectormust switch tometrics.serviceMonitor.additionalLabels. Happy to instead keepselectoras a deprecated fallback for one release if reviewers prefer a non-breaking path.Related issue number
Checks
values.yamland the helm-docs-generatedREADME.mdrow were updated to match. Verified withhelm lint(passes) andhelm template:additionalLabels→ nolabels:key rendered.additionalLabels.release=prometheus→metadata.labels.release: prometheusrendered.🤖 Generated with Claude Code