Skip to content

karmada-search: wire cluster-api-qps and cluster-api-burst#7325

Open
manmathbh wants to merge 1 commit intokarmada-io:masterfrom
manmathbh:fix/search-cluster-api-qps-burst
Open

karmada-search: wire cluster-api-qps and cluster-api-burst#7325
manmathbh wants to merge 1 commit intokarmada-io:masterfrom
manmathbh:fix/search-cluster-api-qps-burst

Conversation

@manmathbh
Copy link
Copy Markdown

@manmathbh manmathbh commented Mar 23, 2026

What type of PR is this?

/kind feature
/kind cleanup

What this PR does / why we need it:

This PR adds --cluster-api-qps and --cluster-api-burst to karmada-search, and wires them into member-cluster dynamic client creation used by the search controller.

Previously, the dynamic client path passed nil client options. With this change, karmada-search now builds a util.ClientOption with a rate limiter and passes it through, so member-cluster API access uses the configured QPS/burst settings.

Also includes:

small naming cleanup (clientOption -> clusterClientOption) based on review feedback
formatting/lint fix in controller.go

Special notes reviewer:
Validated locally with:
go test [karmada-search]
go test [pkg]
[verify-staticcheck.sh]
[verify-import-aliases.sh]

Does this PR introduce a user-facing change?:
``karmada-search: add --cluster-api-qps` and `--cluster-api-burst` flags, and use them when creating member-cluster dynamic clients in search controller.`

Copilot AI review requested due to automatic review settings March 23, 2026 16:38
@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 23, 2026
@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 enhances the karmada-search component by providing configurable rate limits for API interactions with member clusters. This change allows operators to fine-tune the query per second (QPS) and burst rates, which can improve the stability and resource utilization of the karmada-search service when dealing with a large number of clusters or high API traffic.

Highlights

  • New Rate Limiting Options: Introduced new command-line flags --cluster-api-qps and --cluster-api-burst for karmada-search to control the rate of API calls made to member clusters.
  • Controller Integration: The karmada-search controller has been updated to accept and utilize these new rate-limiting parameters when establishing dynamic client connections to managed clusters.
  • Code Refactoring: The NewController function and related clusterDynamicClientBuilder now include a clientOption parameter to propagate the configured rate limits, enhancing control over cluster API interactions.
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 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 counter productive. 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR wires configurable rate limiting for member-cluster API access in karmada-search by introducing and threading --cluster-api-qps / --cluster-api-burst into the search controller’s member-cluster dynamic client creation.

Changes:

  • Add --cluster-api-qps and --cluster-api-burst flags to karmada-search options.
  • Pass a util.ClientOption with a per-cluster rate limiter getter into search.NewController.
  • Extend the search controller to accept and use the client option when building member-cluster dynamic clients (and update unit tests accordingly).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
cmd/karmada-search/app/options/options.go Adds new CLI flags for member-cluster API QPS/burst tuning.
cmd/karmada-search/app/karmada-search.go Constructs ClientOption using the new flags and passes it into the search controller.
pkg/search/controller.go Threads ClientOption through controller construction and dynamic cluster client creation.
pkg/search/controllers_test.go Updates tests to match the updated controller/builder function signatures.

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

Comment on lines +93 to +94
flags.Float32Var(&o.ClusterAPIQPS, "cluster-api-qps", 40.0, "QPS to use while talking with cluster kube-apiserver.")
flags.IntVar(&o.ClusterAPIBurst, "cluster-api-burst", 60, "Burst to use while talking with cluster kube-apiserver.")
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This PR introduces new user-facing flags (--cluster-api-qps/--cluster-api-burst). The PR description’s release-note block is currently empty; please add an appropriate release note entry (or explicitly set it to "NONE" if you consider it not user-facing).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

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 introduces QPS and burst rate limiting for API calls made to member clusters by karmada-search. New command-line flags (--cluster-api-qps and --cluster-api-burst) have been added to configure these limits, and the search.Controller has been updated to pass these options to the clusterDynamicClientBuilder when creating dynamic clients. The current tests for the controller compile by passing nil for the new client option, but a suggestion was made to add a test case to verify that the clientOption is correctly passed to the clusterDynamicClientBuilder to ensure the QPS and burst settings are applied.

