---
id: w1/m20/t001
title: Autoscaling stanza on the App CRD (min/max + target CPU%/mem%)
worker: worker1
status: done
estimate: 40m
depends_on: []
---

## Objective

Add an `autoscaling` stanza to the `App` spec so a service can declare autoscaling intent: enabled, min/max replicas, and target CPU/memory utilization. Types only — the reconciler that acts on it is t002.

## Context

- `lego/types/` holds the `App`/`Database` CRD types (`app.bex.co/v1alpha1`); leaf module, imports nothing.
- Codegen (deepcopy + CRD manifest) runs from `lego/operator/` via `make manifests generate` (reads markers from `../types`).
- Render's shape: `minInstances`, `maxInstances`, `targetCPUPercent`, `targetMemoryPercent` (either/both targets allowed).

## Steps

1. Add `Autoscaling *AutoscalingSpec` to the App spec with `Enabled bool`, `MinReplicas int32`, `MaxReplicas int32`, `TargetCPUPercent *int32`, `TargetMemoryPercent *int32` (pointers where "unset" is meaningful).
2. Add kubebuilder validation markers (min ≤ max, percentages 1–100, min ≥ 0).
3. Run `make manifests generate fmt vet` from `lego/operator/`; commit the regenerated deepcopy + CRD YAML.

## Files

- `lego/types/…/app_types.go` (spec + markers)
- regenerated: `zz_generated.deepcopy.go`, `lego/operator/config/crd/…`

## Acceptance criteria

- [ ] `App.spec.autoscaling` accepts a valid stanza and rejects min>max / out-of-range percentages (envtest or apply against a kind cluster).
- [ ] `make test` green.

## Out of scope

- The reconciler behavior (t002) and any API/UI surface (t003/t004).
