Skip to content

feat: add hpa support#39

Merged
gjorgji-ts merged 1 commit into
mainfrom
feat/hpa-integration
Mar 28, 2026
Merged

feat: add hpa support#39
gjorgji-ts merged 1 commit into
mainfrom
feat/hpa-integration

Conversation

@gjorgji-ts

Copy link
Copy Markdown
Owner

Motivation

HPA managed deployments were being scaled down by LightsOut but the HPA would immediately fight back, restoring replicas to minReplicas. The original approach of setting minReplicas=0 was invalid. Kubernetes only allows minReplicas=0 with Object or External metrics, Resource (CPU) metrics are rejected by the API server.

Changes

Rather than patching minReplicas, LightsOut now sets spec.behavior.scaleUp.selectPolicy: Disabled on HPAs that target a managed workload. This prevents the HPA from acting while LightsOut holds the deployment at 0, without requiring any specific metric type configuration.

Strategy:

  • Downscale: read the current scaleUp.selectPolicy, store it in an annotation (lightsout.techsupport.mk/original-hpa-scale-up-policy), then set selectPolicy: Disabled
  • Upscale: restore the original policy (or remove the field if it was absent) and remove the LightsOut annotations
  • Skip conditions: HPAs already at selectPolicy: Disabled without a managed-by annotation are treated as user-managed and left untouched, HPAs managed by a different schedule are skipped

Testing

  • Unit tests: internal/controller/hpa_test.go (patch/restore logic, skip conditions, policy preservation), internal/controller/scaler_test.go (HPA wired into scale-down/up paths for Deployments and StatefulSets, crash window recovery)
  • e2e: test/e2e/hpa_test.go — 5 scenarios run against a live cluster:
    1. Downscale sets selectPolicy: Disabled, leaves minReplicas unchanged
    2. Upscale restores original policy and removes annotations
    3. Workload without an HPA scales normally (no HPA-related side effects)
    4. User-managed HPA with selectPolicy: Disabled already set is skipped (no annotations stamped)
    5. v1 HPA (autoscaling/v1) is handled correctly via internal v2 storage
  • Manual: verified against local Kind demo — api-server HPA correctly enters ScalingDisabled state with pods at 0, then fully restores on upscale

Checklist

  • Tests added / updated
  • Docs updated if behaviour changed
  • make lint passes
  • make test passes
  • make manifests generate run if API types changed
  • make helm-crds run if CRDs changed

@gjorgji-ts gjorgji-ts linked an issue Mar 28, 2026 that may be closed by this pull request
@gjorgji-ts gjorgji-ts self-assigned this Mar 28, 2026
@gjorgji-ts gjorgji-ts added the enhancement New feature or request label Mar 28, 2026
@gjorgji-ts gjorgji-ts merged commit 76aaace into main Mar 28, 2026
3 checks passed
@gjorgji-ts gjorgji-ts deleted the feat/hpa-integration branch March 28, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integration - HPA

1 participant