feat(cost): CI cost-guardrail — price manifest changes, flag/block PR $ deltas#20
Merged
Conversation
… $ deltas
New `kubetidy cost` command (Phase 2): prices CPU/memory requests in Kubernetes
manifests with no cluster access, and — given --base/--head — reports the monthly
$ a change adds or saves ("this change adds $88/mo"). The CI guardrail.
- internal/manifest: pure YAML/JSON → []model.Workload parser (Deployments,
StatefulSets, DaemonSets, ReplicaSets; requests normalized to millicores/bytes),
plus CostWorkloads + Compare (added/removed/changed/unchanged + net delta).
- internal/cli/cost.go: `cost [manifests…]` or `--base/--head` (file or dir);
table or `-o json`; `--fail-over <budget>` exits non-zero on a net increase >
budget; `--cpu-cost/--mem-cost` overrides. Uses derived blended pricing.
- docs/examples/cost-guardrail.yml: ready-to-copy GitHub Action (comment the delta
via git worktree base-diff + optional budget enforcement). Under docs/ so it
doesn't auto-run on this repo.
- docs: README cost section, ROADMAP checked off, CHANGELOG (Unreleased).
Coverage: manifest 86.1%, cost CLI paths tested (diff, guardrail pass/fail, total,
no-input). Full build/vet/fmt/test/lint green.
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.
Implements the roadmap's CI cost-guardrail (Phase 2): a
kubetidy costcommand that prices a PR's resource-request changes — no cluster needed — so CI can say "this PR adds $400/mo" and optionally block it.Usage
How
internal/manifest— pure YAML/JSON →[]model.Workloadparser (Deployment/StatefulSet/DaemonSet/ReplicaSet; requests normalized to millicores/bytes), plusCostWorkloads(× replicas, viacostmodel) andCompare(added/removed/changed/unchanged + net delta).internal/cli/cost.go—cost [manifests…]or--base/--head(file or dir);table/json;--fail-over <budget>is the CI gate;--cpu-cost/--mem-costoverrides. Derived blended pricing (no cluster).docs/examples/cost-guardrail.yml— ready-to-copy GitHub Action: diffs base vs head viagit worktree, comments the table on the PR, and enforces a budget. Kept underdocs/so it doesn't auto-run on this repo.Tests
internal/manifest86.1% (parser incl. DaemonSet defaults, namespace default, bad-YAML error; Compare add/remove/change).costCLI: diff output, guardrail pass/fail, single-set total, no-input error. Fullgo build/vet/gofmt/test ./...+golangci-lint(0 issues) green.Follow-ups
uses: mayur-tolexo/kubetidy@v0) wrapping this.