All jobs

Add Pre-commit Hooks to a Kubernetes Manifest Repository

Yes. An agent adds pre-commit hooks that lint your manifests with yamllint and validate them with kubeconform, tuned to your files, and opens a PR with what remains.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads what the repository checks today before it adds a hook, and in a manifest collection like kubernetes/examples the answer is almost nothing on a commit. There is no .github/ directory, no .pre-commit-config.yaml and no .yamllint; the only automation is tests/e2e/e2e-kind, a script that downloads kind v0.32.0, creates a cluster and runs web/guestbook/e2e/test-kind, which builds two images with Docker, applies six manifests, waits for the rollout and the Redis replication link, port-forwards the frontend and writes and reads one message. That is an end-to-end test of one example, not a check of the YAML in the others. guidelines.md sets the rules the manifests are meant to follow: stable APIs, image tags pinned to a version rather than latest, realistic resource requests and limits. The live tree has 40 manifest files under AI/, databases/, nginx-platform-app/ and web/ holding 56 resources, four of which are Prometheus Operator custom resources under AI/vllm-deployment/hpa/, three ServiceMonitor and one PrometheusRule; _archived/ holds the retired examples, and two YAML files under databases/cassandra/ are Cassandra's own configuration, not Kubernetes objects.

The hooks have to fit those files, so the agent runs the tools over the tree first and writes the config from what it sees. yamllint with its default rules reports 316 problems in 42 files, dominated by line-length and indentation, because these manifests write list items at the same indent as their parent key, and by document-start on every file without a leading ---; those are house style, not defects. A .yamllint.yaml that extends default, sets indentation to indent-sequences: consistent, disables document-start, raises line-length to 120 as a warning, allows one space before a comment and ignores _archived/ and the two Cassandra files leaves 28 errors and 5 warnings in 16 files, and those are real: trailing spaces, files with no final newline, web/guestbook-go/redis-master-controller.yaml indented by one space in places and two in others, databases/mysql-cinder-pd/mysql.yaml with a space before a colon in limits :, and AI/vllm-deployment/hpa/horizontal-pod-autoscaler.yaml with two spaces after one. kubeconform in -strict mode validates 52 of the 56 resources against the upstream schemas and cannot find a schema for the four custom resources; adding Datree's CRDs-catalog as a second -schema-location validates all 56.

So .pre-commit-config.yaml has four parts. From pre-commit/pre-commit-hooks pinned to v6.0.0: check-yaml with --allow-multiple-documents, because the five all-in-one manifests hold several documents each, end-of-file-fixer and trailing-whitespace, all excluding _archived/. From adrienverge/yamllint pinned to v1.38.0: yamllint with -c .yamllint.yaml --strict, so a warning fails the hook too, excluding the archive and the Cassandra files. And a repo: local hook for kubeconform with language: golang and additional_dependencies naming github.com/yannh/kubeconform/cmd/kubeconform@v0.8.0, which pre-commit installs into the hook's own GOPATH, bootstrapping Go itself when the machine has none; its args pass -strict, -summary and the two schema locations, and its files pattern limits it to YAML outside the archive, the Cassandra config and the two dotfiles. Nothing about latest tags: kubeconform checks shape, not policy, and the agent writes databases/mysql-cinder-pd/mysql.yaml's untagged image: mysql into the pull request as a guideline finding rather than inventing a hook for it.

In its sandbox the agent runs pre-commit run --all-files twice. The first run lets the two fixers rewrite what they can, which touches YAML and the Markdown READMEs alike, and the agent keeps those edits in a separate commit titled for what they fixed. The second run shows what a person must fix by hand, the indentation and colon problems above, which the agent corrects in a third commit, file by file, so the diff for each is reviewable, then runs once more and pastes the clean output and kubeconform's 56 resources found in 40 files summary into the pull request. CONTRIBUTING.md gets two lines on pre-commit install, and no CI job is added, since the repository has none and that is a separate decision.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add pre-commit hooks to this Kubernetes manifest repository and open a pull request. Read README.md, guidelines.md, CONTRIBUTING.md, tests/e2e/e2e-kind, web/guestbook/e2e/test-kind and the manifests under AI/, databases/, nginx-platform-app/ and web/ first; treat _archived/ and the Cassandra application config files as out of scope. Run yamllint with its defaults over the tree, then write a .yamllint.yaml that keeps the repository's list indentation (indent-sequences consistent), disables document-start, makes line-length 120 a warning and allows one space before comments, so only real problems remain. Write .pre-commit-config.yaml with check-yaml --allow-multiple-documents, end-of-file-fixer and trailing-whitespace from pre-commit/pre-commit-hooks at a release tag, yamllint from adrienverge/yamllint at a release tag with --strict, and a local golang hook for kubeconform installed through additional_dependencies at a pinned version, run with -strict, -summary, the default schema location and Datree's CRDs-catalog for the ServiceMonitor and PrometheusRule resources. Run pre-commit run --all-files; keep the fixers' edits in one commit, hand fixes in another, and the config in a third. Note any image without a version tag as a guideline finding in the description, do not add a hook for it, and do not add CI. Add pre-commit install to CONTRIBUTING.md and paste the final hook output and the kubeconform summary.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request with three commits: the whitespace fixers' edits across the YAML and Markdown files, the hand fixes to the manifests with inconsistent indentation and stray spaces around colons, and the config itself, .pre-commit-config.yaml, .yamllint.yaml and two lines in CONTRIBUTING.md. The description pastes the final pre-commit run --all-files output with every hook passing and kubeconform's summary of resources found and valid.

