feat(init): bundle Prometheus + fix OpenCost RBAC (follow-up to #21)#22
Merged
Conversation
OpenCost watches PodDisruptionBudgets; without the rule its reflector spams "poddisruptionbudgets.policy is forbidden". Caught on a real cluster.
…ined OpenCost has a hard Prometheus dependency; on a cluster without Prometheus it crash-loops (FTL) no matter the endpoint. Make init deploy the whole Tier-2 stack so cost works in one command, no prerequisites — caught on a real cluster running SigNoz (no Prometheus). - Embed a minimal Prometheus manifest (monitoring namespace, scrapes kubelet/cAdvisor) at prometheus-server.monitoring.svc:80 — which is both OpenCost's default endpoint AND a kubetidy auto-detect candidate, so scan Tier-1 and OpenCost Tier-2 both find it with zero config. - `init --with-opencost` now also deploys the bundled Prometheus unless --prometheus-url points at an existing one (then the bundle is skipped). - `init --with-prometheus` deploys just Prometheus (unlocks Tier 1) on its own. - `uninstall --with-prometheus` removes it — but never the shared `monitoring` namespace (deleteManifestSkipNamespaces), so a user's other tooling is safe. - --print includes whatever --with-* flags select. - Docs: README setup + Tier 2, ROADMAP, CHANGELOG.
… proxy scan runs on the user's machine, but auto-detection returned an in-cluster Service DNS name (*.svc) that only resolves inside the cluster. Every query failed with "no such host" and the scan silently reported a misleading 100/100 $0 (zero usage mistaken for zero waste) — hit on a real cluster. - Reach an auto-detected Prometheus/OpenCost through the Kubernetes API server proxy (/api/v1/namespaces/<ns>/services/<svc>:<port>/proxy), reusing the kubeconfig's API server address + credentials. Works wherever kubectl works, no port-forward. - Validate reachability (a trivial `up` query / live allocation fetch) before committing to Tier 1 / Tier 2; an unreachable endpoint falls back to the operator / metrics-server / derived pricing with a clear note. - Expose kube.Clients.RESTConfig; add DetectPrometheusEndpoint / DetectOpenCostEndpoint (+ struct), NewPrometheusProviderViaAPIProxy, NewOpenCostProviderViaAPIProxy, and usage.Reachable. Auto-detect now sits behind provider seams (prometheusAutoProvider / openCostAutoProvider). - An explicit --prometheus-url / --opencost-url is still used directly.
…ntext Workload names with dots (CSI drivers like rbd.csi.ceph.com-nodeplugin) or other regex metacharacters produced `unknown escape sequence U+002E '.'`: regexp.QuoteMeta yields `\.`, which is an invalid escape inside a PromQL double-quoted string, so those workloads were skipped. Double the backslashes when embedding the pod regex. Caught on a real cluster.
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 a follow-up
PR #21 was merged right after its first commit, before two further commits landed on the branch. Both were found while testing #21 on a real cluster (running SigNoz, no Prometheus). This PR brings them into
main.1. Fix: OpenCost RBAC missing
policy/poddisruptionbudgetsOpenCost watches PodDisruptionBudgets; without the rule its reflector spammed
poddisruptionbudgets.policy is forbidden. Adds thepolicygroup to the embedded ClusterRole.2. Feature: bundle Prometheus so
init --with-opencostis self-containedOpenCost has a hard Prometheus dependency — on a cluster without one it crash-loops (
FTL Failed to create Prometheus data source ... no such host), no matter the endpoint. That's exactly what happened in testing. Soinitnow deploys the whole Tier-2 stack:internal/installer/assets/prometheus.yaml) — monitoring namespace, scrapes kubelet/cAdvisor, atprometheus-server.monitoring.svc:80. That address is both OpenCost's default endpoint and a kubetidy auto-detect candidate, so scan Tier-1 and OpenCost Tier-2 both find it with zero config.init --with-opencostnow also deploys the bundled Prometheus unless--prometheus-urlpoints at an existing one (then the bundle is skipped).init --with-prometheusdeploys just Prometheus (unlocks Tier-1 history) on its own.uninstall --with-prometheusremoves it — but never the sharedmonitoringnamespace (deleteManifestSkipNamespaces), so a user's other tooling is safe.--printincludes whatever--with-*flags select.The bundled Prometheus is deliberately minimal (single replica, ephemeral storage, 15-day window) — great for getting cost working immediately; run your own and pass
--prometheus-urlfor durable metrics.Tests
internal/installer/opencost_test.go: Prometheus manifest decode (7 kinds) + correct default endpoint;Uninstall --with-prometheuslogs removal and keeps the namespace;deleteManifestSkipNamespacespreserves a seededmonitoringnamespace.internal/cli/init_test.go:includePrometheus()truth table;--printbundles Prometheus with--with-opencost/--with-prometheus, omits the bundle when--prometheus-urlis given.Full gate green: build, vet, gofmt,
go test ./..., golangci-lint (0 issues).🤖 Generated with Claude Code