-
Notifications
You must be signed in to change notification settings - Fork 1k
remark the workload for resourcebinding #6881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
remark the workload for resourcebinding #6881
Conversation
Signed-off-by: LivingCcj <[email protected]>
Summary of ChangesHello @LivingCcj, 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 introduces a refined mechanism for identifying workload-associated ResourceBindings within the system. By adding a dedicated helper function and integrating it into the scheduler's core logic, the system can now more accurately distinguish between different types of resources, leading to more intelligent and flexible replica scheduling and cluster assignment strategies. This change improves the overall resource management capabilities, particularly for distributed workloads. Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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 introduces a new IsBindingWorkload() method to improve workload identification for ResourceBindings. Instead of simply checking if replicas are zero, the new method provides a more comprehensive way to determine if a ResourceBinding is associated with a workload by also considering ReplicaRequirements and Components fields.
Key changes:
- Added
IsBindingWorkload()method toResourceBindingSpecthat checks replicas, replica requirements, and components - Replaced direct
Replicas == 0checks with calls to the newIsBindingWorkload()method in scheduler code - Updated replica assignment logic to use the new workload identification method
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/apis/work/v1alpha2/binding_types_helper.go | Adds the IsBindingWorkload() method to centralize workload identification logic |
| pkg/apis/work/v1alpha2/binding_types_helper_test.go | Adds unit tests for the new IsBindingWorkload() method |
| pkg/scheduler/scheduler.go | Replaces Replicas == 0 checks with IsBindingWorkload() calls in scheduling logic |
| pkg/scheduler/core/common.go | Updates AssignReplicas() to use IsBindingWorkload() for conditional logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pkg/scheduler/core/common.go
Outdated
| var targetClusters []workv1alpha2.TargetCluster | ||
| if !spec.IsBindingWorkload() { | ||
| for _, cluster := range clusters { | ||
| targetClusters = append(targetClusters, workv1alpha2.TargetCluster{Name: cluster.Cluster.Name}) | ||
| } | ||
| } |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When spec.IsBindingWorkload() returns true (indicating a workload), targetClusters remains nil instead of being initialized to an empty slice. This changes the return behavior from returning an initialized empty slice to returning nil, which could cause issues for callers expecting a non-nil slice. Initialize targetClusters to an empty slice using make([]workv1alpha2.TargetCluster, 0) or preserve the original pre-allocation logic for the workload case.
There was a problem hiding this 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 helper function IsBindingWorkload to determine if a ResourceBinding is for a workload, and refactors the scheduler to use this function. The overall approach is sound. My review includes suggestions to improve code conciseness in IsBindingWorkload, enhance test coverage to ensure all conditions of the new function are tested, and a minor performance optimization in slice handling.
| { | ||
| name: "binding a workload", | ||
| spec: &ResourceBindingSpec{ | ||
| Replicas: 1, | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "not binding a workload when replicas is 0", | ||
| spec: &ResourceBindingSpec{ | ||
| Replicas: 0, | ||
| }, | ||
| want: false, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test cases for IsBindingWorkload are not comprehensive as they only cover the Replicas field. To ensure the function works correctly under all conditions, please add test cases for ReplicaRequirements and Components as well.
{
name: "binding a workload by replicas",
spec: &ResourceBindingSpec{
Replicas: 1,
},
want: true,
},
{
name: "binding a workload by replica requirements",
spec: &ResourceBindingSpec{
ReplicaRequirements: &ReplicaRequirements{},
},
want: true,
},
{
name: "binding a workload by components",
spec: &ResourceBindingSpec{
Components: []Component{{Name: "test"}},
},
want: true,
},
{
name: "not a workload",
spec: &ResourceBindingSpec{
Replicas: 0,
},
want: false,
},There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- binding represents a workload that has replicas
- binding represents a workload that has replica requirements
- binding represents a workload that has components
| if s.Replicas > 0 || s.ReplicaRequirements != nil || len(s.Components) > 0 { | ||
| return true | ||
| } | ||
| return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I‘m ok with the current implementation, which I think is clear and easy to understand.
But I'm suggesting changing the method name, since Binding is a bit redundant. Like:
// IsWorkload returns true if the ResourceBinding represents a workload
// (e.g., Deployment, StatefulSet) that has replicas or replica requirements.
func (s *ResourceBindingSpec) IsWorkload() bool {
}
pkg/scheduler/core/common.go
Outdated
| if !spec.IsBindingWorkload() { | ||
| for _, cluster := range clusters { | ||
| targetClusters = append(targetClusters, workv1alpha2.TargetCluster{Name: cluster.Cluster.Name}) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using append inside a loop can be inefficient due to potential reallocations if the slice grows. Since the number of clusters is known beforehand, it's more performant to pre-allocate the slice with make.
| if !spec.IsBindingWorkload() { | |
| for _, cluster := range clusters { | |
| targetClusters = append(targetClusters, workv1alpha2.TargetCluster{Name: cluster.Cluster.Name}) | |
| } | |
| } | |
| if !spec.IsBindingWorkload() { | |
| targetClusters = make([]workv1alpha2.TargetCluster, len(clusters)) | |
| for i, cluster := range clusters { | |
| targetClusters[i] = workv1alpha2.TargetCluster{Name: cluster.Cluster.Name} | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6881 +/- ##
==========================================
+ Coverage 46.38% 46.40% +0.02%
==========================================
Files 698 698
Lines 47763 47767 +4
==========================================
+ Hits 22155 22167 +12
+ Misses 23938 23932 -6
+ Partials 1670 1668 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/retest |
|
@LivingCcj: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
|
@LivingCcj: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
|
/ok-to-test |
|
/retest |
RainbowMango
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/assign
RainbowMango
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good to me. But we might need to postpone this for a while, as the workloads do not currently support replica assignment yet. With this patch workload with multiple pod templates will be ignored during AssignReplicas, resulting in a return nil.
|
@LivingCcj This PR acutally fixes the #6156, right? Could you please update the PR description according to the PR template? |
Signed-off-by: LivingCcj <[email protected]>
Yes, this could fix the issue #6156, the PR describe and new commit has been pushed. |
pkg/scheduler/scheduler.go
Outdated
| return err | ||
| } | ||
| if rb.Spec.Replicas == 0 || | ||
| if !rb.Spec.IsSingleComponentsWorkload() || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both single-component workload and multi-component workload should be skipped from rescheduling.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Adding label 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. |
Signed-off-by: LivingCcj <[email protected]>
What type of PR is this?
/kind feature
What this PR does / why we need it:
This PR defines how to identify the resourcebinding represents resource is a workload which has a pod template ;
the function will be called by both the karmada-scheduler and the karmada controller.
For example:#6156
When the replicas of single pod template workload is zero, and
replicaSchedulingTypeof their resource bindings is notDuplicated, karmada-scehduler should ignore to reschedule these resource bindings.Fix relevant code:
karmada/pkg/scheduler/scheduler.go
Lines 393 to 401 in 006cf70