Skip to content

Fix CronFederatedHPA missing targetReplicas panic#7727

Open
rootp1 wants to merge 1 commit into
karmada-io:masterfrom
rootp1:fix/cronfhpa-missing-targetreplicas
Open

Fix CronFederatedHPA missing targetReplicas panic#7727
rootp1 wants to merge 1 commit into
karmada-io:masterfrom
rootp1:fix/cronfhpa-missing-targetreplicas

Conversation

@rootp1

@rootp1 rootp1 commented Jul 7, 2026

Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

Summary

  • add a defensive nil check in ScalingJob.ScaleWorkloads() so invalid direct workload scaling rules return an error instead of panicking
  • add a regression test for a missing targetReplicas rule

Linked Issue

Fixes #7726

What Changed

  • return a clear error when direct workload scaling is requested without targetReplicas
  • cover the nil TargetReplicas path in cronfederatedhpa_job_test.go

Verification

  • go test ./pkg/controllers/cronfederatedhpa — passed
  • make test — passed
  • make verify — not run cleanly: the target was executed twice; the first run failed because golangci-lint was installed into ~/go/bin but that path was not on PATH, and the rerun progressed further but failed in repository verification cleanup/codegen with existing API-rule output and permission errors removing the generated local _go toolchain directory

Scope

  • only the CronFederatedHPA controller and its focused unit test were changed; unrelated files were not modified

Which issue(s) this PR fixes:

Fixes #7726

Special notes for your reviewer:

  • make verify did not complete successfully in this local environment for reasons described above.

Does this PR introduce a user-facing change?:

NONE

Copilot AI review requested due to automatic review settings July 7, 2026 17:37
@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 7, 2026
@karmada-bot karmada-bot requested review from jwcesign and pigletfly July 7, 2026 17:37
@karmada-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mszacillo for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a runtime panic in the CronFederatedHPA controller. By validating the presence of targetReplicas before attempting to scale workloads, the controller now gracefully handles misconfigured scaling rules by returning a descriptive error instead of crashing.

Highlights

  • Bug Fix: Added a defensive nil check in ScalingJob.ScaleWorkloads to prevent panics when targetReplicas is missing.
  • Regression Testing: Introduced a new unit test, TestScaleWorkloadsNilTargetReplicas, to verify that an appropriate error is returned when targetReplicas is nil.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@karmada-bot karmada-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jul 7, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request adds a nil check for TargetReplicas in the ScaleWorkloads function of the ScalingJob controller to prevent potential issues when scaling workloads. It also introduces a corresponding unit test TestScaleWorkloadsNilTargetReplicas to verify that an appropriate error is returned when TargetReplicas is nil. There are no review comments, so I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@codecov-commenter

codecov-commenter commented Jul 7, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.06%. Comparing base (d01d3a8) to head (2213303).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7727   +/-   ##
=======================================
  Coverage   42.06%   42.06%           
=======================================
  Files         879      879           
  Lines       54831    54833    +2     
=======================================
+ Hits        23065    23067    +2     
+ Misses      30022    30021    -1     
- Partials     1744     1745    +1     
Flag Coverage Δ
unittests 42.06% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

Signed-off-by: rootp1 <arnav.iitr@gmail.com>
@rootp1 rootp1 force-pushed the fix/cronfhpa-missing-targetreplicas branch from 642b40f to 2213303 Compare July 7, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CronFederatedHPA direct workload scaling can panic when targetReplicas is missing

4 participants