> ## Documentation Index
> Fetch the complete documentation index at: https://autopilot.docs.xano.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HPA Behavior Overrides

> Fine-tune HPA scaling behavior during a scheduled window — speed presets, scale-down disabling, and CPU target.

Each `ScaleWindow` in a [ScheduledScalePolicy](/platform/scheduled-scaling) can optionally
override HPA scaling behavior during the window. All fields are optional — omitting a field
means the HPA's existing config is untouched. Original values are saved in the CRD status
and restored when windows deactivate.

## Fields

| Field                  | Type                                 | Description                                                         |
| ---------------------- | ------------------------------------ | ------------------------------------------------------------------- |
| `disableScaleDown`     | bool                                 | Prevents the HPA from removing pods (sets `selectPolicy: Disabled`) |
| `scaleUpSpeed`         | `Instant` / `Aggressive` / `Gradual` | Preset for HPA scaleUp behavior                                     |
| `scaleDownSpeed`       | `Slow` / `Gradual` / `Fast`          | Preset for HPA scaleDown behavior (ignored if `disableScaleDown`)   |
| `targetCPUUtilization` | int (1–100)                          | Override the HPA CPU metric target %                                |

## Speed presets

### scaleUpSpeed

| Value        | Stabilization | Policy           | Effect                             |
| ------------ | ------------- | ---------------- | ---------------------------------- |
| `Instant`    | 0s            | Percent: 200/60s | Triple per minute, zero delay      |
| `Aggressive` | 15s           | Percent: 100/60s | Double per minute, brief smoothing |
| `Gradual`    | 60s           | Pods: 3/60s      | Slow ramp, 3 pods/min max          |

### scaleDownSpeed

| Value     | Stabilization | Policy          | Effect                                                     |
| --------- | ------------- | --------------- | ---------------------------------------------------------- |
| `Slow`    | 600s          | Percent: 5/60s  | 10-min wait, shed 5% per minute                            |
| `Gradual` | 300s          | Percent: 10/60s | 5-min wait, shed 10% per minute (close to the K8s default) |
| `Fast`    | 60s           | Percent: 25/60s | 1-min wait, shed 25% per minute                            |

## Overlapping windows

* `minReplicas`: highest wins.
* Behavior fields: the first active window (in spec order) that sets a given field wins.
* Different fields from different windows compose — window A's `scaleUpSpeed` and window B's `scaleDownSpeed` both apply.

## Save / restore

* Original `minReplicas`/`maxReplicas` are stored as HPA annotations (lightweight, survives controller restarts).
* Original HPA `spec.behavior` is stored as JSON in the CRD status (`OriginalBehavior` field) — too complex for annotations.
* Original CPU target is stored as `OriginalCPUTarget` in the CRD status (`-1` = the metric didn't exist before).

## Full example

```yaml theme={null}
apiVersion: ops-ai.io/v1alpha1
kind: ScheduledScalePolicy
metadata:
  name: morning-burst
  namespace: tenant-ns
spec:
  hpaName: backend-hpa
  baseMinReplicas: 10
  mode: active
  windows:
    - name: morning-login-surge
      minReplicas: 50
      preScaleMinutes: 5
      disableScaleDown: true
      scaleUpSpeed: Instant
      targetCPUUtilization: 90
      schedule:
        type: Weekly
        startTime: "08:30"
        endTime: "10:30"
        timezone: "America/Los_Angeles"
        daysOfWeek: [Monday, Tuesday, Wednesday, Thursday, Friday]

    - name: afternoon-steady
      minReplicas: 20
      scaleUpSpeed: Gradual
      scaleDownSpeed: Slow
      schedule:
        type: Weekly
        startTime: "12:00"
        endTime: "17:00"
        timezone: "America/Los_Angeles"
        daysOfWeek: [Monday, Tuesday, Wednesday, Thursday, Friday]
```
