Skip to content

UPSTREAM: <carry>: Migrate HPA plugin from autoscaling/v2beta1 to v2#447

Merged
openshift-merge-bot[bot] merged 1 commit into
openshift:oadp-devfrom
Joeavaikath:fix/migrate-hpa-v2beta1-to-v2
Jul 17, 2026
Merged

UPSTREAM: <carry>: Migrate HPA plugin from autoscaling/v2beta1 to v2#447
openshift-merge-bot[bot] merged 1 commit into
openshift:oadp-devfrom
Joeavaikath:fix/migrate-hpa-v2beta1-to-v2

Conversation

@Joeavaikath

@Joeavaikath Joeavaikath commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrates the HorizontalPodAutoscaler restore plugin from k8s.io/api/autoscaling/v2beta1 to k8s.io/api/autoscaling/v2.

The autoscaling/v2beta1 package was removed in k8s.io/api v0.36.0. The oadp-dev rebase is blocked because the velero dependency now pulls in the newer k8s.io/api, and the HPA plugin still imports the removed package. The autoscaling/v2 API is the stable replacement and is structurally compatible -- HorizontalPodAutoscaler, CrossVersionObjectReference, and all fields used by the plugin (Spec.ScaleTargetRef, APIVersion, Kind, Name) are identical in the v2 API.

Closes #446

Changes

  • velero-plugins/horizontalpodautoscaler/restore.go: Updated import from v2beta1 to v2, updated all type references (v2beta1.HorizontalPodAutoscaler to v2.HorizontalPodAutoscaler, v2beta1.CrossVersionObjectReference to v2.CrossVersionObjectReference)
  • velero-plugins/horizontalpodautoscaler/restore_test.go: Same import and type reference updates, plus updated test fixture apiVersion fields from autoscaling/v2beta1 to autoscaling/v2

Test plan

  • go build ./velero-plugins/horizontalpodautoscaler/... compiles cleanly
  • go test ./velero-plugins/horizontalpodautoscaler/... passes (all 6 test cases)
  • go vet ./velero-plugins/horizontalpodautoscaler/... reports no issues
  • No remaining references to v2beta1 in the codebase

Summary by CodeRabbit

  • Bug Fixes
    • Updated Horizontal Pod Autoscaler restoration to support the stable autoscaling/v2 API.
    • Preserved existing handling for scale target references, including DeploymentConfig targets.
    • Updated restoration validation and expected behavior for the newer API version.

…oscaling/v2

The autoscaling/v2beta1 package was removed in k8s.io/api v0.36.0,
which breaks the oadp-dev rebase when velero pulls in the newer
k8s.io/api. The v2 API is the stable replacement and is structurally
compatible — HorizontalPodAutoscaler and CrossVersionObjectReference
have the same fields used by the plugin.

Closes: openshift#446

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Walkthrough

The HPA restore plugin now uses autoscaling/v2 for deserialization and scale target references. Tests update their types and fixtures while preserving existing modification and error expectations.

Changes

HPA autoscaling v2 migration

