Skip to content

fix: handle nil minReplicas in CronFederatedHPA scaling#7725

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

fix: handle nil minReplicas in CronFederatedHPA scaling#7725
rootp1 wants to merge 1 commit into
karmada-io:masterfrom
rootp1:fix/cronfhpa-minreplicas-nil

Conversation

@rootp1

@rootp1 rootp1 commented Jul 7, 2026

Copy link
Copy Markdown

What type of PR is this?

/kind bug
/kind regression

What this PR does / why we need it:

Prevents CronFederatedHPA from panicking when the target FederatedHPA omits spec.minReplicas. The controller now initializes MinReplicas when a target minimum is provided, and the regression test covers the nil-pointer path.

Summary

  • guard ScaleFHPA against a nil FederatedHPA.Spec.MinReplicas
  • initialize MinReplicas from targetMinReplicas when needed
  • add a regression test for the nil existing pointer case

Which issue(s) this PR fixes:
Fixes #7724

Linked Issue

Fixes #7724

What Changed

  • updated pkg/controllers/cronfederatedhpa/cronfederatedhpa_job.go to avoid dereferencing a nil MinReplicas pointer
  • added Initialize Nil MinReplicas coverage to pkg/controllers/cronfederatedhpa/cronfederatedhpa_job_test.go

Verification

  • go test ./pkg/controllers/cronfederatedhpa -run TestScaleFHPA -count=1 — passed
  • make verify — failed: hack/update-codegen.sh cleanup could not remove repo-local _go toolchain files on darwin because the downloaded toolchain cache was read-only
  • PATH="$(go env GOPATH)/bin:$PATH" make verify — failed: same _go cleanup permission issue after verification steps completed
  • PATH="$(go env GOPATH)/bin:$PATH" GOTOOLCHAIN=local make verify — failed: local non-auto toolchain is go1.23.12, but go.mod requires >= 1.26.4
  • make test — passed

Special notes for your reviewer:

make verify reached and passed the substantive verification stages relevant to this change, including staticcheck, mock verification, gofmt, vendor, swagger docs, command-line flags, and CRD generation checks, before failing in temporary _go cleanup. No repository files were left modified by that failure.

Scope

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

Does this PR introduce a user-facing change?:

`karmada-controller-manager`: Fixed a CronFederatedHPA panic when the target FederatedHPA omitted `spec.minReplicas`.

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

Copy link
Copy Markdown
Contributor

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

Details

In response to this:

What type of PR is this?

/kind bug
/kind regression

What this PR does / why we need it:

Prevents CronFederatedHPA from panicking when the target FederatedHPA omits spec.minReplicas. The controller now initializes MinReplicas when a target minimum is provided, and the regression test covers the nil-pointer path.

Summary

  • guard ScaleFHPA against a nil FederatedHPA.Spec.MinReplicas
  • initialize MinReplicas from targetMinReplicas when needed
  • add a regression test for the nil existing pointer case

Which issue(s) this PR fixes:
Fixes #7724

Linked Issue

Fixes #7724

What Changed

  • updated pkg/controllers/cronfederatedhpa/cronfederatedhpa_job.go to avoid dereferencing a nil MinReplicas pointer
  • added Initialize Nil MinReplicas coverage to pkg/controllers/cronfederatedhpa/cronfederatedhpa_job_test.go

Verification

  • go test ./pkg/controllers/cronfederatedhpa -run TestScaleFHPA -count=1 — passed
  • make verify — failed: hack/update-codegen.sh cleanup could not remove repo-local _go toolchain files on darwin because the downloaded toolchain cache was read-only
  • PATH="$(go env GOPATH)/bin:$PATH" make verify — failed: same _go cleanup permission issue after verification steps completed
  • PATH="$(go env GOPATH)/bin:$PATH" GOTOOLCHAIN=local make verify — failed: local non-auto toolchain is go1.23.12, but go.mod requires >= 1.26.4
  • make test — passed

Special notes for your reviewer:

make verify reached and passed the substantive verification stages relevant to this change, including staticcheck, mock verification, gofmt, vendor, swagger docs, command-line flags, and CRD generation checks, before failing in temporary _go cleanup. No repository files were left modified by that failure.

Scope

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

Does this PR introduce a user-facing change?:

`karmada-controller-manager`: Fixed a CronFederatedHPA panic when the target FederatedHPA omitted `spec.minReplicas`.

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.

@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 garrybest 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

@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 critical bug in the CronFederatedHPA controller that caused a panic when interacting with FederatedHPA resources that lacked a defined minReplicas value. By adding a null check and implementing proper pointer initialization, the controller now gracefully handles these configurations. The changes are accompanied by a new regression test to ensure stability and prevent future occurrences of this issue.

Highlights

  • Panic Prevention: Updated the CronFederatedHPA controller to safely handle cases where the target FederatedHPA's minReplicas field is nil, preventing potential nil-pointer dereference panics.
  • Initialization Logic: Modified the scaling logic to correctly initialize the minReplicas field when a target value is provided but the current value is missing.
  • Regression Testing: Added a new unit test case to verify that the controller correctly handles and initializes nil minReplicas pointers.
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

Copy link
Copy Markdown
Contributor

Welcome @rootp1! It looks like this is your first PR to karmada-io/karmada 🎉

@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 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 updates the ScaleFHPA method in cronfederatedhpa_job.go to safely handle cases where fhpa.Spec.MinReplicas is nil, preventing potential nil pointer dereferences. It also adds a corresponding unit test to verify the initialization of MinReplicas when it is nil. There are no review comments, and 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.

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.

Pull request overview

Fixes a nil-pointer panic in the CronFederatedHPA controller when scaling a target FederatedHPA that omits spec.minReplicas by guarding the dereference and initializing MinReplicas when a target minimum is provided.

Changes:

  • Add a nil-safe comparison for fhpa.Spec.MinReplicas during scheduled scaling.
  • Initialize fhpa.Spec.MinReplicas from TargetMinReplicas when the existing field is nil.
  • Add a regression test case covering the “existing MinReplicas is nil” path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/controllers/cronfederatedhpa/cronfederatedhpa_job.go Prevents nil dereference by guarding and initializing MinReplicas during scaling updates.
pkg/controllers/cronfederatedhpa/cronfederatedhpa_job_test.go Adds regression coverage for scaling when the existing FederatedHPA has spec.minReplicas omitted.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter

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.07%. Comparing base (d01d3a8) to head (f4e030c).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7725   +/-   ##
=======================================
  Coverage   42.06%   42.07%           
=======================================
  Files         879      879           
  Lines       54831    54832    +1     
=======================================
+ Hits        23065    23068    +3     
+ Misses      30022    30020    -2     
  Partials     1744     1744           
Flag Coverage Δ
unittests 42.07% <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.

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/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CronFederatedHPA scaling can panic when the target FederatedHPA has no minReplicas

4 participants