The description also lists what the hooks do not cover and the agent found by reading: the untagged mysql image in databases/mysql-cinder-pd/mysql.yaml against the guideline that images carry a version, and the nginx:stable tag in nginx-platform-app/deployment.yml, which is pinned to a channel rather than a release. Those are for a maintainer to decide.

Before merging, a reviewer reads the indentation changes in web/guestbook-go/ to confirm nothing moved between keys, checks that the yamllint rules match the style the repository wants to keep rather than the style it happens to have, and decides whether the same hooks should also run in CI, which this pull request leaves out on purpose.

Run it on every manifest repository without hooks

A platform team with several manifest repositories sends one POST /o/{org}/sessions per repository from its terminal or a script, with this prompt and the repository in resources, and a request_id that is a UUID v5 of the repository name so a retried call returns the run already started. GET /o/{org}/github lists every repository the Rush GitHub App installation can reach, so a script can start a run only where no .pre-commit-config.yaml exists.

Each run reads that repository's own manifests and writes a yamllint config for its style and a kubeconform schema list for its custom resources, so a repository full of Argo CD or cert-manager objects gets those schemas rather than this one's, and each opens its own pull request. A webhook URL on the API key reports run.completed with the session_url to read the pull request link from.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

The config is thirty lines, and the work is in the fit: a yamllint default that fails every file for the way Kubernetes manifests indent lists, a kubeconform run that rejects every custom resource until it knows where the schema is, a multi-document file that check-yaml refuses without a flag, and a Go tool that the hook has to install itself. The agent runs the tools over the real tree in its own sandbox before writing a line of config, so the first version of the hooks already passes on the files that are fine and fails only on the ones that are not.

Every command and its output stays on the run, and the fixes land in commits a reviewer can read one at a time. The same request runs against each manifest repository a team owns, each in its own sandbox, each config shaped by that repository's own style and resources.

Frequently asked questions

Why not use yamllint's defaults?

Because they fail every manifest in the repository for its indentation style and for the missing --- at the top of each file. With the defaults yamllint reports 316 problems; with indent-sequences: consistent, document-start off and a 120-column warning it reports 28 errors and 5 warnings, all of them things a maintainer would actually fix. A linter that fails on style nobody wants to change gets disabled within a week.

How does kubeconform validate the ServiceMonitor and PrometheusRule objects?

Through a second -schema-location pointing at Datree's CRDs-catalog, which serves JSON schemas for the Prometheus Operator's resources by group, kind and version. Without it kubeconform reports could not find schema for those four and validates the other 52; with it all 56 pass in -strict mode.

Does a contributor need Go installed for the kubeconform hook?

No. The hook is declared with language: golang and additional_dependencies naming the module at a pinned version, so pre-commit installs it into the hook's own GOPATH the first time it runs, and bootstraps a Go toolchain if the machine has none.

Will the fixers change files outside the manifests?

Yes, end-of-file-fixer and trailing-whitespace run on every file type unless excluded, and in this repository they touch several READMEs as well as YAML. The agent keeps all of those edits in their own commit so a reviewer can skim or drop them, and excludes only _archived/.

Why is there no hook for :latest image tags?

Because neither yamllint nor kubeconform checks image tags, and a regex hook over every image: line would need a list of exceptions on day one. The agent reports the untagged mysql image and the nginx:stable channel tag in the pull request against the guideline, and a maintainer decides whether a policy tool belongs in the repository.

More Kubernetes jobs

The same job on other stacks

Keep reading