Skip to content

Commit 8848071

Browse files
authored
fix: update scheduler to support customized cluster affinity plugin (#330)
fix scheduler for future implementation Signed-off-by: Britania Rodriguez Reyes <[email protected]>
1 parent ffc7479 commit 8848071

File tree

5 files changed

+214
-154
lines changed

5 files changed

+214
-154
lines changed

pkg/scheduler/framework/plugins/clusteraffinity/filtering.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ func (p *Plugin) Filter(
5959

6060
for idx := range ps.GetPolicySnapshotSpec().Policy.Affinity.ClusterAffinity.RequiredDuringSchedulingIgnoredDuringExecution.ClusterSelectorTerms {
6161
t := &ps.GetPolicySnapshotSpec().Policy.Affinity.ClusterAffinity.RequiredDuringSchedulingIgnoredDuringExecution.ClusterSelectorTerms[idx]
62-
r := clusterRequirement(*t)
62+
r := clusterRequirement{
63+
ClusterSelectorTerm: *t,
64+
}
6365
isMatched, err := r.Matches(cluster)
6466
if err != nil {
6567
// An error has occurred when matching the cluster against a required affinity term.

pkg/scheduler/framework/plugins/clusteraffinity/plugin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package clusteraffinity features a scheduler plugin that enforces cluster affinity (if any) defined on a CRP.
17+
// Package clusteraffinity features a scheduler plugin that enforces cluster affinity (if any) defined on a RP/CRP.
1818
package clusteraffinity
1919

2020
import (
@@ -24,7 +24,7 @@ import (
2424
"github.com/kubefleet-dev/kubefleet/pkg/scheduler/framework"
2525
)
2626

27-
// Plugin is the scheduler plugin that enforces the cluster affinity (if any) defined on a CRP.
27+
// Plugin is the scheduler plugin that enforces the cluster affinity (if any) defined on a R/CRP.
2828
type Plugin struct {
2929
// The name of the plugin.
3030
name string

pkg/scheduler/framework/plugins/clusteraffinity/types.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ import (
3333

3434
// clusterRequirement is a type alias for ClusterSelectorTerm in the API, which allows
3535
// easy method extension.
36-
type clusterRequirement placementv1beta1.ClusterSelectorTerm
36+
type clusterRequirement struct {
37+
// Embed the original ClusterSelectorTerm.
38+
ClusterSelectorTerm placementv1beta1.ClusterSelectorTerm
39+
}
3740

3841
// retrieveResourceUsageFrom retrieves a resource property value from a member cluster.
3942
//
@@ -121,8 +124,8 @@ func retrievePropertyValueFrom(cluster *clusterv1beta1.MemberCluster, name strin
121124
// This is an extended method for the ClusterSelectorTerm API.
122125
func (c *clusterRequirement) Matches(cluster *clusterv1beta1.MemberCluster) (bool, error) {
123126
// Match the cluster against the label selector.
124-
if c.LabelSelector != nil {
125-
ls, err := metav1.LabelSelectorAsSelector(c.LabelSelector)
127+
if c.ClusterSelectorTerm.LabelSelector != nil {
128+
ls, err := metav1.LabelSelectorAsSelector(c.ClusterSelectorTerm.LabelSelector)
126129
if err != nil {
127130
return false, fmt.Errorf("failed to parse label selector: %w", err)
128131
}
@@ -134,12 +137,12 @@ func (c *clusterRequirement) Matches(cluster *clusterv1beta1.MemberCluster) (boo
134137
}
135138

136139
// Match the cluster against the property selector.
137-
if c.PropertySelector == nil || len(c.PropertySelector.MatchExpressions) == 0 {
140+
if c.ClusterSelectorTerm.PropertySelector == nil || len(c.ClusterSelectorTerm.PropertySelector.MatchExpressions) == 0 {
138141
// The term does not feature a property selector; no check is needed.
139142
return true, nil
140143
}
141144

142-
for _, exp := range c.PropertySelector.MatchExpressions {
145+
for _, exp := range c.ClusterSelectorTerm.PropertySelector.MatchExpressions {
143146
// Compare the observed value with the expected one using the specified operator.
144147
q, err := retrievePropertyValueFrom(cluster, exp.Name)
145148
if err != nil {

0 commit comments

Comments
 (0)