Merge pull request #114125 from sanposhiho/skip-reimplementation

feature(scheduler): won't run Filter if PreFilter returned a Skip status
This commit is contained in:
Kubernetes Prow Robot
2023-01-06 02:25:59 -08:00
committed by GitHub
8 changed files with 406 additions and 47 deletions

View File

@@ -20,7 +20,7 @@ import (
"context"
"fmt"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
@@ -89,13 +89,19 @@ func (pl *NodeAffinity) EventsToRegister() []framework.ClusterEvent {
// PreFilter builds and writes cycle state used by Filter.
func (pl *NodeAffinity) PreFilter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
affinity := pod.Spec.Affinity
noNodeAffinity := (affinity == nil ||
affinity.NodeAffinity == nil ||
affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution == nil)
if noNodeAffinity && pl.addedNodeSelector == nil && pod.Spec.NodeSelector == nil {
// NodeAffinity Filter has nothing to do with the Pod.
return nil, framework.NewStatus(framework.Skip)
}
state := &preFilterState{requiredNodeSelectorAndAffinity: nodeaffinity.GetRequiredNodeAffinity(pod)}
cycleState.Write(preFilterStateKey, state)
affinity := pod.Spec.Affinity
if affinity == nil ||
affinity.NodeAffinity == nil ||
affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution == nil ||
len(affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms) == 0 {
if noNodeAffinity || len(affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms) == 0 {
return nil, nil
}

View File

@@ -44,10 +44,6 @@ func TestNodeAffinity(t *testing.T) {
args config.NodeAffinityArgs
disablePreFilter bool
}{
{
name: "no selector",
pod: &v1.Pod{},
},
{
name: "missing labels",
pod: st.MakePod().NodeSelector(map[string]string{
@@ -285,6 +281,7 @@ func TestNodeAffinity(t *testing.T) {
labels: map[string]string{
"foo": "bar",
},
wantPreFilterStatus: framework.NewStatus(framework.Skip),
},
{
name: "Pod with Affinity but nil NodeSelector will schedule onto a node",
@@ -300,6 +297,7 @@ func TestNodeAffinity(t *testing.T) {
labels: map[string]string{
"foo": "bar",
},
wantPreFilterStatus: framework.NewStatus(framework.Skip),
},
{
name: "Pod with multiple matchExpressions ANDed that matches the existing node",