Skip to content

fix(prometheus): keep the operator's own Prometheus working with prometheus.enabled off - #957

Closed
boddumanohar wants to merge 15 commits into
prometheus-operator-migrationfrom
fix/prom-migration-upgrade-path
Closed

boddumanohar wants to merge 15 commits into
prometheus-operator-migrationfrom
fix/prom-migration-upgrade-path

Conversation

@boddumanohar

Copy link
Copy Markdown
Member

Makes #692 safe to merge for upgrades from 26.3. An upgrade runs with prometheus.enabled=false, so the operator keeps running simplyblock-prometheus. #692 broke that path in three ways, and the bundled-stack path had one more bug.

Path Problem in #692 Fix
prometheus.enabled=false The management API stopped trusting simplyblock-prometheus, so every scrape got a 401 The operator always trusts its own Prometheus, then any accounts the chart adds
prometheus.enabled=false Control Center pointed at prometheus-operated, which doesn't exist on this path prometheus.simplyblock.prometheusURL defaults to empty and follows prometheus.enabled
prometheus.enabled=false Thanos Query lost the sidecar --store, so the newest ~2 h were missing from Grafana The --store line is back whenever prometheus.enabled is off
prometheus.enabled=true The ScrapeConfig used authorization.credentialsFile, which prometheus-operator doesn't have It uses authorization.credentials with the token of a new chart ServiceAccount simplyblock-metrics-scraper, which the management API trusts

Also runs gofmt on prometheus.go and prometheus_test.go from #692, which make lint rejected.

Tests (each failed before the fix)

  • TestTheOperatorsOwnPrometheusStaysTrusted replaces TestNoExtraMetricsServiceAccountsMeansNoneAreTrusted, which asserted the 401 behavior. TestExtraMetricsServiceAccountsReachTheManagementAPI now expects the operator's own account first.
  • helm-charts/scripts/test-prometheus-values.sh renders both paths and checks the Control Center URL, the Thanos stores, the ScrapeConfig authorization, and the trusted account. It's added to the Helm lint workflow.

Not tested on a live cluster. make lint passes, and so do the controlplane package tests and helm lint.

Not covered here

  • Turning on prometheus.enabled doesn't delete a simplyblock-prometheus that's already running.
  • With prometheus.enabled on, metricsAPI.prometheusURL still defaults to simplyblock-prometheus.
  • helm upgrade doesn't install the kube-prometheus-stack CRDs on an existing release.

#953 handles these through the Managed/External mode.

https://claude.ai/code/session_011oztNZUjNFk6NYW7UXA1A2

mxsrc and others added 15 commits November 18, 2026 15:01
…prometheus-operator

Lets a customer running their own prometheus-operator scrape this chart's
targets via ServiceMonitor/PodMonitor objects instead of the bundled
`prometheus` subchart's static scrape config. Gated behind
`prometheusOperator.enabled`, mutually exclusive with `prometheus.enabled`,
and failing fast when the monitoring.coreos.com CRDs aren't present.

The webappapi Service carried no labels of its own, only a Pod selector, so a
ServiceMonitor had nothing to match it by.
…own prometheus-operator

Converts the Grafana-provisioned alert rules and contact points in
controlplane_configmap.yaml into a PrometheusRule (all eleven rules, same
expr/for/labels/annotations) and an AlertmanagerConfig built from the same
controlplane.observability.grafana.notifications.* values, so a customer's own
Alertmanager can route these alerts instead of Grafana's alerting engine.

Independent of the previous commit's ServiceMonitor/PodMonitor objects: a
customer can take the scrape config without the rules, or the rules without
alert routing, since the PrometheusRule renders whenever prometheusOperator.enabled
is true regardless of which (if any) notifications.* receiver is configured.
…block.io annotations

Nothing reads prometheus.simplyblock.io/scrape|port|path: the bundled static
prometheus.yml has no annotation-based (kubernetes_sd_configs) discovery, and
the PodMonitor added for prometheus-operator selects storage node pods by the
role=simplyblock-storage-node label, not by annotation. They predate both
scrape paths and had no consumer in either.

The test asserting these annotations could not have caught their removal: it
rebuilds its "expected" pod by replaying injectSidecar and re-setting the same
constants by hand, rather than reading them off the real admission patch, so
it was checking its own fixture rather than the webhook's output.

Also fixes two preexisting house-style findings the quality gate surfaced on
this file (a British spelling, a misplaced closing quotation mark), unrelated
to this change but in a file this commit already touches.
Same pattern as the rebalancer's PodMonitor: selects storage node pods by
role=simplyblock-storage-node and scrapes a named container port rather than a
fixed number, since each proxy binds its own RPC_PORT on the host network.
Assumes the proxy-http port (added to the storage node pod template in the
control-plane repo) and an unauthenticated /_meta/metrics are both in place.
…or only