// It returns the created Controller or an error if initialization fails.
func createController(ctx context.Context, restConfig *rest.Config, factory informerfactory.SharedInformerFactory, restMapper meta.RESTMapper) (*Controller, error) {
newController, err := NewController(restConfig, factory, restMapper)
newController, err := NewController(restConfig, factory, restMapper, nil)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The tests have been updated to compile by passing nil for the new clientOption parameter. However, this doesn't verify that the option is correctly passed through the controller. To ensure the new QPS and burst settings are applied, please consider adding a test case that verifies the clientOption is passed to clusterDynamicClientBuilder. You could, for example, modify createController to accept a clientOption and then add a test that provides a non-nil option and asserts that the mocked clusterDynamicClientBuilder receives it.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 23, 2026

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

Codecov Report

❌ Patch coverage is 53.33333% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.03%. Comparing base (3424bc7) to head (84893a8).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
cmd/karmada-search/app/karmada-search.go 0.00% 3 Missing ⚠️
cmd/karmada-search/app/options/options.go 0.00% 2 Missing ⚠️
pkg/search/controller.go 80.00% 2 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7325   +/-   ##
=======================================
  Coverage   42.03%   42.03%           
=======================================
  Files         874      874           
  Lines       53551    53556    +5     
=======================================
+ Hits        22511    22514    +3     
- Misses      29349    29352    +3     
+ Partials     1691     1690    -1     
Flag Coverage Δ
unittests 42.03% <53.33%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@manmathbh
Copy link
Copy Markdown
Author

PTAL @XiShanYongYe-Chang
CI Workflow / e2e test (v1.34.0) failed in resource_status collection

@XiShanYongYe-Chang
Copy link
Copy Markdown
Member

Thanks
/assign

flake test:

• [FAILED] [300.151 seconds]
[resource-status collection] resource status collection testing PodDisruptionBudget collection testing [It] pdb status collection testing
/home/runner/work/karmada/karmada/test/e2e/suites/base/resource_test.go:602

  Captured StdOut/StdErr Output >>
  I0323 16:57:34.901335   [570](https://github.com/karmada-io/karmada/actions/runs/23448666188/job/68220660961?pr=7325#step:6:571)43 resource_test.go:604] Waiting for PodDisruptionBudget(karmadatest-qb57p/poddisruptionbudget-kpbt8) collecting correctly status
  I0323 16:57:34.904280   57043 resource_test.go:614] PodDisruptionBudget(karmadatest-qb57p/poddisruptionbudget-kpbt8) Disruption Allowed: 0, wanted: 6
  I0323 16:57:34.904324   57043 resource_test.go:615] PodDisruptionBudget(karmadatest-qb57p/poddisruptionbudget-kpbt8) Expected Pods: 0, wanted: 9
  I0323 16:57:39.911691   57043 resource_test.go:614] PodDisruptionBudget(karmadatest-qb57p/poddisruptionbudget-kpbt8) Disruption Allowed: 0, wanted: 6
  I0323 16:57:39.911732   57043 resource_test.go:615] PodDisruptionBudget(karmadatest-qb57p/poddisruptionbudget-kpbt8) Expected Pods: 9, wanted: 9

...

  Timeline >>
  STEP: Creating Deployment(karmadatest-qb57p/poddisruptionbudget-kpbt8) @ 03/23/26 16:57:34.825
  STEP: Creating PodDisruptionBudget(karmadatest-qb57p/poddisruptionbudget-kpbt8) @ 03/23/26 16:57:34.84
  STEP: Creating PropagationPolicy(karmadatest-qb57p/poddisruptionbudget-kpbt8) @ 03/23/26 16:57:34.861
  STEP: check whether the pdb status can be correctly collected @ 03/23/26 16:57:34.901
  [FAILED] in [It] - /home/runner/work/karmada/karmada/test/e2e/suites/base/resource_test.go:622 @ 03/23/26 17:02:34.903
  STEP: Removing PropagationPolicy(karmadatest-qb57p/poddisruptionbudget-kpbt8) @ 03/23/26 17:02:34.959
  STEP: Removing PodDisruptionBudget(karmadatest-qb57p/poddisruptionbudget-kpbt8) @ 03/23/26 17:02:34.969
  << Timeline

  [FAILED] Timed out after 300.001s.
  Expected
      <bool>: false
  to equal
      <bool>: true
  In [It] at: /home/runner/work/karmada/karmada/test/e2e/suites/base/resource_test.go:622 @ 03/23/26 17:02:34.903

  Full Stack Trace
    github.com/karmada-io/karmada/test/e2e/suites/base.init.func55.9.3.1()
    	/home/runner/work/karmada/karmada/test/e2e/suites/base/resource_test.go:622 +0x59a
    github.com/karmada-io/karmada/test/e2e/suites/base.init.func55.9.3()
    	/home/runner/work/karmada/karmada/test/e2e/suites/base/resource_test.go:603 +0xd5

/retest

informerFactory informerfactory.SharedInformerFactory
clusterLister clusterlister.ClusterLister
queue workqueue.TypedRateLimitingInterface[any]
clientOption *util.ClientOption
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.

I suggest renaming it to clusterClientOption.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated as suggested: renamed to clusterClientOption in the search controller path and re-ran search/app tests. PTAL.

@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 ask for approval from xishanyongye-chang. 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

@XiShanYongYe-Chang
Copy link
Copy Markdown
Member

The lint has failed, can you help fix it?
By the way, can you help squash the commits into one?

@manmathbh
Copy link
Copy Markdown
Author

The lint has failed, can you help fix it? By the way, can you help squash the commits into one?

Thanks for the feedback! I've pushed a commit to take care of the linting issue. I'm just waiting to see if the CI passes, and then I'll squash the commits into one.

Signed-off-by: manmathbh <manmathcode@gmail.com>

search: rename clientOption to clusterClientOption

Signed-off-by: manmathbh <manmathcode@gmail.com>

search: format controller for gci lint

Signed-off-by: manmathbh <manmathcode@gmail.com>
@manmathbh manmathbh force-pushed the fix/search-cluster-api-qps-burst branch from 39393f5 to 84893a8 Compare March 24, 2026 15:59
@manmathbh
Copy link
Copy Markdown
Author

@XiShanYongYe-Chang IG we are good to go!

Copy link
Copy Markdown
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

Thanks~
/lgtm
Ask the todo owner to help review it again.
/cc @zach593

@karmada-bot karmada-bot requested a review from zach593 March 25, 2026 01:06
@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Indicates that a PR is ready to be merged. 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.

5 participants