Skip to content

fix: fall back to autoscaling/v1 for native HPA - #595

Closed
haorenfsa wants to merge 2 commits into
mainfrom
fix-hpa-api-discovery
Closed

haorenfsa wants to merge 2 commits into
mainfrom
fix-hpa-api-discovery

Conversation

@haorenfsa

@haorenfsa haorenfsa commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #592. Related to #594.

Summary

On Kubernetes 1.21.5, the Operator queries autoscaling/v2 while reconciling every component, including components that have never configured native HPA. The API is unavailable on that cluster, so the reconcile fails before it can finish.

  • Discover HPA API support before reconciling component workloads. Prefer autoscaling/v2, fall back to autoscaling/v1 on API NoMatch, and propagate other discovery errors.

  • When only v1 is served, reconcile and clean up operator-owned HPAs. Support a single CPU utilization target, with 80% as the default. Report metrics or scaling behavior that require v2 before changing component workloads.

  • When neither API is served, skip HPA reconciliation for instances without native HPA and return a component-specific error for explicit HPA configuration.

  • Keep HPA suspension available through v1 during an active rollout or upgrade stop. Require the same UID and resource version when deleting an HPA so a replacement or updated owner is preserved.

Validation

  • AWS UAT Job operator-hpa-595-review-r2-1204 passed the HPA regression tests and go test ./pkg/controllers/... -short -count=1 with Go 1.27.4.
  • The regression tests simulate a v1-only API server and exercise version selection, create/update/cleanup during a rollout, and protection of externally managed HPAs.
  • The review follow-up patch is byte-for-byte identical to the patch tested in UAT.

Signed-off-by: shaoyue <haorenfsa@gmail.com>
@sre-ci-robot

Copy link
Copy Markdown
Collaborator

@haorenfsa: The label(s) kind/bug cannot be applied, because the repository doesn't have them.

Details

In response to this:

Fixes #592. Related to #594.

/kind bug

Summary

On Kubernetes 1.21.5, the Operator queries autoscaling/v2 while reconciling every component, including components that have never configured native HPA. The API is unavailable on that cluster, so the reconcile fails before it can finish.

  • Discover HPA API support before reconciling component workloads. Prefer autoscaling/v2, fall back to autoscaling/v1 on API NoMatch, and propagate other discovery errors.
  • When only v1 is served, reconcile and clean up operator-owned HPAs. Support a single CPU utilization target, with 80% as the default. Report metrics or scaling behavior that require v2 before changing component workloads.
  • When neither API is served, skip HPA reconciliation for instances without native HPA and return a component-specific error for explicit HPA configuration.

Validation

  • AWS UAT Job operator-hpa-v1-592-1204 passed the HPA regression tests and go test ./pkg/controllers/... -short -count=1 with Go 1.27.4.
  • The regression tests simulate a v1-only API server and exercise version selection, create/update/cleanup during a rollout, and protection of externally managed HPAs.
  • The source patch is byte-for-byte identical to the patch tested in UAT after syncing with main.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sre-ci-robot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: haorenfsa

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mergify

mergify Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

This pull request is closed, so it cannot be queued. Reopen it to get the box back.

@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.04950% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.15%. Comparing base (76b6119) to head (b869306).

Files with missing lines Patch % Lines
pkg/controllers/hpa.go 94.11% 3 Missing ⚠️
pkg/controllers/hpa_v1.go 95.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #595      +/-   ##
==========================================
+ Coverage   86.06%   86.15%   +0.09%     
==========================================
  Files          76       77       +1     
  Lines        7663     7749      +86     
==========================================
+ Hits         6595     6676      +81     
- Misses       1066     1071       +5     
  Partials        2        2              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Allow v1 HPA cleanup during an active rollout or upgrade stop before validating settings for HPA creation. Protect cleanup with Kubernetes delete preconditions and share HPA metadata and replica limits across API versions.

Signed-off-by: shaoyue <haorenfsa@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fails reconciliation without HPA configured when autoscaling/v2 is unavailable

2 participants