This chart deployed its own prometheus-community/prometheus subchart as one
of two scrape paths, mutually exclusive with the bring-your-own
prometheus-operator path (ServiceMonitor/PodMonitor/ScrapeConfig/
PrometheusRule/AlertmanagerConfig). Removes the bundled path entirely, since
maintaining two ways to scrape the same targets only kept the gap between
them from ever being forced shut.

Removed:
- The `prometheus` Chart.yaml dependency and its vendored tarball.
- The entire `prometheus:` values block (server, alertmanager,
  prometheus-pushgateway, prometheus-node-exporter, kube-state-metrics,
  configmapReload, defaultBackend) except `simplyblock.{prometheusURL,
  prometheusPORT}`, which Control Center's own Prometheus link still falls
  back to and now defaults empty.
- The legacy `simplyblock-prometheus-config` static scrape ConfigMap
  (controlplane_configmap.yaml), including its lookup-based preserve-on-
  upgrade trick.
- The Thanos querier's per-replica --store= flags against the bundled
  Prometheus's own thanos-sidecar (controlplane_deploy.yaml), which pointed
  at StatefulSet pods nothing creates once the subchart is gone.
- The now-moot prometheus.enabled/prometheusOperator.enabled mutual-
  exclusivity fail check.

Also corrected two assumptions the bundled subchart's existence had let the
code carry silently:
- managementapi.go's SB_K8S_METRICS_SERVICE_ACCOUNTS trusted the bundled
  subchart's own ServiceAccount by default; with no bundled Prometheus ever
  presenting that identity, the entry was dead weight. The management API
  now trusts only identities the chart names via prometheusOperator's
  configured account (SB_EXTRA_METRICS_SERVICE_ACCOUNTS), the same way
  SB_K8S_ADMIN_SERVICE_ACCOUNTS already works.
- podspec.go's hardcoded PROMETHEUS_URL/PROMETHEUS_PORT (where the control
  plane pushes what it measures) still names the bundled chart's old Service,
  which nothing creates anymore. Left as-is and flagged in its own comment:
  making this configurable is a separate change this commit does not make.
prometheus-operator is the only scrape path this chart supports now, so
there is no second `prometheus` value left to collide with: the old
prometheus.simplyblock.{prometheusURL,prometheusPORT} (Control Center's own
fallback) is folded in as a sibling of enabled/additionalLabels/interval/
serviceAccount under one prometheus: key, and every .Values.prometheusOperator
reference, fail-fast message, and prose mention is renamed to match.
…when enabled

prometheus.enabled now needs nothing installed beforehand: it brings its own
prometheus-operator (kube-prometheus-stack 92.2.0, condition:
prometheus.enabled) by default — CRDs, the controller, one Prometheus, and
Alertmanager (for the PrometheusRule/AlertmanagerConfig objects this chart
also renders). Grafana, node-exporter, and kube-state-metrics stay off: a
scrape target for the customer's own dashboards, not a second monitoring
stack.

The bundled Prometheus's ServiceAccount is pinned to a literal name
(simplyblock-prometheus-operator) rather than left to kube-prometheus-stack's
own release-derived default, so prometheus.serviceAccount can name it without
predicting it — the metrics-scraper trust that used to need a manual
`kubectl get prometheus ... serviceAccountName` lookup is wired by default
now. Its prometheusSpec also turns off every selector's
NilUsesHelmValues, which otherwise restricts discovery to objects carrying a
release label this chart's own ServiceMonitor/PodMonitor/ScrapeConfig/
PrometheusRule objects don't set.

To scrape with a prometheus-operator the customer already runs instead, every
component kube-prometheus-stack renders has to be turned off explicitly
(values.yaml documents the full list — cluster-component scrapers and
defaultRules are separate toggles that don't follow
prometheusOperator.enabled/prometheus.enabled, discovered by testing each
override combination against `helm template` until nothing from the
dependency rendered). Left on with monitoring.coreos.com CRDs already present
from elsewhere, the chart now fails fast rather than installing a second
prometheus-operator: a release-ownership check (via `lookup`, comparing the
existing ServiceMonitor CRD's meta.helm.sh/release-name annotation against
this release) tells apart "ours, from import a prior upgrade of this same
release" from "somebody else's."

