Skip to content
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

Keep backward compatibility for 'node.Spec.Unschedulable'. #68984

Merged
merged 1 commit into from
Sep 27, 2018
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
9 changes: 8 additions & 1 deletion pkg/scheduler/algorithm/predicates/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,14 @@ func CheckNodeUnschedulablePredicate(pod *v1.Pod, meta algorithm.PredicateMetada
return false, []algorithm.PredicateFailureReason{ErrNodeUnknownCondition}, nil
}

if nodeInfo.Node().Spec.Unschedulable {
// If pod tolerate unschedulable taint, it's also tolerate `node.Spec.Unschedulable`.
podToleratesUnschedulable := v1helper.TolerationsTolerateTaint(pod.Spec.Tolerations, &v1.Taint{
Key: algorithm.TaintNodeUnschedulable,
Effect: v1.TaintEffectNoSchedule,
})

// TODO (k82cn): deprecates `node.Spec.Unschedulable` in 1.13.
if nodeInfo.Node().Spec.Unschedulable && !podToleratesUnschedulable {
return false, []algorithm.PredicateFailureReason{ErrNodeUnschedulable}, nil
}

Expand Down
62 changes: 62 additions & 0 deletions pkg/scheduler/algorithm/predicates/predicates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4982,3 +4982,65 @@ func TestGetMaxVols(t *testing.T) {
os.Setenv(KubeMaxPDVols, previousValue)
}
}

func TestCheckNodeUnschedulablePredicate(t *testing.T) {
testCases := []struct {
name string
pod *v1.Pod
node *v1.Node
fit bool
}{
{
name: "Does not schedule pod to unschedulable node (node.Spec.Unschedulable==true)",
pod: &v1.Pod{},
node: &v1.Node{
Spec: v1.NodeSpec{
Unschedulable: true,
},
},
fit: false,
},
{
name: "Schedule pod to normal node",
pod: &v1.Pod{},
node: &v1.Node{
Spec: v1.NodeSpec{
Unschedulable: false,
},
},
fit: true,
},
{
name: "Schedule pod with toleration to unschedulable node (node.Spec.Unschedulable==true)",
pod: &v1.Pod{
Spec: v1.PodSpec{
Tolerations: []v1.Toleration{
{
Key: algorithm.TaintNodeUnschedulable,
Effect: v1.TaintEffectNoSchedule,
},
},
},
},
node: &v1.Node{
Spec: v1.NodeSpec{
Unschedulable: true,
},
},
fit: true,
},
}

for _, test := range testCases {
nodeInfo := schedulercache.NewNodeInfo()
nodeInfo.SetNode(test.node)
fit, _, err := CheckNodeUnschedulablePredicate(test.pod, nil, nodeInfo)
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like the CheckNodeUnschedulablePredicate() has no callers at all, can you confirm about that?
if so, do we still need to update this func?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added it by RegisterMandatoryFitPredicate in this PR.

if err != nil {
t.Fatalf("Failed to check node unschedulable: %v", err)
}

if fit != test.fit {
t.Errorf("Unexpected fit: expected %v, got %v", test.fit, fit)
}
}
}
3 changes: 3 additions & 0 deletions pkg/scheduler/algorithmprovider/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@ func ApplyFeatureGates() {

// Fit is determined based on whether a pod can tolerate all of the node's taints
factory.RegisterMandatoryFitPredicate(predicates.PodToleratesNodeTaintsPred, predicates.PodToleratesNodeTaints)
// Fit is determined based on whether a pod can tolerate unschedulable of node
factory.RegisterMandatoryFitPredicate(predicates.CheckNodeUnschedulablePred, predicates.CheckNodeUnschedulablePredicate)
// Insert Key "PodToleratesNodeTaints" and "CheckNodeUnschedulable" To All Algorithm Provider
// The key will insert to all providers which in algorithmProviderMap[]
// if you just want insert to specific provider, call func InsertPredicateKeyToAlgoProvider()
factory.InsertPredicateKeyToAlgorithmProviderMap(predicates.PodToleratesNodeTaintsPred)
factory.InsertPredicateKeyToAlgorithmProviderMap(predicates.CheckNodeUnschedulablePred)

glog.Warningf("TaintNodesByCondition is enabled, PodToleratesNodeTaints predicate is mandatory")
}
Expand Down