-
Notifications
You must be signed in to change notification settings - Fork 73
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
Support interpodaffinity and podtopologyspread #61
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,10 +31,12 @@ import ( | |
"github.com/kubewharf/godel-scheduler/pkg/binder/apis" | ||
godelcache "github.com/kubewharf/godel-scheduler/pkg/binder/cache" | ||
"github.com/kubewharf/godel-scheduler/pkg/binder/framework/plugins/defaultbinder" | ||
"github.com/kubewharf/godel-scheduler/pkg/binder/framework/plugins/interpodaffinity" | ||
"github.com/kubewharf/godel-scheduler/pkg/binder/framework/plugins/nodeports" | ||
"github.com/kubewharf/godel-scheduler/pkg/binder/framework/plugins/noderesources" | ||
"github.com/kubewharf/godel-scheduler/pkg/binder/framework/plugins/nodevolumelimits" | ||
"github.com/kubewharf/godel-scheduler/pkg/binder/framework/plugins/nonnativeresource" | ||
"github.com/kubewharf/godel-scheduler/pkg/binder/framework/plugins/podtopologyspread" | ||
"github.com/kubewharf/godel-scheduler/pkg/binder/framework/plugins/volumebinding" | ||
"github.com/kubewharf/godel-scheduler/pkg/binder/queue" | ||
"github.com/kubewharf/godel-scheduler/pkg/features" | ||
|
@@ -67,7 +69,10 @@ func DefaultUnitQueueSortFunc() framework.UnitLessFunc { | |
func NewBasePlugins(victimsCheckingPlugins []*framework.VictimCheckingPluginCollectionSpec) *apis.BinderPluginCollection { | ||
// TODO add some default plugins later | ||
basicPlugins := apis.BinderPluginCollection{ | ||
CheckTopology: []string{}, | ||
CheckTopology: []string{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add these plugins on demand. We don't need to prepare date when the incoming Pod doesn't have cross-node constraints. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After considering the |
||
interpodaffinity.Name, | ||
podtopologyspread.Name, | ||
}, | ||
CheckConflicts: []string{ | ||
noderesources.ConflictCheckName, | ||
nodevolumelimits.CSIName, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
Copyright 2024 The Godel Scheduler Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package interpodaffinity | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/kubewharf/godel-scheduler/pkg/binder/framework/handle" | ||
framework "github.com/kubewharf/godel-scheduler/pkg/framework/api" | ||
utils "github.com/kubewharf/godel-scheduler/pkg/plugins/interpodaffinity" | ||
"github.com/kubewharf/godel-scheduler/pkg/plugins/podlauncher" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
const ( | ||
Name = "InterPodAffinityCheck" | ||
ErrorReasonWhenFilterNodeWithSameTopology = "failed to get nodes with same topology labels" | ||
) | ||
|
||
type InterPodAffinity struct { | ||
frameworkHandle handle.BinderFrameworkHandle | ||
} | ||
|
||
var _ framework.CheckTopologyPlugin = &InterPodAffinity{} | ||
|
||
func (pl *InterPodAffinity) Name() string { | ||
return Name | ||
} | ||
|
||
func (pl *InterPodAffinity) CheckTopology(_ context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeInfo framework.NodeInfo) *framework.Status { | ||
// Get the nodes with the same topology labels as the node to be scheduled | ||
podLauncher, status := podlauncher.NodeFits(nil, pod, nodeInfo) | ||
if status != nil { | ||
return status | ||
} | ||
|
||
nodeInfos := pl.frameworkHandle.ListNodeInfos() | ||
|
||
existingPodAntiAffinityMap := utils.GetTPMapMatchingExistingAntiAffinity(pod, nodeInfos) | ||
|
||
podInfo := framework.NewPodInfo(pod) | ||
incomingPodAffinityMap, incomingPodAntiAffinityMap := utils.GetTPMapMatchingIncomingAffinityAntiAffinity(podInfo, nodeInfos) | ||
|
||
state := &utils.PreFilterState{ | ||
TopologyToMatchedExistingAntiAffinityTerms: existingPodAntiAffinityMap, | ||
TopologyToMatchedAffinityTerms: incomingPodAffinityMap, | ||
TopologyToMatchedAntiAffinityTerms: incomingPodAntiAffinityMap, | ||
PodInfo: podInfo, | ||
} | ||
|
||
if !utils.SatisfyPodAffinity(state, nodeInfo, podLauncher) { | ||
return framework.NewStatus(framework.UnschedulableAndUnresolvable, utils.ErrReasonAffinityNotMatch, utils.ErrReasonAffinityRulesNotMatch) | ||
} | ||
|
||
if !utils.SatisfyPodAntiAffinity(state, nodeInfo, podLauncher) { | ||
return framework.NewStatus(framework.Unschedulable, utils.ErrReasonAffinityNotMatch, utils.ErrReasonAntiAffinityRulesNotMatch) | ||
} | ||
|
||
if !utils.SatisfyExistingPodsAntiAffinity(state, nodeInfo, podLauncher) { | ||
return framework.NewStatus(framework.Unschedulable, utils.ErrReasonAffinityNotMatch, utils.ErrReasonExistingAntiAffinityRulesNotMatch) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func New(_ runtime.Object, handle handle.BinderFrameworkHandle) (framework.Plugin, error) { | ||
return &InterPodAffinity{ | ||
frameworkHandle: handle, | ||
}, nil | ||
} |
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.
Need lock.
BTW it's dangerous to expose all of the nodes.
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.
Yes, I have add lock.
Because the binder needs all the nodeInfo information when performing topology checks for
InterPodAffinity
andPodTopologySpread
, I added this function. Is there a safer method?