Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/scheduler/framework/plugins/clusteraffinity/filtering.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func (p *Plugin) Filter(

for idx := range ps.GetPolicySnapshotSpec().Policy.Affinity.ClusterAffinity.RequiredDuringSchedulingIgnoredDuringExecution.ClusterSelectorTerms {
t := &ps.GetPolicySnapshotSpec().Policy.Affinity.ClusterAffinity.RequiredDuringSchedulingIgnoredDuringExecution.ClusterSelectorTerms[idx]
r := clusterRequirement(*t)
r := clusterRequirement{
ClusterSelectorTerm: *t,
}
isMatched, err := r.Matches(cluster)
if err != nil {
// An error has occurred when matching the cluster against a required affinity term.
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/framework/plugins/clusteraffinity/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

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

import (
Expand All @@ -24,7 +24,7 @@ import (
"github.com/kubefleet-dev/kubefleet/pkg/scheduler/framework"
)

// Plugin is the scheduler plugin that enforces the cluster affinity (if any) defined on a CRP.
// Plugin is the scheduler plugin that enforces the cluster affinity (if any) defined on a R/CRP.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Plugin is the scheduler plugin that enforces the cluster affinity (if any) defined on a R/CRP.
// Plugin is the scheduler plugin that enforces the cluster affinity (if any) defined on a RP/CRP.

type Plugin struct {
// The name of the plugin.
name string
Expand Down
13 changes: 8 additions & 5 deletions pkg/scheduler/framework/plugins/clusteraffinity/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import (

// clusterRequirement is a type alias for ClusterSelectorTerm in the API, which allows
// easy method extension.
type clusterRequirement placementv1beta1.ClusterSelectorTerm
type clusterRequirement struct {
// Embed the original ClusterSelectorTerm.
ClusterSelectorTerm placementv1beta1.ClusterSelectorTerm
}

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

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

for _, exp := range c.PropertySelector.MatchExpressions {
for _, exp := range c.ClusterSelectorTerm.PropertySelector.MatchExpressions {
// Compare the observed value with the expected one using the specified operator.
q, err := retrievePropertyValueFrom(cluster, exp.Name)
if err != nil {
Expand Down
Loading
Loading