Skip to content

Commit

Permalink
Merge pull request #318 from Tal-or/best_effort_pod_fix
Browse files Browse the repository at this point in the history
NodeResourceTopology: handle best-effort pods in score plugin
  • Loading branch information
k8s-ci-robot authored Jan 20, 2022
2 parents 7b3182b + 954d0c2 commit ec632c3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/noderesourcetopology/score.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

v1 "k8s.io/api/core/v1"
"k8s.io/klog/v2"
v1qos "k8s.io/kubernetes/pkg/apis/core/v1/helper/qos"
"k8s.io/kubernetes/pkg/scheduler/framework"
apiconfig "sigs.k8s.io/scheduler-plugins/pkg/apis/config"

Expand Down Expand Up @@ -55,6 +56,11 @@ func (rw resourceToWeightMap) weight(r v1.ResourceName) int64 {

func (tm *TopologyMatch) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
klog.V(5).InfoS("Scoring node", "nodeName", nodeName)
// if it's a non-guaranteed pod, every node is considered to be a good fit
if v1qos.GetPodQOS(pod) != v1.PodQOSGuaranteed {
return framework.MaxNodeScore, nil
}

nodeTopology := findNodeTopology(nodeName, tm.lister)

if nodeTopology == nil {
Expand Down
26 changes: 26 additions & 0 deletions test/integration/noderesourcetopology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,32 @@ func TestTopologyMatchPlugin(t *testing.T) {
},
expectedNodes: []string{"fake-node-1"},
},
// in the following "Scheduling Best-Effort pod with least-allocatable/balanced-allocation/most-allocatable strategy" tests,
// both nodes are expected to get the maximum score.
// in case of multiple nodes with the same highest score, the chosen node selection might vary.
// thus, we can't tell exactly which node will get selected, so the only option is to accept both of them,
// and it's still good enough for making sure that pod not stuck in pending state and/or the program isn't crashing
{
name: "Scheduling Best-Effort pod with least-allocatable strategy scheduler",
pods: []*v1.Pod{
st.MakePod().Namespace(ns.Name).Name("topology-aware-scheduler-pod").SchedulerName(leastAllocatableScheduler).Container(pause).Obj(),
},
expectedNodes: []string{"fake-node-1", "fake-node-2"},
},
{
name: "Scheduling Best-Effort pod with balanced-allocation strategy scheduler",
pods: []*v1.Pod{
st.MakePod().Namespace(ns.Name).Name("topology-aware-scheduler-pod").SchedulerName(balancedAllocationScheduler).Container(pause).Obj(),
},
expectedNodes: []string{"fake-node-1", "fake-node-2"},
},
{
name: "Scheduling Best-Effort pod with most-allocatable strategy scheduler",
pods: []*v1.Pod{
st.MakePod().Namespace(ns.Name).Name("topology-aware-scheduler-pod").SchedulerName(mostAllocatableScheduler).Container(pause).Obj(),
},
expectedNodes: []string{"fake-node-1", "fake-node-2"},
},
} {
t.Run(tt.name, func(t *testing.T) {
t.Logf("Start-topology-match-test %v", tt.name)
Expand Down

0 comments on commit ec632c3

Please sign in to comment.