Skip to content

[helm][kuberay-operator] Don't emit empty ServiceMonitor labels; rename selector -> additionalLabels#4979

Merged
kevin85421 merged 3 commits into
ray-project:masterfrom
kevin85421:fix-servicemonitor-labels
Jul 7, 2026
Merged

[helm][kuberay-operator] Don't emit empty ServiceMonitor labels; rename selector -> additionalLabels#4979
kevin85421 merged 3 commits into
ray-project:masterfrom
kevin85421:fix-servicemonitor-labels

Conversation

@kevin85421

Copy link
Copy Markdown
Member

Why are these changes needed?

Two fixes to helm-chart/kuberay-operator/templates/servicemonitor.yaml:

1. Don't emit an empty labels: block

The template unconditionally rendered a labels: key:

  labels:
    {{- with .Values.metrics.serviceMonitor.selector }}
      {{- toYaml . | nindent 4 }}
    {{- end }}

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 as OutOfSync. The labels: key is now wrapped in {{- with }} so it's only emitted when labels are actually configured.

2. Rename selectoradditionalLabels

.Values.metrics.serviceMonitor.selector populates the ServiceMonitor's metadata.labels — it is not a selector. The name was confusing because:

  • It sets labels, not a selector.
  • It collided conceptually with the template's real spec.selector (which selects the Service to scrape).

The value exists so that Prometheus can discover this ServiceMonitor via its serviceMonitorSelector (e.g. release: prometheus for kube-prometheus-stack). additionalLabels matches 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.selector must switch to metrics.serviceMonitor.additionalLabels. Happy to instead keep selector as a deprecated fallback for one release if reviewers prefer a non-breaking path.

Related issue number

Checks

values.yaml and the helm-docs-generated README.md row were updated to match. Verified with helm lint (passes) and helm template:

  • ServiceMonitor enabled, no additionalLabels → no labels: key rendered.
  • ServiceMonitor enabled, additionalLabels.release=prometheusmetadata.labels.release: prometheus rendered.

🤖 Generated with Claude Code

kevin85421 and others added 2 commits July 6, 2026 18:15
…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>

@Future-Outlier Future-Outlier left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevin85421 kevin85421 merged commit bb6a02f into ray-project:master Jul 7, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants