Skip to content

Conversation

@mszacillo
Copy link
Contributor

What type of PR is this?
/kind feature

What this PR does / why we need it:
Introduces a new method MaxAvailableComponentSets which will return a list of TargetClusters, where the replica # will correspond to the total number of component sets for multiple-component CRDs.

I decided to add the new method as a part of a separate interface called ComponentSetEstimator. This was done because if you add the MaxAvailableComponentSets, all downstream implementers of ReplicaEstimator will expect an implementation of MaxAvailableComponentSets.

By adding a separate extended interface, other estimators (such as GeneralEstimator) can keep their implementations of ReplicaEstimator, and only estimators that support multi-component workloads will implement ComponentSetEstimator.

Which issue(s) this PR fixes:
Part of #6734

Does this PR introduce a user-facing change?:

Adding maxAvailableComponentSets to estimator interface

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 20, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @mszacillo, 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 estimator framework by introducing a specialized interface for handling multi-component workloads. By creating a new ComponentSetEstimator that extends the base ReplicaEstimator, the design allows for the estimation of complete component sets without forcing all existing estimators to adopt new functionalities. This approach maintains the clarity and purpose of the original ReplicaEstimator while providing necessary extensibility for more complex resource allocation scenarios.

Highlights

  • New Interface for Multi-Component Workloads: Introduced a new interface, ComponentSetEstimator, specifically designed to handle estimations for multi-component CRDs.
  • New Method MaxAvailableComponentSets: The ComponentSetEstimator interface includes a new method, MaxAvailableComponentSets, which returns the maximum number of complete multi-component sets a cluster can host.
  • Interface Extension Strategy: The ComponentSetEstimator extends the existing ReplicaEstimator interface, ensuring that only estimators supporting multi-component workloads need to implement the new method, avoiding unnecessary changes to existing single-component estimators.
  • Enhanced ReplicaEstimator Documentation: Updated the comments for the ReplicaEstimator and its MaxAvailableReplicas method to clarify its purpose for single-component workloads.
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

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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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 Sep 20, 2025
Copy link

@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 a new ComponentSetEstimator interface to support replica estimation for multi-component workloads. This is a good approach as it extends the existing ReplicaEstimator without introducing breaking changes. The comments for existing interfaces and methods have also been improved for clarity.

I have one suggestion regarding the signature of the new MaxAvailableComponentSets method to ensure it can correctly handle multi-component requirements.

@mszacillo
Copy link
Contributor Author

Hi @RainbowMango, I've currently listed the return type as []workv1alpha2.TargetCluster. TargetCluster currently does not have a concept of ComponentSets, just replicas. Perhaps in the implementation of the method, we can change the unit from sets -> replicas? Or would we rather extend TargetCluster to have a ComponentSets number as well?

@codecov-commenter
Copy link

codecov-commenter commented Sep 20, 2025

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

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.82%. Comparing base (f9cd5c9) to head (3c5bdfe).
⚠️ Report is 16 commits behind head on master.

Files with missing lines Patch % Lines
pkg/estimator/client/accurate.go 0.00% 4 Missing ⚠️
pkg/estimator/client/general.go 0.00% 4 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6765      +/-   ##
==========================================
+ Coverage   45.73%   45.82%   +0.09%     
==========================================
  Files         689      690       +1     
  Lines       57152    57250      +98     
==========================================
+ Hits        26136    26235      +99     
- Misses      29384    29389       +5     
+ Partials     1632     1626       -6     
Flag Coverage Δ
unittests 45.82% <0.00%> (+0.09%) ⬆️

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.

Comment on lines 44 to 50
// ComponentSetEstimator extends ReplicaEstimator to handle multi-component workloads,
// where all components in a set must be scheduled together.
type ComponentSetEstimator interface {
ReplicaEstimator
// MaxAvailableComponentSets returns the maximum number of complete multi-component sets (in terms of replicas) that each cluster can host.
MaxAvailableComponentSets(ctx context.Context, clusters []*clusterv1alpha1.Cluster, components []*workv1alpha2.Component) ([]workv1alpha2.TargetCluster, error)
}
Copy link
Member

Choose a reason for hiding this comment

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

  1. The interface can have its own structure, it doesn't have to rely on the structure defined in the ResourceBinding API.
  2. We do need to think about how to let the ResourceBinding hold the set concept more straightforwardly.
  3. I suggest having a struct to hold the request and response, respectively. That makes room for extending more parameters, like we are likely to have a field like reserved resources to tell estimator implementations to reserve some resources before the estimation.
Suggested change
// ComponentSetEstimator extends ReplicaEstimator to handle multi-component workloads,
// where all components in a set must be scheduled together.
type ComponentSetEstimator interface {
ReplicaEstimator
// MaxAvailableComponentSets returns the maximum number of complete multi-component sets (in terms of replicas) that each cluster can host.
MaxAvailableComponentSets(ctx context.Context, clusters []*clusterv1alpha1.Cluster, components []*workv1alpha2.Component) ([]workv1alpha2.TargetCluster, error)
}
// ComponentSetEstimator extends ReplicaEstimator to handle multi-component workloads,
// where all components in a set must be scheduled together.
type ComponentSetEstimator interface {
// MaxAvailableComponentSets returns, for each cluster, the maximum number of complete multi-component sets it can host.
// The input is provided via a request struct to allow future extensibility, and the result reflects number of sets per cluster.
MaxAvailableComponentSets(ctx context.Context, req *ComponentSetEstimationRequest) ([]ComponentSetEstimationResponse, error)
}
// ComponentSetEstimationRequest carries input parameters for estimating multi-component set availability per cluster.
// Fields can be extended over time without changing the method signature.
type ComponentSetEstimationRequest struct {
// Clusters are the candidate clusters to estimate against.
Clusters []*clusterv1alpha1.Cluster
// Components are the components that form a multi-component workload.
Components []*workv1alpha2.Component
// Namespace is the namespace of the workload being estimated.
// It is used by the accurate estimator to check the quota configurations
// in the target member cluster. This field is required for quota-aware estimation.
Namespace string
}
// ComponentSetEstimationResponse represents how many complete component sets a cluster can accommodate.
type ComponentSetEstimationResponse struct {
// Name is the cluster name.
Name string
// Sets is the maximum number of complete component sets that can be scheduled on the cluster.
Sets int32
}

Copy link
Member

Choose a reason for hiding this comment

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

In addition, can we put the MaxAvailableComponentSets method into the legacy type ReplicaEstimator interface?
All we need to do is let the current estimator implementations(general-estimator and scheduler-estimator) to implement the new method. (Sure, we can have a dummy implementation in this PR.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do need to think about how to let the ResourceBinding hold the set concept more straightforwardly.

To me set can just be an internal concept to the implementers of MaxAvailableComponentSets. At the end of the day, a set is comprised of replicas - why not just convert the unit of sets into replicas after the calculation if complete?

I suggest having a struct to hold the request and response, respectively. That makes room for extending more parameters, like we are likely to have a field like reserved resources to tell estimator implementations to reserve some resources before the estimation.

Sounds good! I wasn't sure if this was within the scope of the ticket, but happy to include this.

In addition, can we put the MaxAvailableComponentSets method into the legacy type ReplicaEstimator interface?

I had separated the interfaces specifically so I wouldn't need to make dummy implementations haha, but yes I can also do this if it makes this logically easier to follow.

Copy link
Member

Choose a reason for hiding this comment

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

Any update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated - I've taken your suggestion to add the ComponentSetEstimationRequest to make the inputs more easily extensible. I also added back the MaxAvailableComponentSets into the original ReplicaEstimator interface and marked the implementations as TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if you have further questions / comments.

@RainbowMango
Copy link
Member

At the end of the day, a set is comprised of replicas - why not just convert the unit of sets into replicas after the calculation if complete?

I think it's doable, at least for now, if you mean the number of replicas for each cluster (just one cluster for multiple components workload) is always 1. Are we on the same page?

@RainbowMango
Copy link
Member

Sounds good! I wasn't sure if this was within the scope of the ticket, but happy to include this.

No, the extended idea(should have another proposal before starting) is not in the scope. Currently we are still focusing on implementing the proposal.

@mszacillo
Copy link
Contributor Author

I think it's doable, at least for now, if you mean the number of replicas for each cluster (just one cluster for multiple components workload) is always 1. Are we on the same page?

Something like that would work yes - as long as the maxSet calculation unit is consistent, the scheduler would still be able to make stack-ranked decisions on which cluster has the most available resources.

@karmada-bot karmada-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 29, 2025
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 29, 2025
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 29, 2025
@karmada-bot karmada-bot merged commit 498355d into karmada-io:master Sep 29, 2025
24 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. kind/feature Categorizes issue or PR as related to a new feature. 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.

4 participants