1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /*
- 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"
- framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
- schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
- )
- 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 := schedulernodeinfo.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)
- }
- }
- }
|