All jobs

Add a ResourceQuota and LimitRange to Kubernetes Manifests

Yes. An agent adds up every request and limit in your manifests, writes a ResourceQuota and LimitRange sized from them, checks the kustomize build and opens a PR.

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 clones the repository into its own cloud sandbox and reads every workload before writing a quota. In an app like GoogleCloudPlatform/microservices-demo the manifests live in kubernetes-manifests/, one file per service, each with a Deployment, a ClusterIP Service and a ServiceAccount; cartservice.yaml also carries a redis-cart Deployment, and frontend.yaml adds a second Service of type LoadBalancer. kustomization.yaml lists ten of the files and leaves loadgenerator.yaml commented out for skaffold to add during development, and the README says the files are meant for skaffold, which fills in the image tags. No file sets a namespace, and nothing in the repository defines a ResourceQuota or a LimitRange, so a namespace that receives these manifests has no ceiling on what they, or anything deployed beside them, can ask for.

It reads the resources block of every container. Most services request 100m of CPU and 64Mi of memory with limits of 200m and 128Mi; adservice asks for 200m and 180Mi, cartservice for 200m and 64Mi, recommendationservice for 100m and 220Mi with a 450Mi limit, and redis-cart for 70m and 200Mi. Added across the ten files in the kustomization that is 1270m of CPU and 1112Mi of memory requested, and 2325m and 2030Mi in limits, with the load generator adding 300m and 256Mi requested and 500m and 512Mi in limits when it is enabled. The agent does the sum with a short script over the rendered output of kubectl kustomize, not by hand, and pastes the per-container table into the pull request.

From those totals it writes kubernetes-manifests/resource-quota.yaml: a ResourceQuota with requests.cpu, requests.memory, limits.cpu and limits.memory set to the sums plus headroom for a rolling update, which by default surges one extra pod per Deployment, sized so the largest service can roll with a replica to spare, and a pods count that allows the eleven workloads plus the load generator and the surge. Beside it, limit-range.yaml holds a LimitRange for Container with defaultRequest and default values taken from the most common block in the manifests, 100m and 64Mi requesting and 200m and 128Mi limiting, and a max above the largest container present, so a future Deployment that forgets its resources block still fits under the quota instead of being refused, which is what a quota does to a pod with no requests. Both files are added to kustomization.yaml, and because the quota is namespace-scoped and these manifests name none, the agent adds a comment and a README note that the files apply to whatever namespace kubectl or skaffold targets.

To check it, the agent runs kubectl kustomize kubernetes-manifests and confirms the two new objects render with the rest, validates the output with kubeconform against the Kubernetes schemas so a typo in limits.memory is caught, and re-runs its sum over the rendered manifests to show the quota exceeds the totals by the headroom it stated. It also renders the kustomize/ base, which mirrors these manifests, to confirm the files do not need a second copy there, and explains in the pull request why it did not add one.

Start it with one API call

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

{
  "agent": "claude",
  "input": "Do the work the Linear issue describes: add a ResourceQuota and a LimitRange to this repository's Kubernetes manifests. Read the kustomization and every manifest it includes, plus any it leaves commented out, and the README first. Render the manifests with kubectl kustomize and compute the total CPU and memory requests and limits across every container with a script, listing each container in a table. Write a ResourceQuota whose hard limits cover those totals plus headroom for a rolling update surge and a pods count, and a LimitRange for containers with defaultRequest and default values taken from the most common resources block and a max above the largest container. Add both to the kustomization. Do not change any existing Deployment. Validate the rendered output with kubeconform and show the sums against the quota. Note how the namespace is chosen, since the manifests name none. Open a pull request with the table, the quota arithmetic and the validation output.",
  "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 adding resource-quota.yaml and limit-range.yaml under the manifests directory, two lines in kustomization.yaml and a short README note. No Deployment changes, so every container keeps the requests and limits it had, and the diff is two small objects plus the wiring.

The description holds the per-container table, the four totals it adds up to, the headroom the quota leaves and why, and the kubeconform output for the rendered manifests. It names the one Deployment the kustomization leaves out, the load generator, and shows that the quota still fits when skaffold adds it.

Before merging, a reviewer checks the headroom against how many replicas the services run in the real cluster, since the manifests set none and the defaults assume one, decides whether the LimitRange defaults should be stricter for new workloads than the existing ones, and confirms which namespace the quota will land in for each environment.

Run it on every Linear issue labelled platform

Add an automation to the Project with this prompt and a linear trigger on linear.issue.labeled with the label your platform team uses for agent work. The trigger adds the labelled issue after the prompt, so an issue that names the namespace, a replica count the quota must cover or a cluster-wide policy to match steers the run without any edit to the prompt; a change made by an app integration never fires it, and max_runs_per_hour caps how many issues the automation picks up in an hour.

From your own server, send POST /o/{org}/sessions with the repository and the issue URL in resources so the issue text reaches the agent through your Linear connection, and a request_id that is a UUID v5 of the issue id so a retried call returns the run already started. Set a webhook_url on the key to receive run.completed with data.session_url when the pull request is open.

The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.

Why run it on Rush?

A quota that is too tight breaks the next rollout and one that is too loose is decoration, and getting it right means adding up every container across every manifest, including the ones a kustomization comments out and the surge a rolling update needs. The agent reads all of it, computes the sums from the rendered output rather than from memory, and keeps the script, the table and the kubeconform run in the record beside the pull request, so a reviewer checks arithmetic that is shown rather than redoing it.

The same request runs across every repository that ships manifests, each in its own sandbox with its own totals, which is how a platform team gets a quota and a LimitRange into every namespace in one review cycle, each sized from that app's real numbers rather than a cluster-wide guess.

Frequently asked questions

Will the quota break my existing Deployments?

Not as sized. The hard limits are the current totals plus headroom for a rolling update surge, and every existing container already sets requests and limits, which a compute quota requires. The pull request shows the sums against the quota so the margin is visible before merge.

Why add a LimitRange as well?

Once a namespace has a compute quota, a pod with no requests or limits is refused at admission. The LimitRange gives such a container default values, taken from the most common block in your manifests, so a new Deployment that forgets its resources still schedules and still counts against the quota.

What about replicas, HPAs and surge during rollouts?

The manifests here set no replica counts, so the agent sizes for one replica each plus the default rolling update surge of one extra pod. If an HPA or a higher replica count runs in the real cluster, the issue should say so and the agent multiplies accordingly; the arithmetic is in the description to adjust.

Which namespace does the quota apply to?

Whichever one the manifests are applied into, because they name none; a ResourceQuota is namespace-scoped. The agent adds a note on that, and if your environments use a kustomize overlay per namespace it can set namespace there in a follow-up.

Does it also cover storage or object counts?

The quota includes a pods count sized for the workloads and their surge. Storage and other object counts are left out unless the issue asks for them, since this app uses an emptyDir for Redis and no PersistentVolumeClaims, and a quota should name only what the manifests use.

More Kubernetes jobs

More jobs like this: Turn a Linear label into a PR

Keep reading