UPSTREAM: <carry>: Migrate HPA plugin from autoscaling/v2beta1 to v2#447
Conversation
…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>
WalkthroughThe HPA restore plugin now uses ChangesHPA autoscaling v2 migration
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 15✅ Passed checks (15 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
velero-plugins/horizontalpodautoscaler/restore.govelero-plugins/horizontalpodautoscaler/restore_test.go
| hpa := v2.HorizontalPodAutoscaler{} | ||
| itemMarshal, _ := json.Marshal(input.Item) | ||
| json.Unmarshal(itemMarshal, &hpa) | ||
|
|
||
| if (v2beta1.CrossVersionObjectReference{}) != hpa.Spec.ScaleTargetRef { | ||
| if (v2.CrossVersionObjectReference{}) != hpa.Spec.ScaleTargetRef { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
rg -n -C2 'json\.(Marshal|Unmarshal)' velero-plugins/horizontalpodautoscaler/restore.goRepository: openshift/openshift-velero-plugin
Length of output: 671
🏁 Script executed:
sed -n '1,120p' velero-plugins/horizontalpodautoscaler/restore.go | cat -nRepository: 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
|
/retest |
|
@Joeavaikath: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions 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. |
|
/approve |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Summary
Migrates the HorizontalPodAutoscaler restore plugin from
k8s.io/api/autoscaling/v2beta1tok8s.io/api/autoscaling/v2.The
autoscaling/v2beta1package was removed ink8s.io/api v0.36.0. The oadp-dev rebase is blocked because the velero dependency now pulls in the newerk8s.io/api, and the HPA plugin still imports the removed package. Theautoscaling/v2API 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 fromv2beta1tov2, updated all type references (v2beta1.HorizontalPodAutoscalertov2.HorizontalPodAutoscaler,v2beta1.CrossVersionObjectReferencetov2.CrossVersionObjectReference)velero-plugins/horizontalpodautoscaler/restore_test.go: Same import and type reference updates, plus updated test fixtureapiVersionfields fromautoscaling/v2beta1toautoscaling/v2Test plan
go build ./velero-plugins/horizontalpodautoscaler/...compiles cleanlygo test ./velero-plugins/horizontalpodautoscaler/...passes (all 6 test cases)go vet ./velero-plugins/horizontalpodautoscaler/...reports no issuesv2beta1in the codebaseSummary by CodeRabbit
autoscaling/v2API.