Layer / File(s) Summary
Update HPA restore types and validation
velero-plugins/horizontalpodautoscaler/restore.go, velero-plugins/horizontalpodautoscaler/restore_test.go
The restore implementation and table-driven tests replace autoscaling/v2beta1 with autoscaling/v2, retaining existing rewrite, non-modification, and invalid-reference expectations.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main change: migrating the HPA plugin from autoscaling/v2beta1 to v2.
Linked Issues check ✅ Passed The plugin and tests were updated to use autoscaling/v2, matching the required fix for the removed v2beta1 API.
Out of Scope Changes check ✅ Passed The changes stay focused on the HPA restore plugin and its tests, with no unrelated code areas touched.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Stable And Deterministic Test Names ✅ Passed The only test titles are static t.Run strings; no generated names, timestamps, UUIDs, or runtime values appear in test titles.
Test Structure And Quality ✅ Passed No Ginkgo or cluster-interaction tests here; the table-driven unit tests isolate one HPA behavior per case and need no cleanup/timeouts.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the changes are unit tests/restore logic only, so MicroShift-specific compatibility is not implicated.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PASS: The PR only changes a unit-test file and a restore plugin; no Ginkgo e2e specs or SNO-sensitive multi-node assumptions are present.
Topology-Aware Scheduling Compatibility ✅ Passed Only HPA restore type migrations were changed; no scheduling, affinity, nodeSelector, replica, or PDB logic was introduced.
Ote Binary Stdout Contract ✅ Passed The diff only changes HPA restore logic and its unit tests; no main/init/suite code or stdout-printing calls were added.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; only restore plugin code and unit tests changed, with no IPv4 or external-network assumptions.
No-Weak-Crypto ✅ Passed The only changed files are HPA restore/test code; they use no crypto primitives, weak ciphers, or secret/token comparisons.
Container-Privileges ✅ Passed Only HPA restore Go files changed; no container/K8s manifests or privilege settings (privileged, hostPID, hostNetwork, hostIPC, SYS_ADMIN, allowPrivilegeEscalation) were added.
No-Sensitive-Data-In-Logs ✅ Passed Changed logs are generic status/error messages; no sensitive data such as passwords, tokens, PII, or hostnames is logged.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@velero-plugins/horizontalpodautoscaler/restore.go`:
- Around line 29-33: Update the HPA conversion flow around the input
`json.Marshal`/`json.Unmarshal` and the corresponding output conversion to
capture and return both errors instead of ignoring them. Ensure malformed input
cannot continue with a zero-value HPA or bypass the `DeploymentConfig` fix,
while preserving the existing successful conversion behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9df0e44f-2966-41c2-adcd-23ba36c77e57

📥 Commits

Reviewing files that changed from the base of the PR and between 6ddb843 and c4bbe72.

📒 Files selected for processing (2)
  • velero-plugins/horizontalpodautoscaler/restore.go
  • velero-plugins/horizontalpodautoscaler/restore_test.go

Comment on lines +29 to +33
hpa := v2.HorizontalPodAutoscaler{}
itemMarshal, _ := json.Marshal(input.Item)
json.Unmarshal(itemMarshal, &hpa)

if (v2beta1.CrossVersionObjectReference{}) != hpa.Spec.ScaleTargetRef {
if (v2.CrossVersionObjectReference{}) != hpa.Spec.ScaleTargetRef {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

rg -n -C2 'json\.(Marshal|Unmarshal)' velero-plugins/horizontalpodautoscaler/restore.go

Repository: openshift/openshift-velero-plugin

Length of output: 671


🏁 Script executed:

sed -n '1,120p' velero-plugins/horizontalpodautoscaler/restore.go | cat -n

Repository: openshift/openshift-velero-plugin

Length of output: 2509


Propagate JSON errors in both conversions.
json.Marshal/json.Unmarshal are ignored here and again in the output conversion, so malformed input can become a zero-value HPA and silently skip the DeploymentConfig fix. Return the conversion errors instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@velero-plugins/horizontalpodautoscaler/restore.go` around lines 29 - 33,
Update the HPA conversion flow around the input `json.Marshal`/`json.Unmarshal`
and the corresponding output conversion to capture and return both errors
instead of ignoring them. Ensure malformed input cannot continue with a
zero-value HPA or bypass the `DeploymentConfig` fix, while preserving the
existing successful conversion behavior.

Source: Path instructions

@Joeavaikath

Copy link
Copy Markdown
Contributor Author

/retest

@openshift-ci

openshift-ci Bot commented Jul 17, 2026

Copy link
Copy Markdown

@Joeavaikath: all tests passed!

Full PR test history. Your PR dashboard.

Details

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-sigs/prow repository. I understand the commands that are listed here.

@sseago

sseago commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

/approve

@shubham-pampattiwar shubham-pampattiwar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 17, 2026
@openshift-ci

openshift-ci Bot commented Jul 17, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Joeavaikath, shubham-pampattiwar, sseago

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:
  • OWNERS [Joeavaikath,shubham-pampattiwar,sseago]

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

@openshift-merge-bot
openshift-merge-bot Bot merged commit 2b9f8f8 into openshift:oadp-dev Jul 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rebase blocked: autoscaling/v2beta1 removed in k8s.io/api v0.36

3 participants