The existing "CRD missing" fail-fast checks in
prometheus-operator-servicemonitors.yaml and prometheus-operator-alerting.yaml
had to change shape too: .Capabilities.APIVersions is captured before this
same install's own kube-prometheus-stack dependency would create its CRDs, so
on a fresh bundled install the literal capability check would fail an install
that was about to supply the CRD itself. They now skip that check entirely
whenever bundling is in effect (simplyblock.bundlesPrometheusOperator) and
trust Helm's own install ordering instead, applying only to the
not-bundling (bring-your-own) path.
…eus subchart removal deleted

TestAKeyHoldingDotsIsOneSegment anchored on prometheus.server.extraArgs."storage.tsdb.min-block-duration",
which no longer exists now that the bundled Prometheus subchart is gone. Point it at an Ingress annotation
key instead, and resync the chart/ copy this module keeps of values.yaml and Chart.yaml.
…already scrapes it

managementAPIObjects always applied a Prometheus+Thanos StatefulSet, unconditionally,
for every local ControlPlane install -- including one where the chart's own
prometheus.enabled path (bundled kube-prometheus-stack, or bring-your-own) already
scrapes the management API through a ServiceMonitor. The two ran side by side,
duplicating scrapes, with no flag to turn either off.

Detect the chart's ServiceMonitor instead of adding a new one, matching the
convention internal/prerequisites already uses for cert-manager and the other
cluster add-ons: check what's on the cluster before installing, rather than
threading a coordination flag through the chart and the CRD. Present, this
control plane's own Prometheus, Thanos, and RBAC are left out of the apply.

Known gap: flipping prometheus.enabled on for an install that already has its
own Prometheus StatefulSet leaves that StatefulSet in place rather than
deleting it -- applyAll only ever applies what's in the set, never prunes.
…etheus.enabled off

An upgrade from 26.3 runs with prometheus.enabled=false, where the operator
still runs simplyblock-prometheus. The migration broke that path three ways:

- The management API no longer trusted simplyblock-prometheus, so every
  scrape got a 401. The operator now always trusts it, then the chart's extras.
- Control Center's Prometheus URL defaulted to prometheus-operated, which only
  exists with the bundled stack. It now follows prometheus.enabled.
- Thanos Query lost the sidecar --store, hiding the newest two hours. It is
  back whenever prometheus.enabled is off.

With prometheus.enabled on, the ScrapeConfig used authorization.credentialsFile,
which prometheus-operator does not have. It now presents the token of a chart
ServiceAccount, simplyblock-metrics-scraper, which the management API trusts.

helm-charts/scripts/test-prometheus-values.sh checks both renders and runs in
the Helm lint workflow.

Claude-Session: https://claude.ai/code/session_011oztNZUjNFk6NYW7UXA1A2
…ers (#932)

* fix(ci): run the CSI unit and integration suites on Ubuntu 26.04 runners

ubuntu-latest moved to 26.04 between two runs on main (7983a98 passed,
1c4fb97 failed), which brings two changes the tests assumed away.

- coreutils comes from uutils, where sleep is a hard link to one
  multicall binary that picks the utility from its own name. The
  nfsexport tests copied sleep as rpc.idmapd and nfsdcld to fake a
  running daemon. The copy refused to run and exited, so the "already
  running" tests lost a race on every run. The fake is now a copy of the
  test binary, which sleeps when NFSEXPORT_FAKE_PROCESS is set.
- sudo is sudo-rs, which ignores -E and warns on stderr. The integration
  harness ran talosctl under sudo -E for HOME and KUBECONFIG. talosctl
  ran with root's HOME, and the warning landed in the JSON the harness
  parses, so no suite brought its cluster up. Both variables are now
  passed by name through env, in the harness and in the workflow's
  diagnostics and cleanup steps.

Verified on an ubuntu:26.04 container: TestAFakeProcessKeepsRunning is
red before and green after, and the nfsexport package passes three runs
under -race -cover. The sudo change is unit-tested on the arguments
only; the integration job on this PR is its live check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(ci): set talosctl's HOME and KUBECONFIG as sudo arguments, not through env

Running talosctl through `sudo env` changed the command sudo authorizes
from talosctl to env, which the scoped SETENV grant in the integration
README does not cover. An unattended developer host would have been
prompted, while the GitHub runner's NOPASSWD: ALL hid it. The variables
are now sudo's own VAR=value arguments, which that grant covers.

Checked on ubuntu:26.04 with sudo-rs 0.2.13: VAR=value works under both
NOPASSWD: ALL and a scoped SETENV grant, and the scoped grant refuses
the env form. README and workflow steps updated to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit bda2665)
@boddumanohar

Copy link
Copy Markdown
Member Author

Folded into #692: the two fix commits were cherry-picked onto #692, which is now rebased onto main (head f060523). The #932 commit was left out because main already has it, and the installer regeneration was dropped because main no longer commits operator/dist/install.yaml (#938).

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.

3 participants