kubernetes/pkg/scheduler/framework/plugins/nodeunschedulable/node_unschedulable_test.go

85 lines
2.0 KiB
Go

/*
Copyright 2019 The Kubernetes 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 nodeunschedulable
import (
"context"
"reflect"
"testing"
v1 "k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/scheduler/framework"
)
func TestNodeUnschedulable(t *testing.T) {
testCases := []struct {
name string
pod *v1.Pod
node *v1.Node
wantStatus *framework.Status
}{
{
name: "Does not schedule pod to unschedulable node (node.Spec.Unschedulable==true)",
pod: &v1.Pod{},
node: &v1.Node{
Spec: v1.NodeSpec{
Unschedulable: true,
},
},
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonUnschedulable),
},
{
name: "Schedule pod to normal node",
pod: &v1.Pod{},
node: &v1.Node{
Spec: v1.NodeSpec{
Unschedulable: false,
},
},
},
{
name: "Schedule pod with toleration to unschedulable node (node.Spec.Unschedulable==true)",
pod: &v1.Pod{
Spec: v1.PodSpec{
Tolerations: []v1.Toleration{
{
Key: v1.TaintNodeUnschedulable,
Effect: v1.TaintEffectNoSchedule,
},
},
},
},
node: &v1.Node{
Spec: v1.NodeSpec{
Unschedulable: true,
},
},
},
}
for _, test := range testCases {
nodeInfo := framework.NewNodeInfo()
nodeInfo.SetNode(test.node)
p, _ := New(nil, nil)
gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), nil, test.pod, nodeInfo)
if !reflect.DeepEqual(gotStatus, test.wantStatus) {
t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
}
}
}