feat: add hpa support#39
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 settingminReplicas=0was invalid. Kubernetes only allowsminReplicas=0with Object or External metrics, Resource (CPU) metrics are rejected by the API server.Changes
Rather than patching
minReplicas, LightsOut now setsspec.behavior.scaleUp.selectPolicy: Disabledon 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:
scaleUp.selectPolicy, store it in an annotation (lightsout.techsupport.mk/original-hpa-scale-up-policy), then setselectPolicy: DisabledselectPolicy: Disabledwithout amanaged-byannotation are treated as user-managed and left untouched, HPAs managed by a different schedule are skippedTesting
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)test/e2e/hpa_test.go— 5 scenarios run against a live cluster:selectPolicy: Disabled, leavesminReplicasunchangedselectPolicy: Disabledalready set is skipped (no annotations stamped)autoscaling/v1) is handled correctly via internal v2 storageapi-serverHPA correctly entersScalingDisabledstate with pods at 0, then fully restores on upscaleChecklist
make lintpassesmake testpassesmake manifests generaterun if API types changedmake helm-crdsrun if CRDs changed