123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- /*
- 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 volumerestrictions
- 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 TestGCEDiskConflicts(t *testing.T) {
- volState := v1.PodSpec{
- Volumes: []v1.Volume{
- {
- VolumeSource: v1.VolumeSource{
- GCEPersistentDisk: &v1.GCEPersistentDiskVolumeSource{
- PDName: "foo",
- },
- },
- },
- },
- }
- volState2 := v1.PodSpec{
- Volumes: []v1.Volume{
- {
- VolumeSource: v1.VolumeSource{
- GCEPersistentDisk: &v1.GCEPersistentDiskVolumeSource{
- PDName: "bar",
- },
- },
- },
- },
- }
- errStatus := framework.NewStatus(framework.Unschedulable, ErrReasonDiskConflict)
- tests := []struct {
- pod *v1.Pod
- nodeInfo *schedulernodeinfo.NodeInfo
- isOk bool
- name string
- wantStatus *framework.Status
- }{
- {&v1.Pod{}, schedulernodeinfo.NewNodeInfo(), true, "nothing", nil},
- {&v1.Pod{}, schedulernodeinfo.NewNodeInfo(&v1.Pod{Spec: volState}), true, "one state", nil},
- {&v1.Pod{Spec: volState}, schedulernodeinfo.NewNodeInfo(&v1.Pod{Spec: volState}), false, "same state", errStatus},
- {&v1.Pod{Spec: volState2}, schedulernodeinfo.NewNodeInfo(&v1.Pod{Spec: volState}), true, "different state", nil},
- }
- for _, test := range tests {
- t.Run(test.name, func(t *testing.T) {
- p, _ := New(nil, nil)
- gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), nil, test.pod, test.nodeInfo)
- if !reflect.DeepEqual(gotStatus, test.wantStatus) {
- t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
- }
- })
- }
- }
- func TestAWSDiskConflicts(t *testing.T) {
- volState := v1.PodSpec{
- Volumes: []v1.Volume{
- {
- VolumeSource: v1.VolumeSource{
- AWSElasticBlockStore: &v1.AWSElasticBlockStoreVolumeSource{
- VolumeID: "foo",
- },
- },
- },
- },
- }
- volState2 := v1.PodSpec{
- Volumes: []v1.Volume{
- {
- VolumeSource: v1.VolumeSource{
- AWSElasticBlockStore: &v1.AWSElasticBlockStoreVolumeSource{
- VolumeID: "bar",
- },
- },
- },
- },
- }
- errStatus := framework.NewStatus(framework.Unschedulable, ErrReasonDiskConflict)
- tests := []struct {
- pod *v1.Pod
- nodeInfo *schedulernodeinfo.NodeInfo
- isOk bool
- name string
- wantStatus *framework.Status
- }{
- {&v1.Pod{}, schedulernodeinfo.NewNodeInfo(), true, "nothing", nil},
- {&v1.Pod{}, schedulernodeinfo.NewNodeInfo(&v1.Pod{Spec: volState}), true, "one state", nil},
- {&v1.Pod{Spec: volState}, schedulernodeinfo.NewNodeInfo(&v1.Pod{Spec: volState}), false, "same state", errStatus},
- {&v1.Pod{Spec: volState2}, schedulernodeinfo.NewNodeInfo(&v1.Pod{Spec: volState}), true, "different state", nil},
- }
- for _, test := range tests {
- t.Run(test.name, func(t *testing.T) {
- p, _ := New(nil, nil)
- gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), nil, test.pod, test.nodeInfo)
- if !reflect.DeepEqual(gotStatus, test.wantStatus) {
- t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
- }
- })
- }
- }
- func TestRBDDiskConflicts(t *testing.T) {
- volState := v1.PodSpec{
- Volumes: []v1.Volume{
- {
- VolumeSource: v1.VolumeSource{
- RBD: &v1.RBDVolumeSource{
- CephMonitors: []string{"a", "b"},
- RBDPool: "foo",
- RBDImage: "bar",
- FSType: "ext4",
- },
- },
- },
- },
- }
- volState2 := v1.PodSpec{
- Volumes: []v1.Volume{
- {
- VolumeSource: v1.VolumeSource{
- RBD: &v1.RBDVolumeSource{
- CephMonitors: []string{"c", "d"},
- RBDPool: "foo",
- RBDImage: "bar",
- FSType: "ext4",
- },
- },
- },
- },
- }
- errStatus := framework.NewStatus(framework.Unschedulable, ErrReasonDiskConflict)
- tests := []struct {
- pod *v1.Pod
- nodeInfo *schedulernodeinfo.NodeInfo
- isOk bool
- name string
- wantStatus *framework.Status
- }{
- {&v1.Pod{}, schedulernodeinfo.NewNodeInfo(), true, "nothing", nil},
- {&v1.Pod{}, schedulernodeinfo.NewNodeInfo(&v1.Pod{Spec: volState}), true, "one state", nil},
- {&v1.Pod{Spec: volState}, schedulernodeinfo.NewNodeInfo(&v1.Pod{Spec: volState}), false, "same state", errStatus},
- {&v1.Pod{Spec: volState2}, schedulernodeinfo.NewNodeInfo(&v1.Pod{Spec: volState}), true, "different state", nil},
- }
- for _, test := range tests {
- t.Run(test.name, func(t *testing.T) {
- p, _ := New(nil, nil)
- gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), nil, test.pod, test.nodeInfo)
- if !reflect.DeepEqual(gotStatus, test.wantStatus) {
- t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
- }
- })
- }
- }
- func TestISCSIDiskConflicts(t *testing.T) {
- volState := v1.PodSpec{
- Volumes: []v1.Volume{
- {
- VolumeSource: v1.VolumeSource{
- ISCSI: &v1.ISCSIVolumeSource{
- TargetPortal: "127.0.0.1:3260",
- IQN: "iqn.2016-12.server:storage.target01",
- FSType: "ext4",
- Lun: 0,
- },
- },
- },
- },
- }
- volState2 := v1.PodSpec{
- Volumes: []v1.Volume{
- {
- VolumeSource: v1.VolumeSource{
- ISCSI: &v1.ISCSIVolumeSource{
- TargetPortal: "127.0.0.1:3260",
- IQN: "iqn.2017-12.server:storage.target01",
- FSType: "ext4",
- Lun: 0,
- },
- },
- },
- },
- }
- errStatus := framework.NewStatus(framework.Unschedulable, ErrReasonDiskConflict)
- tests := []struct {
- pod *v1.Pod
- nodeInfo *schedulernodeinfo.NodeInfo
- isOk bool
- name string
- wantStatus *framework.Status
- }{
- {&v1.Pod{}, schedulernodeinfo.NewNodeInfo(), true, "nothing", nil},
- {&v1.Pod{}, schedulernodeinfo.NewNodeInfo(&v1.Pod{Spec: volState}), true, "one state", nil},
- {&v1.Pod{Spec: volState}, schedulernodeinfo.NewNodeInfo(&v1.Pod{Spec: volState}), false, "same state", errStatus},
- {&v1.Pod{Spec: volState2}, schedulernodeinfo.NewNodeInfo(&v1.Pod{Spec: volState}), true, "different state", nil},
- }
- for _, test := range tests {
- t.Run(test.name, func(t *testing.T) {
- p, _ := New(nil, nil)
- gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), nil, test.pod, test.nodeInfo)
- if !reflect.DeepEqual(gotStatus, test.wantStatus) {
- t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
- }
- })
- }
- }
|