tests only

This commit is contained in:
Yecheng Fu 2020-06-17 20:43:02 +08:00
parent ee4d7410be
commit 4627b419b4
8 changed files with 128 additions and 310 deletions

View File

@ -202,7 +202,6 @@ profiles:
"ReservePlugin": {{Name: "VolumeBinding"}}, "ReservePlugin": {{Name: "VolumeBinding"}},
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
} }
testcases := []struct { testcases := []struct {
@ -237,7 +236,6 @@ profiles:
"ReservePlugin": {{Name: "VolumeBinding"}}, "ReservePlugin": {{Name: "VolumeBinding"}},
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
}, },
}, },
@ -255,7 +253,6 @@ profiles:
"ReservePlugin": {{Name: "VolumeBinding"}}, "ReservePlugin": {{Name: "VolumeBinding"}},
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
}, },
}, },
@ -338,7 +335,6 @@ profiles:
"ReservePlugin": {{Name: "VolumeBinding"}}, "ReservePlugin": {{Name: "VolumeBinding"}},
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
}, },
}, },

View File

@ -1,150 +0,0 @@
/*
Copyright 2017 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 scheduling
import (
"reflect"
"testing"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestUpdateGetBindings(t *testing.T) {
scenarios := map[string]struct {
updateBindings []*bindingInfo
updateProvisionings []*v1.PersistentVolumeClaim
updatePod string
updateNode string
getBindings []*bindingInfo
getProvisionings []*v1.PersistentVolumeClaim
getPod string
getNode string
}{
"no-pod": {
getPod: "pod1",
getNode: "node1",
},
"no-node": {
updatePod: "pod1",
updateNode: "node1",
updateBindings: []*bindingInfo{},
updateProvisionings: []*v1.PersistentVolumeClaim{},
getPod: "pod1",
getNode: "node2",
},
"binding-nil": {
updatePod: "pod1",
updateNode: "node1",
updateBindings: nil,
updateProvisionings: nil,
getPod: "pod1",
getNode: "node1",
},
"binding-exists": {
updatePod: "pod1",
updateNode: "node1",
updateBindings: []*bindingInfo{{pvc: &v1.PersistentVolumeClaim{ObjectMeta: metav1.ObjectMeta{Name: "pvc1"}}}},
updateProvisionings: []*v1.PersistentVolumeClaim{{ObjectMeta: metav1.ObjectMeta{Name: "pvc2"}}},
getPod: "pod1",
getNode: "node1",
getBindings: []*bindingInfo{{pvc: &v1.PersistentVolumeClaim{ObjectMeta: metav1.ObjectMeta{Name: "pvc1"}}}},
getProvisionings: []*v1.PersistentVolumeClaim{{ObjectMeta: metav1.ObjectMeta{Name: "pvc2"}}},
},
}
for name, scenario := range scenarios {
cache := NewPodBindingCache()
// Perform updates
updatePod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: scenario.updatePod, Namespace: "ns"}}
cache.UpdateBindings(updatePod, scenario.updateNode, scenario.updateBindings, scenario.updateProvisionings)
// Verify updated bindings
bindings := cache.GetBindings(updatePod, scenario.updateNode)
if !reflect.DeepEqual(bindings, scenario.updateBindings) {
t.Errorf("Test %v failed: returned bindings after update different. Got %+v, expected %+v", name, bindings, scenario.updateBindings)
}
// Verify updated provisionings
provisionings := cache.GetProvisionedPVCs(updatePod, scenario.updateNode)
if !reflect.DeepEqual(provisionings, scenario.updateProvisionings) {
t.Errorf("Test %v failed: returned provisionings after update different. Got %+v, expected %+v", name, provisionings, scenario.updateProvisionings)
}
// Get bindings
getPod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: scenario.getPod, Namespace: "ns"}}
bindings = cache.GetBindings(getPod, scenario.getNode)
if !reflect.DeepEqual(bindings, scenario.getBindings) {
t.Errorf("Test %v failed: unexpected bindings returned. Got %+v, expected %+v", name, bindings, scenario.updateBindings)
}
// Get provisionings
provisionings = cache.GetProvisionedPVCs(getPod, scenario.getNode)
if !reflect.DeepEqual(provisionings, scenario.getProvisionings) {
t.Errorf("Test %v failed: unexpected bindings returned. Got %+v, expected %+v", name, provisionings, scenario.getProvisionings)
}
}
}
func TestDeleteBindings(t *testing.T) {
initialBindings := []*bindingInfo{{pvc: &v1.PersistentVolumeClaim{ObjectMeta: metav1.ObjectMeta{Name: "pvc1"}}}}
initialProvisionings := []*v1.PersistentVolumeClaim{{ObjectMeta: metav1.ObjectMeta{Name: "pvc2"}}}
cache := NewPodBindingCache()
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "pod1", Namespace: "ns"}}
// Get nil bindings and provisionings
bindings := cache.GetBindings(pod, "node1")
if bindings != nil {
t.Errorf("Test failed: expected initial nil bindings, got %+v", bindings)
}
provisionings := cache.GetProvisionedPVCs(pod, "node1")
if provisionings != nil {
t.Errorf("Test failed: expected initial nil provisionings, got %+v", provisionings)
}
// Delete nothing
cache.DeleteBindings(pod)
// Perform updates
cache.UpdateBindings(pod, "node1", initialBindings, initialProvisionings)
// Get bindings and provisionings
bindings = cache.GetBindings(pod, "node1")
if !reflect.DeepEqual(bindings, initialBindings) {
t.Errorf("Test failed: expected bindings %+v, got %+v", initialBindings, bindings)
}
provisionings = cache.GetProvisionedPVCs(pod, "node1")
if !reflect.DeepEqual(provisionings, initialProvisionings) {
t.Errorf("Test failed: expected provisionings %+v, got %+v", initialProvisionings, provisionings)
}
// Delete
cache.DeleteBindings(pod)
// Get bindings and provisionings
bindings = cache.GetBindings(pod, "node1")
if bindings != nil {
t.Errorf("Test failed: expected nil bindings, got %+v", bindings)
}
provisionings = cache.GetProvisionedPVCs(pod, "node1")
if provisionings != nil {
t.Errorf("Test failed: expected nil provisionings, got %+v", provisionings)
}
}

View File

@ -123,6 +123,7 @@ type testEnv struct {
reactor *pvtesting.VolumeReactor reactor *pvtesting.VolumeReactor
binder SchedulerVolumeBinder binder SchedulerVolumeBinder
internalBinder *volumeBinder internalBinder *volumeBinder
internalPodInformer coreinformers.PodInformer
internalNodeInformer coreinformers.NodeInformer internalNodeInformer coreinformers.NodeInformer
internalCSINodeInformer storageinformers.CSINodeInformer internalCSINodeInformer storageinformers.CSINodeInformer
internalPVCache *assumeCache internalPVCache *assumeCache
@ -144,12 +145,14 @@ func newTestBinder(t *testing.T, stopCh <-chan struct{}) *testEnv {
}) })
informerFactory := informers.NewSharedInformerFactory(client, controller.NoResyncPeriodFunc()) informerFactory := informers.NewSharedInformerFactory(client, controller.NoResyncPeriodFunc())
podInformer := informerFactory.Core().V1().Pods()
nodeInformer := informerFactory.Core().V1().Nodes() nodeInformer := informerFactory.Core().V1().Nodes()
csiNodeInformer := informerFactory.Storage().V1().CSINodes() csiNodeInformer := informerFactory.Storage().V1().CSINodes()
pvcInformer := informerFactory.Core().V1().PersistentVolumeClaims() pvcInformer := informerFactory.Core().V1().PersistentVolumeClaims()
classInformer := informerFactory.Storage().V1().StorageClasses() classInformer := informerFactory.Storage().V1().StorageClasses()
binder := NewVolumeBinder( binder := NewVolumeBinder(
client, client,
podInformer,
nodeInformer, nodeInformer,
csiNodeInformer, csiNodeInformer,
pvcInformer, pvcInformer,
@ -246,6 +249,7 @@ func newTestBinder(t *testing.T, stopCh <-chan struct{}) *testEnv {
reactor: reactor, reactor: reactor,
binder: binder, binder: binder,
internalBinder: internalBinder, internalBinder: internalBinder,
internalPodInformer: podInformer,
internalNodeInformer: nodeInformer, internalNodeInformer: nodeInformer,
internalCSINodeInformer: csiNodeInformer, internalCSINodeInformer: csiNodeInformer,
internalPVCache: internalPVCache, internalPVCache: internalPVCache,
@ -358,7 +362,7 @@ func (env *testEnv) deleteClaims(pvcs []*v1.PersistentVolumeClaim) {
} }
} }
func (env *testEnv) assumeVolumes(t *testing.T, node string, pod *v1.Pod, bindings []*bindingInfo, provisionings []*v1.PersistentVolumeClaim) { func (env *testEnv) assumeVolumes(t *testing.T, node string, pod *v1.Pod, bindings []*BindingInfo, provisionings []*v1.PersistentVolumeClaim) {
pvCache := env.internalBinder.pvCache pvCache := env.internalBinder.pvCache
for _, binding := range bindings { for _, binding := range bindings {
if err := pvCache.Assume(binding.pv); err != nil { if err := pvCache.Assume(binding.pv); err != nil {
@ -372,18 +376,17 @@ func (env *testEnv) assumeVolumes(t *testing.T, node string, pod *v1.Pod, bindin
t.Fatalf("error: %v", err) t.Fatalf("error: %v", err)
} }
} }
env.internalBinder.podBindingCache.UpdateBindings(pod, node, bindings, provisionings)
} }
func (env *testEnv) initPodCache(pod *v1.Pod, node string, bindings []*bindingInfo, provisionings []*v1.PersistentVolumeClaim) { func (env *testEnv) validatePodCache(t *testing.T, node string, pod *v1.Pod, podVolumes *PodVolumes, expectedBindings []*BindingInfo, expectedProvisionings []*v1.PersistentVolumeClaim) {
cache := env.internalBinder.podBindingCache var (
cache.UpdateBindings(pod, node, bindings, provisionings) bindings []*BindingInfo
} provisionedClaims []*v1.PersistentVolumeClaim
)
func (env *testEnv) validatePodCache(t *testing.T, node string, pod *v1.Pod, expectedBindings []*bindingInfo, expectedProvisionings []*v1.PersistentVolumeClaim) { if podVolumes != nil {
cache := env.internalBinder.podBindingCache bindings = podVolumes.StaticBindings
bindings := cache.GetBindings(pod, node) provisionedClaims = podVolumes.DynamicProvisions
}
if aLen, eLen := len(bindings), len(expectedBindings); aLen != eLen { if aLen, eLen := len(bindings), len(expectedBindings); aLen != eLen {
t.Errorf("expected %v bindings, got %v", eLen, aLen) t.Errorf("expected %v bindings, got %v", eLen, aLen)
} else if expectedBindings == nil && bindings != nil { } else if expectedBindings == nil && bindings != nil {
@ -406,7 +409,6 @@ func (env *testEnv) validatePodCache(t *testing.T, node string, pod *v1.Pod, exp
} }
} }
provisionedClaims := cache.GetProvisionedPVCs(pod, node)
if aLen, eLen := len(provisionedClaims), len(expectedProvisionings); aLen != eLen { if aLen, eLen := len(provisionedClaims), len(expectedProvisionings); aLen != eLen {
t.Errorf("expected %v provisioned claims, got %v", eLen, aLen) t.Errorf("expected %v provisioned claims, got %v", eLen, aLen)
} else if expectedProvisionings == nil && provisionedClaims != nil { } else if expectedProvisionings == nil && provisionedClaims != nil {
@ -424,12 +426,7 @@ func (env *testEnv) validatePodCache(t *testing.T, node string, pod *v1.Pod, exp
} }
} }
func (env *testEnv) getPodBindings(t *testing.T, node string, pod *v1.Pod) []*bindingInfo { func (env *testEnv) validateAssume(t *testing.T, pod *v1.Pod, bindings []*BindingInfo, provisionings []*v1.PersistentVolumeClaim) {
cache := env.internalBinder.podBindingCache
return cache.GetBindings(pod, node)
}
func (env *testEnv) validateAssume(t *testing.T, pod *v1.Pod, bindings []*bindingInfo, provisionings []*v1.PersistentVolumeClaim) {
// Check pv cache // Check pv cache
pvCache := env.internalBinder.pvCache pvCache := env.internalBinder.pvCache
for _, b := range bindings { for _, b := range bindings {
@ -465,7 +462,7 @@ func (env *testEnv) validateAssume(t *testing.T, pod *v1.Pod, bindings []*bindin
} }
} }
func (env *testEnv) validateCacheRestored(t *testing.T, pod *v1.Pod, bindings []*bindingInfo, provisionings []*v1.PersistentVolumeClaim) { func (env *testEnv) validateCacheRestored(t *testing.T, pod *v1.Pod, bindings []*BindingInfo, provisionings []*v1.PersistentVolumeClaim) {
// All PVs have been unmodified in cache // All PVs have been unmodified in cache
pvCache := env.internalBinder.pvCache pvCache := env.internalBinder.pvCache
for _, b := range bindings { for _, b := range bindings {
@ -725,8 +722,8 @@ func makePodWithoutPVC() *v1.Pod {
return pod return pod
} }
func makeBinding(pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) *bindingInfo { func makeBinding(pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) *BindingInfo {
return &bindingInfo{pvc: pvc, pv: pv} return &BindingInfo{pvc: pvc, pv: pv}
} }
func addProvisionAnn(pvc *v1.PersistentVolumeClaim) *v1.PersistentVolumeClaim { func addProvisionAnn(pvc *v1.PersistentVolumeClaim) *v1.PersistentVolumeClaim {
@ -773,13 +770,13 @@ func checkReasons(t *testing.T, actual, expected ConflictReasons) {
} }
// findPodVolumes gets and finds volumes for given pod and node // findPodVolumes gets and finds volumes for given pod and node
func findPodVolumes(binder SchedulerVolumeBinder, pod *v1.Pod, node *v1.Node) (ConflictReasons, error) { func findPodVolumes(binder SchedulerVolumeBinder, pod *v1.Pod, node *v1.Node) (*PodVolumes, ConflictReasons, error) {
boundClaims, claimsToBind, unboundClaimsImmediate, err := binder.GetPodVolumes(pod) boundClaims, claimsToBind, unboundClaimsImmediate, err := binder.GetPodVolumes(pod)
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
if len(unboundClaimsImmediate) > 0 { if len(unboundClaimsImmediate) > 0 {
return nil, fmt.Errorf("pod has unbound immediate PersistentVolumeClaims") return nil, nil, fmt.Errorf("pod has unbound immediate PersistentVolumeClaims")
} }
return binder.FindPodVolumes(pod, boundClaims, claimsToBind, node) return binder.FindPodVolumes(pod, boundClaims, claimsToBind, node)
} }
@ -795,7 +792,7 @@ func TestFindPodVolumesWithoutProvisioning(t *testing.T) {
pod *v1.Pod pod *v1.Pod
// Expected podBindingCache fields // Expected podBindingCache fields
expectedBindings []*bindingInfo expectedBindings []*BindingInfo
// Expected return values // Expected return values
reasons ConflictReasons reasons ConflictReasons
@ -829,7 +826,7 @@ func TestFindPodVolumesWithoutProvisioning(t *testing.T) {
"unbound-pvc,pv-same-node": { "unbound-pvc,pv-same-node": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC},
pvs: []*v1.PersistentVolume{pvNode2, pvNode1a, pvNode1b}, pvs: []*v1.PersistentVolume{pvNode2, pvNode1a, pvNode1b},
expectedBindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1a)}, expectedBindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1a)},
}, },
"unbound-pvc,pv-different-node": { "unbound-pvc,pv-different-node": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC},
@ -839,23 +836,23 @@ func TestFindPodVolumesWithoutProvisioning(t *testing.T) {
"two-unbound-pvcs": { "two-unbound-pvcs": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, unboundPVC2}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, unboundPVC2},
pvs: []*v1.PersistentVolume{pvNode1a, pvNode1b}, pvs: []*v1.PersistentVolume{pvNode1a, pvNode1b},
expectedBindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1a), makeBinding(unboundPVC2, pvNode1b)}, expectedBindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1a), makeBinding(unboundPVC2, pvNode1b)},
}, },
"two-unbound-pvcs,order-by-size": { "two-unbound-pvcs,order-by-size": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC2, unboundPVC}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC2, unboundPVC},
pvs: []*v1.PersistentVolume{pvNode1a, pvNode1b}, pvs: []*v1.PersistentVolume{pvNode1a, pvNode1b},
expectedBindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1a), makeBinding(unboundPVC2, pvNode1b)}, expectedBindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1a), makeBinding(unboundPVC2, pvNode1b)},
}, },
"two-unbound-pvcs,partial-match": { "two-unbound-pvcs,partial-match": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, unboundPVC2}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, unboundPVC2},
pvs: []*v1.PersistentVolume{pvNode1a}, pvs: []*v1.PersistentVolume{pvNode1a},
expectedBindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1a)}, expectedBindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1a)},
reasons: ConflictReasons{ErrReasonBindConflict}, reasons: ConflictReasons{ErrReasonBindConflict},
}, },
"one-bound,one-unbound": { "one-bound,one-unbound": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, boundPVC}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, boundPVC},
pvs: []*v1.PersistentVolume{pvBound, pvNode1a}, pvs: []*v1.PersistentVolume{pvBound, pvNode1a},
expectedBindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1a)}, expectedBindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1a)},
}, },
"one-bound,one-unbound,no-match": { "one-bound,one-unbound,no-match": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, boundPVC}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, boundPVC},
@ -920,7 +917,7 @@ func TestFindPodVolumesWithoutProvisioning(t *testing.T) {
} }
// Execute // Execute
reasons, err := findPodVolumes(testEnv.binder, scenario.pod, testNode) podVolumes, reasons, err := findPodVolumes(testEnv.binder, scenario.pod, testNode)
// Validate // Validate
if !scenario.shouldFail && err != nil { if !scenario.shouldFail && err != nil {
@ -930,7 +927,7 @@ func TestFindPodVolumesWithoutProvisioning(t *testing.T) {
t.Error("returned success but expected error") t.Error("returned success but expected error")
} }
checkReasons(t, reasons, scenario.reasons) checkReasons(t, reasons, scenario.reasons)
testEnv.validatePodCache(t, testNode.Name, scenario.pod, scenario.expectedBindings, nil) testEnv.validatePodCache(t, testNode.Name, scenario.pod, podVolumes, scenario.expectedBindings, nil)
} }
for name, scenario := range scenarios { for name, scenario := range scenarios {
@ -949,7 +946,7 @@ func TestFindPodVolumesWithProvisioning(t *testing.T) {
pod *v1.Pod pod *v1.Pod
// Expected podBindingCache fields // Expected podBindingCache fields
expectedBindings []*bindingInfo expectedBindings []*BindingInfo
expectedProvisions []*v1.PersistentVolumeClaim expectedProvisions []*v1.PersistentVolumeClaim
// Expected return values // Expected return values
@ -964,7 +961,7 @@ func TestFindPodVolumesWithProvisioning(t *testing.T) {
"two-unbound-pvcs,one-matched,one-provisioned": { "two-unbound-pvcs,one-matched,one-provisioned": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, provisionedPVC}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, provisionedPVC},
pvs: []*v1.PersistentVolume{pvNode1a}, pvs: []*v1.PersistentVolume{pvNode1a},
expectedBindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1a)}, expectedBindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1a)},
expectedProvisions: []*v1.PersistentVolumeClaim{provisionedPVC}, expectedProvisions: []*v1.PersistentVolumeClaim{provisionedPVC},
}, },
"one-bound,one-provisioned": { "one-bound,one-provisioned": {
@ -1025,7 +1022,7 @@ func TestFindPodVolumesWithProvisioning(t *testing.T) {
} }
// Execute // Execute
reasons, err := findPodVolumes(testEnv.binder, scenario.pod, testNode) podVolumes, reasons, err := findPodVolumes(testEnv.binder, scenario.pod, testNode)
// Validate // Validate
if !scenario.shouldFail && err != nil { if !scenario.shouldFail && err != nil {
@ -1035,7 +1032,7 @@ func TestFindPodVolumesWithProvisioning(t *testing.T) {
t.Error("returned success but expected error") t.Error("returned success but expected error")
} }
checkReasons(t, reasons, scenario.reasons) checkReasons(t, reasons, scenario.reasons)
testEnv.validatePodCache(t, testNode.Name, scenario.pod, scenario.expectedBindings, scenario.expectedProvisions) testEnv.validatePodCache(t, testNode.Name, scenario.pod, podVolumes, scenario.expectedBindings, scenario.expectedProvisions)
} }
for name, scenario := range scenarios { for name, scenario := range scenarios {
@ -1125,7 +1122,7 @@ func TestFindPodVolumesWithCSIMigration(t *testing.T) {
} }
// Execute // Execute
reasons, err := findPodVolumes(testEnv.binder, scenario.pod, node) _, reasons, err := findPodVolumes(testEnv.binder, scenario.pod, node)
// Validate // Validate
if !scenario.shouldFail && err != nil { if !scenario.shouldFail && err != nil {
@ -1147,14 +1144,14 @@ func TestAssumePodVolumes(t *testing.T) {
// Inputs // Inputs
podPVCs []*v1.PersistentVolumeClaim podPVCs []*v1.PersistentVolumeClaim
pvs []*v1.PersistentVolume pvs []*v1.PersistentVolume
bindings []*bindingInfo bindings []*BindingInfo
provisionedPVCs []*v1.PersistentVolumeClaim provisionedPVCs []*v1.PersistentVolumeClaim
// Expected return values // Expected return values
shouldFail bool shouldFail bool
expectedAllBound bool expectedAllBound bool
expectedBindings []*bindingInfo expectedBindings []*BindingInfo
expectedProvisionings []*v1.PersistentVolumeClaim expectedProvisionings []*v1.PersistentVolumeClaim
} }
scenarios := map[string]scenarioType{ scenarios := map[string]scenarioType{
@ -1165,42 +1162,42 @@ func TestAssumePodVolumes(t *testing.T) {
}, },
"one-binding": { "one-binding": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC},
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1a)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1a)},
pvs: []*v1.PersistentVolume{pvNode1a}, pvs: []*v1.PersistentVolume{pvNode1a},
expectedBindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, expectedBindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
expectedProvisionings: []*v1.PersistentVolumeClaim{}, expectedProvisionings: []*v1.PersistentVolumeClaim{},
}, },
"two-bindings": { "two-bindings": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, unboundPVC2}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, unboundPVC2},
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1a), makeBinding(unboundPVC2, pvNode1b)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1a), makeBinding(unboundPVC2, pvNode1b)},
pvs: []*v1.PersistentVolume{pvNode1a, pvNode1b}, pvs: []*v1.PersistentVolume{pvNode1a, pvNode1b},
expectedBindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound), makeBinding(unboundPVC2, pvNode1bBound)}, expectedBindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound), makeBinding(unboundPVC2, pvNode1bBound)},
expectedProvisionings: []*v1.PersistentVolumeClaim{}, expectedProvisionings: []*v1.PersistentVolumeClaim{},
}, },
"pv-already-bound": { "pv-already-bound": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC},
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
pvs: []*v1.PersistentVolume{pvNode1aBound}, pvs: []*v1.PersistentVolume{pvNode1aBound},
expectedBindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, expectedBindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
expectedProvisionings: []*v1.PersistentVolumeClaim{}, expectedProvisionings: []*v1.PersistentVolumeClaim{},
}, },
"tmpupdate-failed": { "tmpupdate-failed": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC},
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1a), makeBinding(unboundPVC2, pvNode1b)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1a), makeBinding(unboundPVC2, pvNode1b)},
pvs: []*v1.PersistentVolume{pvNode1a}, pvs: []*v1.PersistentVolume{pvNode1a},
shouldFail: true, shouldFail: true,
}, },
"one-binding, one-pvc-provisioned": { "one-binding, one-pvc-provisioned": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, provisionedPVC}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, provisionedPVC},
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1a)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1a)},
pvs: []*v1.PersistentVolume{pvNode1a}, pvs: []*v1.PersistentVolume{pvNode1a},
provisionedPVCs: []*v1.PersistentVolumeClaim{provisionedPVC}, provisionedPVCs: []*v1.PersistentVolumeClaim{provisionedPVC},
expectedBindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, expectedBindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
expectedProvisionings: []*v1.PersistentVolumeClaim{selectedNodePVC}, expectedProvisionings: []*v1.PersistentVolumeClaim{selectedNodePVC},
}, },
"one-binding, one-provision-tmpupdate-failed": { "one-binding, one-provision-tmpupdate-failed": {
podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, provisionedPVCHigherVersion}, podPVCs: []*v1.PersistentVolumeClaim{unboundPVC, provisionedPVCHigherVersion},
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1a)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1a)},
pvs: []*v1.PersistentVolume{pvNode1a}, pvs: []*v1.PersistentVolume{pvNode1a},
provisionedPVCs: []*v1.PersistentVolumeClaim{provisionedPVC2}, provisionedPVCs: []*v1.PersistentVolumeClaim{provisionedPVC2},
shouldFail: true, shouldFail: true,
@ -1215,11 +1212,14 @@ func TestAssumePodVolumes(t *testing.T) {
testEnv := newTestBinder(t, ctx.Done()) testEnv := newTestBinder(t, ctx.Done())
testEnv.initClaims(scenario.podPVCs, scenario.podPVCs) testEnv.initClaims(scenario.podPVCs, scenario.podPVCs)
pod := makePod(scenario.podPVCs) pod := makePod(scenario.podPVCs)
testEnv.initPodCache(pod, "node1", scenario.bindings, scenario.provisionedPVCs) podVolumes := &PodVolumes{
StaticBindings: scenario.bindings,
DynamicProvisions: scenario.provisionedPVCs,
}
testEnv.initVolumes(scenario.pvs, scenario.pvs) testEnv.initVolumes(scenario.pvs, scenario.pvs)
// Execute // Execute
allBound, err := testEnv.binder.AssumePodVolumes(pod, "node1") allBound, err := testEnv.binder.AssumePodVolumes(pod, "node1", podVolumes)
// Validate // Validate
if !scenario.shouldFail && err != nil { if !scenario.shouldFail && err != nil {
@ -1242,7 +1242,7 @@ func TestAssumePodVolumes(t *testing.T) {
} else { } else {
testEnv.validateAssume(t, pod, scenario.expectedBindings, scenario.expectedProvisionings) testEnv.validateAssume(t, pod, scenario.expectedBindings, scenario.expectedProvisionings)
} }
testEnv.validatePodCache(t, pod.Spec.NodeName, pod, scenario.expectedBindings, scenario.expectedProvisionings) testEnv.validatePodCache(t, pod.Spec.NodeName, pod, podVolumes, scenario.expectedBindings, scenario.expectedProvisionings)
} }
for name, scenario := range scenarios { for name, scenario := range scenarios {
@ -1255,33 +1255,36 @@ func TestRevertAssumedPodVolumes(t *testing.T) {
defer cancel() defer cancel()
podPVCs := []*v1.PersistentVolumeClaim{unboundPVC, provisionedPVC} podPVCs := []*v1.PersistentVolumeClaim{unboundPVC, provisionedPVC}
bindings := []*bindingInfo{makeBinding(unboundPVC, pvNode1a)} bindings := []*BindingInfo{makeBinding(unboundPVC, pvNode1a)}
pvs := []*v1.PersistentVolume{pvNode1a} pvs := []*v1.PersistentVolume{pvNode1a}
provisionedPVCs := []*v1.PersistentVolumeClaim{provisionedPVC} provisionedPVCs := []*v1.PersistentVolumeClaim{provisionedPVC}
expectedBindings := []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)} expectedBindings := []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)}
expectedProvisionings := []*v1.PersistentVolumeClaim{selectedNodePVC} expectedProvisionings := []*v1.PersistentVolumeClaim{selectedNodePVC}
// Setup // Setup
testEnv := newTestBinder(t, ctx.Done()) testEnv := newTestBinder(t, ctx.Done())
testEnv.initClaims(podPVCs, podPVCs) testEnv.initClaims(podPVCs, podPVCs)
pod := makePod(podPVCs) pod := makePod(podPVCs)
testEnv.initPodCache(pod, "node1", bindings, provisionedPVCs) podVolumes := &PodVolumes{
StaticBindings: bindings,
DynamicProvisions: provisionedPVCs,
}
testEnv.initVolumes(pvs, pvs) testEnv.initVolumes(pvs, pvs)
allbound, err := testEnv.binder.AssumePodVolumes(pod, "node1") allbound, err := testEnv.binder.AssumePodVolumes(pod, "node1", podVolumes)
if allbound || err != nil { if allbound || err != nil {
t.Errorf("No volumes are assumed") t.Errorf("No volumes are assumed")
} }
testEnv.validateAssume(t, pod, expectedBindings, expectedProvisionings) testEnv.validateAssume(t, pod, expectedBindings, expectedProvisionings)
testEnv.binder.RevertAssumedPodVolumes(pod, "node1") testEnv.binder.RevertAssumedPodVolumes(podVolumes)
testEnv.validateCacheRestored(t, pod, bindings, provisionedPVCs) testEnv.validateCacheRestored(t, pod, bindings, provisionedPVCs)
} }
func TestBindAPIUpdate(t *testing.T) { func TestBindAPIUpdate(t *testing.T) {
type scenarioType struct { type scenarioType struct {
// Inputs // Inputs
bindings []*bindingInfo bindings []*BindingInfo
cachedPVs []*v1.PersistentVolume cachedPVs []*v1.PersistentVolume
// if nil, use cachedPVs // if nil, use cachedPVs
apiPVs []*v1.PersistentVolume apiPVs []*v1.PersistentVolume
@ -1310,33 +1313,33 @@ func TestBindAPIUpdate(t *testing.T) {
shouldFail: true, shouldFail: true,
}, },
"nothing-to-bind-provisionings-nil": { "nothing-to-bind-provisionings-nil": {
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
shouldFail: true, shouldFail: true,
}, },
"nothing-to-bind-empty": { "nothing-to-bind-empty": {
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
}, },
"one-binding": { "one-binding": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
cachedPVs: []*v1.PersistentVolume{pvNode1a}, cachedPVs: []*v1.PersistentVolume{pvNode1a},
expectedPVs: []*v1.PersistentVolume{pvNode1aBound}, expectedPVs: []*v1.PersistentVolume{pvNode1aBound},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
}, },
"two-bindings": { "two-bindings": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound), makeBinding(unboundPVC2, pvNode1bBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound), makeBinding(unboundPVC2, pvNode1bBound)},
cachedPVs: []*v1.PersistentVolume{pvNode1a, pvNode1b}, cachedPVs: []*v1.PersistentVolume{pvNode1a, pvNode1b},
expectedPVs: []*v1.PersistentVolume{pvNode1aBound, pvNode1bBound}, expectedPVs: []*v1.PersistentVolume{pvNode1aBound, pvNode1bBound},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
}, },
"api-already-updated": { "api-already-updated": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
cachedPVs: []*v1.PersistentVolume{pvNode1aBound}, cachedPVs: []*v1.PersistentVolume{pvNode1aBound},
expectedPVs: []*v1.PersistentVolume{pvNode1aBound}, expectedPVs: []*v1.PersistentVolume{pvNode1aBound},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
}, },
"api-update-failed": { "api-update-failed": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound), makeBinding(unboundPVC2, pvNode1bBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound), makeBinding(unboundPVC2, pvNode1bBound)},
cachedPVs: []*v1.PersistentVolume{pvNode1a, pvNode1b}, cachedPVs: []*v1.PersistentVolume{pvNode1a, pvNode1b},
apiPVs: []*v1.PersistentVolume{pvNode1a, pvNode1bBoundHigherVersion}, apiPVs: []*v1.PersistentVolume{pvNode1a, pvNode1bBoundHigherVersion},
expectedPVs: []*v1.PersistentVolume{pvNode1aBound, pvNode1b}, expectedPVs: []*v1.PersistentVolume{pvNode1aBound, pvNode1b},
@ -1345,13 +1348,13 @@ func TestBindAPIUpdate(t *testing.T) {
shouldFail: true, shouldFail: true,
}, },
"one-provisioned-pvc": { "one-provisioned-pvc": {
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)}, provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)},
cachedPVCs: []*v1.PersistentVolumeClaim{provisionedPVC}, cachedPVCs: []*v1.PersistentVolumeClaim{provisionedPVC},
expectedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)}, expectedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)},
}, },
"provision-api-update-failed": { "provision-api-update-failed": {
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC), addProvisionAnn(provisionedPVC2)}, provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC), addProvisionAnn(provisionedPVC2)},
cachedPVCs: []*v1.PersistentVolumeClaim{provisionedPVC, provisionedPVC2}, cachedPVCs: []*v1.PersistentVolumeClaim{provisionedPVC, provisionedPVC2},
apiPVCs: []*v1.PersistentVolumeClaim{provisionedPVC, provisionedPVCHigherVersion}, apiPVCs: []*v1.PersistentVolumeClaim{provisionedPVC, provisionedPVCHigherVersion},
@ -1360,7 +1363,7 @@ func TestBindAPIUpdate(t *testing.T) {
shouldFail: true, shouldFail: true,
}, },
"binding-succeed, provision-api-update-failed": { "binding-succeed, provision-api-update-failed": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
cachedPVs: []*v1.PersistentVolume{pvNode1a}, cachedPVs: []*v1.PersistentVolume{pvNode1a},
expectedPVs: []*v1.PersistentVolume{pvNode1aBound}, expectedPVs: []*v1.PersistentVolume{pvNode1aBound},
provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC), addProvisionAnn(provisionedPVC2)}, provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC), addProvisionAnn(provisionedPVC2)},
@ -1420,7 +1423,7 @@ func TestCheckBindings(t *testing.T) {
initPVs []*v1.PersistentVolume initPVs []*v1.PersistentVolume
initPVCs []*v1.PersistentVolumeClaim initPVCs []*v1.PersistentVolumeClaim
bindings []*bindingInfo bindings []*BindingInfo
provisionedPVCs []*v1.PersistentVolumeClaim provisionedPVCs []*v1.PersistentVolumeClaim
// api updates before checking // api updates before checking
@ -1444,41 +1447,41 @@ func TestCheckBindings(t *testing.T) {
shouldFail: true, shouldFail: true,
}, },
"nothing-to-bind-provisionings-nil": { "nothing-to-bind-provisionings-nil": {
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
shouldFail: true, shouldFail: true,
}, },
"nothing-to-bind": { "nothing-to-bind": {
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
expectedBound: true, expectedBound: true,
}, },
"binding-bound": { "binding-bound": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{pvNode1aBound}, initPVs: []*v1.PersistentVolume{pvNode1aBound},
initPVCs: []*v1.PersistentVolumeClaim{boundPVCNode1a}, initPVCs: []*v1.PersistentVolumeClaim{boundPVCNode1a},
expectedBound: true, expectedBound: true,
}, },
"binding-prebound": { "binding-prebound": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{pvNode1aBound}, initPVs: []*v1.PersistentVolume{pvNode1aBound},
initPVCs: []*v1.PersistentVolumeClaim{preboundPVCNode1a}, initPVCs: []*v1.PersistentVolumeClaim{preboundPVCNode1a},
}, },
"binding-unbound": { "binding-unbound": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{pvNode1aBound}, initPVs: []*v1.PersistentVolume{pvNode1aBound},
initPVCs: []*v1.PersistentVolumeClaim{unboundPVC}, initPVCs: []*v1.PersistentVolumeClaim{unboundPVC},
}, },
"binding-pvc-not-exists": { "binding-pvc-not-exists": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{pvNode1aBound}, initPVs: []*v1.PersistentVolume{pvNode1aBound},
shouldFail: true, shouldFail: true,
}, },
"binding-pv-not-exists": { "binding-pv-not-exists": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{pvNode1aBound}, initPVs: []*v1.PersistentVolume{pvNode1aBound},
initPVCs: []*v1.PersistentVolumeClaim{boundPVCNode1a}, initPVCs: []*v1.PersistentVolumeClaim{boundPVCNode1a},
@ -1486,7 +1489,7 @@ func TestCheckBindings(t *testing.T) {
shouldFail: true, shouldFail: true,
}, },
"binding-claimref-nil": { "binding-claimref-nil": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{pvNode1a}, initPVs: []*v1.PersistentVolume{pvNode1a},
initPVCs: []*v1.PersistentVolumeClaim{boundPVCNode1a}, initPVCs: []*v1.PersistentVolumeClaim{boundPVCNode1a},
@ -1495,7 +1498,7 @@ func TestCheckBindings(t *testing.T) {
shouldFail: true, shouldFail: true,
}, },
"binding-claimref-uid-empty": { "binding-claimref-uid-empty": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{pvNode1aBound}, initPVs: []*v1.PersistentVolume{pvNode1aBound},
initPVCs: []*v1.PersistentVolumeClaim{boundPVCNode1a}, initPVCs: []*v1.PersistentVolumeClaim{boundPVCNode1a},
@ -1504,13 +1507,13 @@ func TestCheckBindings(t *testing.T) {
shouldFail: true, shouldFail: true,
}, },
"binding-one-bound,one-unbound": { "binding-one-bound,one-unbound": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound), makeBinding(unboundPVC2, pvNode1bBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound), makeBinding(unboundPVC2, pvNode1bBound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{pvNode1aBound, pvNode1bBound}, initPVs: []*v1.PersistentVolume{pvNode1aBound, pvNode1bBound},
initPVCs: []*v1.PersistentVolumeClaim{boundPVCNode1a, unboundPVC2}, initPVCs: []*v1.PersistentVolumeClaim{boundPVCNode1a, unboundPVC2},
}, },
"provisioning-pvc-bound": { "provisioning-pvc-bound": {
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)}, provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)},
initPVs: []*v1.PersistentVolume{pvBound}, initPVs: []*v1.PersistentVolume{pvBound},
initPVCs: []*v1.PersistentVolumeClaim{provisionedPVCBound}, initPVCs: []*v1.PersistentVolumeClaim{provisionedPVCBound},
@ -1518,26 +1521,26 @@ func TestCheckBindings(t *testing.T) {
expectedBound: true, expectedBound: true,
}, },
"provisioning-pvc-unbound": { "provisioning-pvc-unbound": {
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)}, provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)},
initPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)}, initPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)},
}, },
"provisioning-pvc-not-exists": { "provisioning-pvc-not-exists": {
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)}, provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)},
initPVCs: []*v1.PersistentVolumeClaim{provisionedPVC}, initPVCs: []*v1.PersistentVolumeClaim{provisionedPVC},
deletePVCs: true, deletePVCs: true,
shouldFail: true, shouldFail: true,
}, },
"provisioning-pvc-annotations-nil": { "provisioning-pvc-annotations-nil": {
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)}, provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)},
initPVCs: []*v1.PersistentVolumeClaim{provisionedPVC}, initPVCs: []*v1.PersistentVolumeClaim{provisionedPVC},
apiPVCs: []*v1.PersistentVolumeClaim{provisionedPVC}, apiPVCs: []*v1.PersistentVolumeClaim{provisionedPVC},
shouldFail: true, shouldFail: true,
}, },
"provisioning-pvc-selected-node-dropped": { "provisioning-pvc-selected-node-dropped": {
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)}, provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)},
initPVCs: []*v1.PersistentVolumeClaim{provisionedPVC}, initPVCs: []*v1.PersistentVolumeClaim{provisionedPVC},
apiPVCs: []*v1.PersistentVolumeClaim{pvcSetEmptyAnnotations(provisionedPVC)}, apiPVCs: []*v1.PersistentVolumeClaim{pvcSetEmptyAnnotations(provisionedPVC)},
@ -1545,13 +1548,13 @@ func TestCheckBindings(t *testing.T) {
}, },
"provisioning-pvc-selected-node-wrong-node": { "provisioning-pvc-selected-node-wrong-node": {
initPVCs: []*v1.PersistentVolumeClaim{provisionedPVC}, initPVCs: []*v1.PersistentVolumeClaim{provisionedPVC},
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)}, provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)},
apiPVCs: []*v1.PersistentVolumeClaim{pvcSetSelectedNode(provisionedPVC, "wrong-node")}, apiPVCs: []*v1.PersistentVolumeClaim{pvcSetSelectedNode(provisionedPVC, "wrong-node")},
shouldFail: true, shouldFail: true,
}, },
"binding-bound-provisioning-unbound": { "binding-bound-provisioning-unbound": {
bindings: []*bindingInfo{makeBinding(unboundPVC, pvNode1aBound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, pvNode1aBound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)}, provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)},
initPVs: []*v1.PersistentVolume{pvNode1aBound}, initPVs: []*v1.PersistentVolume{pvNode1aBound},
initPVCs: []*v1.PersistentVolumeClaim{boundPVCNode1a, addProvisionAnn(provisionedPVC)}, initPVCs: []*v1.PersistentVolumeClaim{boundPVCNode1a, addProvisionAnn(provisionedPVC)},
@ -1559,7 +1562,7 @@ func TestCheckBindings(t *testing.T) {
"tolerate-provisioning-pvc-bound-pv-not-found": { "tolerate-provisioning-pvc-bound-pv-not-found": {
initPVs: []*v1.PersistentVolume{pvNode1a}, initPVs: []*v1.PersistentVolume{pvNode1a},
initPVCs: []*v1.PersistentVolumeClaim{provisionedPVC}, initPVCs: []*v1.PersistentVolumeClaim{provisionedPVC},
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)}, provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVC)},
apiPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVCBound)}, apiPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provisionedPVCBound)},
deletePVs: true, deletePVs: true,
@ -1573,6 +1576,7 @@ func TestCheckBindings(t *testing.T) {
// Setup // Setup
pod := makePod(nil) pod := makePod(nil)
testEnv := newTestBinder(t, ctx.Done()) testEnv := newTestBinder(t, ctx.Done())
testEnv.internalPodInformer.Informer().GetIndexer().Add(pod)
testEnv.initNodes([]*v1.Node{node1}) testEnv.initNodes([]*v1.Node{node1})
testEnv.initVolumes(scenario.initPVs, nil) testEnv.initVolumes(scenario.initPVs, nil)
testEnv.initClaims(scenario.initPVCs, nil) testEnv.initClaims(scenario.initPVCs, nil)
@ -1618,7 +1622,7 @@ func TestCheckBindingsWithCSIMigration(t *testing.T) {
initNodes []*v1.Node initNodes []*v1.Node
initCSINodes []*storagev1.CSINode initCSINodes []*storagev1.CSINode
bindings []*bindingInfo bindings []*BindingInfo
provisionedPVCs []*v1.PersistentVolumeClaim provisionedPVCs []*v1.PersistentVolumeClaim
// API updates before checking // API updates before checking
@ -1632,7 +1636,7 @@ func TestCheckBindingsWithCSIMigration(t *testing.T) {
} }
scenarios := map[string]scenarioType{ scenarios := map[string]scenarioType{
"provisioning-pvc-bound": { "provisioning-pvc-bound": {
bindings: []*bindingInfo{}, bindings: []*BindingInfo{},
provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provMigrationPVCBound)}, provisionedPVCs: []*v1.PersistentVolumeClaim{addProvisionAnn(provMigrationPVCBound)},
initPVs: []*v1.PersistentVolume{migrationPVBound}, initPVs: []*v1.PersistentVolume{migrationPVBound},
initPVCs: []*v1.PersistentVolumeClaim{provMigrationPVCBound}, initPVCs: []*v1.PersistentVolumeClaim{provMigrationPVCBound},
@ -1642,7 +1646,7 @@ func TestCheckBindingsWithCSIMigration(t *testing.T) {
expectedBound: true, expectedBound: true,
}, },
"binding-node-pv-same-zone": { "binding-node-pv-same-zone": {
bindings: []*bindingInfo{makeBinding(unboundPVC, migrationPVBoundToUnbound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, migrationPVBoundToUnbound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{migrationPVBoundToUnbound}, initPVs: []*v1.PersistentVolume{migrationPVBoundToUnbound},
initPVCs: []*v1.PersistentVolumeClaim{unboundPVC}, initPVCs: []*v1.PersistentVolumeClaim{unboundPVC},
@ -1651,7 +1655,7 @@ func TestCheckBindingsWithCSIMigration(t *testing.T) {
migrationEnabled: true, migrationEnabled: true,
}, },
"binding-without-csinode": { "binding-without-csinode": {
bindings: []*bindingInfo{makeBinding(unboundPVC, migrationPVBoundToUnbound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, migrationPVBoundToUnbound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{migrationPVBoundToUnbound}, initPVs: []*v1.PersistentVolume{migrationPVBoundToUnbound},
initPVCs: []*v1.PersistentVolumeClaim{unboundPVC}, initPVCs: []*v1.PersistentVolumeClaim{unboundPVC},
@ -1660,7 +1664,7 @@ func TestCheckBindingsWithCSIMigration(t *testing.T) {
migrationEnabled: true, migrationEnabled: true,
}, },
"binding-non-migrated-plugin": { "binding-non-migrated-plugin": {
bindings: []*bindingInfo{makeBinding(unboundPVC, migrationPVBoundToUnbound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, migrationPVBoundToUnbound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{migrationPVBoundToUnbound}, initPVs: []*v1.PersistentVolume{migrationPVBoundToUnbound},
initPVCs: []*v1.PersistentVolumeClaim{unboundPVC}, initPVCs: []*v1.PersistentVolumeClaim{unboundPVC},
@ -1669,7 +1673,7 @@ func TestCheckBindingsWithCSIMigration(t *testing.T) {
migrationEnabled: true, migrationEnabled: true,
}, },
"binding-node-pv-in-different-zones": { "binding-node-pv-in-different-zones": {
bindings: []*bindingInfo{makeBinding(unboundPVC, migrationPVBoundToUnbound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, migrationPVBoundToUnbound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{migrationPVBoundToUnbound}, initPVs: []*v1.PersistentVolume{migrationPVBoundToUnbound},
initPVCs: []*v1.PersistentVolumeClaim{unboundPVC}, initPVCs: []*v1.PersistentVolumeClaim{unboundPVC},
@ -1679,7 +1683,7 @@ func TestCheckBindingsWithCSIMigration(t *testing.T) {
shouldFail: true, shouldFail: true,
}, },
"binding-node-pv-different-zones-migration-off": { "binding-node-pv-different-zones-migration-off": {
bindings: []*bindingInfo{makeBinding(unboundPVC, migrationPVBoundToUnbound)}, bindings: []*BindingInfo{makeBinding(unboundPVC, migrationPVBoundToUnbound)},
provisionedPVCs: []*v1.PersistentVolumeClaim{}, provisionedPVCs: []*v1.PersistentVolumeClaim{},
initPVs: []*v1.PersistentVolume{migrationPVBoundToUnbound}, initPVs: []*v1.PersistentVolume{migrationPVBoundToUnbound},
initPVCs: []*v1.PersistentVolumeClaim{unboundPVC}, initPVCs: []*v1.PersistentVolumeClaim{unboundPVC},
@ -1699,6 +1703,7 @@ func TestCheckBindingsWithCSIMigration(t *testing.T) {
// Setup // Setup
pod := makePod(nil) pod := makePod(nil)
testEnv := newTestBinder(t, ctx.Done()) testEnv := newTestBinder(t, ctx.Done())
testEnv.internalPodInformer.Informer().GetIndexer().Add(pod)
testEnv.initNodes(scenario.initNodes) testEnv.initNodes(scenario.initNodes)
testEnv.initCSINodes(scenario.initCSINodes) testEnv.initCSINodes(scenario.initCSINodes)
testEnv.initVolumes(scenario.initPVs, nil) testEnv.initVolumes(scenario.initPVs, nil)
@ -1741,7 +1746,7 @@ func TestBindPodVolumes(t *testing.T) {
initPVCs []*v1.PersistentVolumeClaim initPVCs []*v1.PersistentVolumeClaim
// assume PV & PVC with these binding results // assume PV & PVC with these binding results
binding *bindingInfo binding *BindingInfo
claimToProvision *v1.PersistentVolumeClaim claimToProvision *v1.PersistentVolumeClaim
// API updates after assume before bind // API updates after assume before bind
@ -1819,19 +1824,7 @@ func TestBindPodVolumes(t *testing.T) {
initPVs: []*v1.PersistentVolume{pvNode1a}, initPVs: []*v1.PersistentVolume{pvNode1a},
initPVCs: []*v1.PersistentVolumeClaim{unboundPVC}, initPVCs: []*v1.PersistentVolumeClaim{unboundPVC},
delayFunc: func(t *testing.T, testEnv *testEnv, pod *v1.Pod, pvs []*v1.PersistentVolume, pvcs []*v1.PersistentVolumeClaim) { delayFunc: func(t *testing.T, testEnv *testEnv, pod *v1.Pod, pvs []*v1.PersistentVolume, pvcs []*v1.PersistentVolumeClaim) {
bindingsCache := testEnv.binder.GetBindingsCache() testEnv.client.CoreV1().Pods(pod.Namespace).Delete(context.Background(), pod.Name, metav1.DeleteOptions{})
if bindingsCache == nil {
t.Fatalf("Failed to get bindings cache")
}
// Delete the pod from the cache
bindingsCache.DeleteBindings(pod)
// Check that it's deleted
bindings := bindingsCache.GetBindings(pod, "node1")
if bindings != nil {
t.Fatalf("Failed to delete bindings")
}
}, },
shouldFail: true, shouldFail: true,
}, },
@ -1892,15 +1885,16 @@ func TestBindPodVolumes(t *testing.T) {
// Setup // Setup
pod := makePod(nil) pod := makePod(nil)
testEnv := newTestBinder(t, ctx.Done()) testEnv := newTestBinder(t, ctx.Done())
testEnv.internalPodInformer.Informer().GetIndexer().Add(pod)
if scenario.nodes == nil { if scenario.nodes == nil {
scenario.nodes = []*v1.Node{node1} scenario.nodes = []*v1.Node{node1}
} }
bindings := []*BindingInfo{}
claimsToProvision := []*v1.PersistentVolumeClaim{}
if !scenario.bindingsNil { if !scenario.bindingsNil {
bindings := []*bindingInfo{}
if scenario.binding != nil { if scenario.binding != nil {
bindings = []*bindingInfo{scenario.binding} bindings = []*BindingInfo{scenario.binding}
} }
claimsToProvision := []*v1.PersistentVolumeClaim{}
if scenario.claimToProvision != nil { if scenario.claimToProvision != nil {
claimsToProvision = []*v1.PersistentVolumeClaim{scenario.claimToProvision} claimsToProvision = []*v1.PersistentVolumeClaim{scenario.claimToProvision}
} }
@ -1934,7 +1928,11 @@ func TestBindPodVolumes(t *testing.T) {
} }
// Execute // Execute
err := testEnv.binder.BindPodVolumes(pod) podVolumes := &PodVolumes{
StaticBindings: bindings,
DynamicProvisions: claimsToProvision,
}
err := testEnv.binder.BindPodVolumes(pod, podVolumes)
// Validate // Validate
if !scenario.shouldFail && err != nil { if !scenario.shouldFail && err != nil {
@ -1974,17 +1972,17 @@ func TestFindAssumeVolumes(t *testing.T) {
// Execute // Execute
// 1. Find matching PVs // 1. Find matching PVs
reasons, err := findPodVolumes(testEnv.binder, pod, testNode) podVolumes, reasons, err := findPodVolumes(testEnv.binder, pod, testNode)
if err != nil { if err != nil {
t.Errorf("Test failed: FindPodVolumes returned error: %v", err) t.Errorf("Test failed: FindPodVolumes returned error: %v", err)
} }
if len(reasons) > 0 { if len(reasons) > 0 {
t.Errorf("Test failed: couldn't find PVs for all PVCs: %v", reasons) t.Errorf("Test failed: couldn't find PVs for all PVCs: %v", reasons)
} }
expectedBindings := testEnv.getPodBindings(t, testNode.Name, pod) expectedBindings := podVolumes.StaticBindings
// 2. Assume matches // 2. Assume matches
allBound, err := testEnv.binder.AssumePodVolumes(pod, testNode.Name) allBound, err := testEnv.binder.AssumePodVolumes(pod, testNode.Name, podVolumes)
if err != nil { if err != nil {
t.Errorf("Test failed: AssumePodVolumes returned error: %v", err) t.Errorf("Test failed: AssumePodVolumes returned error: %v", err)
} }
@ -1994,19 +1992,19 @@ func TestFindAssumeVolumes(t *testing.T) {
testEnv.validateAssume(t, pod, expectedBindings, nil) testEnv.validateAssume(t, pod, expectedBindings, nil)
// After assume, claimref should be set on pv // After assume, claimref should be set on pv
expectedBindings = testEnv.getPodBindings(t, testNode.Name, pod) expectedBindings = podVolumes.StaticBindings
// 3. Find matching PVs again // 3. Find matching PVs again
// This should always return the original chosen pv // This should always return the original chosen pv
// Run this many times in case sorting returns different orders for the two PVs. // Run this many times in case sorting returns different orders for the two PVs.
for i := 0; i < 50; i++ { for i := 0; i < 50; i++ {
reasons, err := findPodVolumes(testEnv.binder, pod, testNode) podVolumes, reasons, err := findPodVolumes(testEnv.binder, pod, testNode)
if err != nil { if err != nil {
t.Errorf("Test failed: FindPodVolumes returned error: %v", err) t.Errorf("Test failed: FindPodVolumes returned error: %v", err)
} }
if len(reasons) > 0 { if len(reasons) > 0 {
t.Errorf("Test failed: couldn't find PVs for all PVCs: %v", reasons) t.Errorf("Test failed: couldn't find PVs for all PVCs: %v", reasons)
} }
testEnv.validatePodCache(t, testNode.Name, pod, expectedBindings, nil) testEnv.validatePodCache(t, testNode.Name, pod, podVolumes, expectedBindings, nil)
} }
} }

View File

@ -127,11 +127,6 @@ func TestClusterAutoscalerProvider(t *testing.T) {
{Name: defaultbinder.Name}, {Name: defaultbinder.Name},
}, },
}, },
PostBind: &schedulerapi.PluginSet{
Enabled: []schedulerapi.Plugin{
{Name: volumebinding.Name},
},
},
} }
r := NewRegistry() r := NewRegistry()
@ -229,11 +224,6 @@ func TestApplyFeatureGates(t *testing.T) {
{Name: defaultbinder.Name}, {Name: defaultbinder.Name},
}, },
}, },
PostBind: &schedulerapi.PluginSet{
Enabled: []schedulerapi.Plugin{
{Name: volumebinding.Name},
},
},
}, },
}, },
{ {
@ -317,11 +307,6 @@ func TestApplyFeatureGates(t *testing.T) {
{Name: defaultbinder.Name}, {Name: defaultbinder.Name},
}, },
}, },
PostBind: &schedulerapi.PluginSet{
Enabled: []schedulerapi.Plugin{
{Name: volumebinding.Name},
},
},
}, },
}, },
} }

View File

@ -706,7 +706,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"ReservePlugin": {{Name: "VolumeBinding"}}, "ReservePlugin": {{Name: "VolumeBinding"}},
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
wantExtenders: []config.Extender{{ wantExtenders: []config.Extender{{
URLPrefix: "/prefix", URLPrefix: "/prefix",
@ -814,7 +813,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"ReservePlugin": {{Name: "VolumeBinding"}}, "ReservePlugin": {{Name: "VolumeBinding"}},
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
wantExtenders: []config.Extender{{ wantExtenders: []config.Extender{{
URLPrefix: "/prefix", URLPrefix: "/prefix",
@ -935,7 +933,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"ReservePlugin": {{Name: "VolumeBinding"}}, "ReservePlugin": {{Name: "VolumeBinding"}},
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
wantExtenders: []config.Extender{{ wantExtenders: []config.Extender{{
URLPrefix: "/prefix", URLPrefix: "/prefix",
@ -1058,7 +1055,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"ReservePlugin": {{Name: "VolumeBinding"}}, "ReservePlugin": {{Name: "VolumeBinding"}},
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
wantExtenders: []config.Extender{{ wantExtenders: []config.Extender{{
URLPrefix: "/prefix", URLPrefix: "/prefix",
@ -1181,7 +1177,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"ReservePlugin": {{Name: "VolumeBinding"}}, "ReservePlugin": {{Name: "VolumeBinding"}},
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
wantExtenders: []config.Extender{{ wantExtenders: []config.Extender{{
URLPrefix: "/prefix", URLPrefix: "/prefix",
@ -1308,7 +1303,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"ReservePlugin": {{Name: "VolumeBinding"}}, "ReservePlugin": {{Name: "VolumeBinding"}},
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
wantExtenders: []config.Extender{{ wantExtenders: []config.Extender{{
URLPrefix: "/prefix", URLPrefix: "/prefix",
@ -1438,7 +1432,6 @@ func TestAlgorithmProviderCompatibility(t *testing.T) {
"ReservePlugin": {{Name: "VolumeBinding"}}, "ReservePlugin": {{Name: "VolumeBinding"}},
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
} }
testcases := []struct { testcases := []struct {
@ -1510,7 +1503,6 @@ func TestAlgorithmProviderCompatibility(t *testing.T) {
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"BindPlugin": {{Name: "DefaultBinder"}}, "BindPlugin": {{Name: "DefaultBinder"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
}, },
} }
@ -1602,7 +1594,6 @@ func TestPluginsConfigurationCompatibility(t *testing.T) {
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"BindPlugin": {{Name: "DefaultBinder"}}, "BindPlugin": {{Name: "DefaultBinder"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
} }
testcases := []struct { testcases := []struct {
@ -1953,7 +1944,6 @@ func TestPluginsConfigurationCompatibility(t *testing.T) {
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"BindPlugin": {{Name: "DefaultBinder"}}, "BindPlugin": {{Name: "DefaultBinder"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
wantPluginConfig: nil, wantPluginConfig: nil,
}, },

View File

@ -134,7 +134,8 @@ func TestVolumeBinding(t *testing.T) {
boundClaims: []*v1.PersistentVolumeClaim{ boundClaims: []*v1.PersistentVolumeClaim{
makePVC("pvc-a", "pv-a", waitSC.Name), makePVC("pvc-a", "pv-a", waitSC.Name),
}, },
claimsToBind: []*v1.PersistentVolumeClaim{}, claimsToBind: []*v1.PersistentVolumeClaim{},
podVolumesByNode: map[string]*scheduling.PodVolumes{},
}, },
}, },
{ {
@ -158,6 +159,7 @@ func TestVolumeBinding(t *testing.T) {
claimsToBind: []*v1.PersistentVolumeClaim{ claimsToBind: []*v1.PersistentVolumeClaim{
makePVC("pvc-a", "", waitSC.Name), makePVC("pvc-a", "", waitSC.Name),
}, },
podVolumesByNode: map[string]*scheduling.PodVolumes{},
}, },
wantFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, string(scheduling.ErrReasonBindConflict)), wantFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, string(scheduling.ErrReasonBindConflict)),
}, },
@ -199,6 +201,7 @@ func TestVolumeBinding(t *testing.T) {
claimsToBind: []*v1.PersistentVolumeClaim{ claimsToBind: []*v1.PersistentVolumeClaim{
makePVC("pvc-b", "", waitSC.Name), makePVC("pvc-b", "", waitSC.Name),
}, },
podVolumesByNode: map[string]*scheduling.PodVolumes{},
}, },
wantFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, string(scheduling.ErrReasonNodeConflict), string(scheduling.ErrReasonBindConflict)), wantFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, string(scheduling.ErrReasonNodeConflict), string(scheduling.ErrReasonBindConflict)),
}, },
@ -221,7 +224,8 @@ func TestVolumeBinding(t *testing.T) {
boundClaims: []*v1.PersistentVolumeClaim{ boundClaims: []*v1.PersistentVolumeClaim{
makePVC("pvc-a", "pv-a", waitSC.Name), makePVC("pvc-a", "pv-a", waitSC.Name),
}, },
claimsToBind: []*v1.PersistentVolumeClaim{}, claimsToBind: []*v1.PersistentVolumeClaim{},
podVolumesByNode: map[string]*scheduling.PodVolumes{},
}, },
wantFilterStatus: framework.NewStatus(framework.Error, `could not find v1.PersistentVolume "pv-a"`), wantFilterStatus: framework.NewStatus(framework.Error, `could not find v1.PersistentVolume "pv-a"`),
}, },
@ -229,7 +233,8 @@ func TestVolumeBinding(t *testing.T) {
for _, item := range table { for _, item := range table {
t.Run(item.name, func(t *testing.T) { t.Run(item.name, func(t *testing.T) {
ctx := context.Background() ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client := fake.NewSimpleClientset() client := fake.NewSimpleClientset()
informerFactory := informers.NewSharedInformerFactory(client, 0) informerFactory := informers.NewSharedInformerFactory(client, 0)
opts := []runtime.Option{ opts := []runtime.Option{
@ -256,15 +261,11 @@ func TestVolumeBinding(t *testing.T) {
if item.node != nil { if item.node != nil {
client.CoreV1().Nodes().Create(ctx, item.node, metav1.CreateOptions{}) client.CoreV1().Nodes().Create(ctx, item.node, metav1.CreateOptions{})
} }
if len(item.pvcs) > 0 { for _, pvc := range item.pvcs {
for _, pvc := range item.pvcs { client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(ctx, pvc, metav1.CreateOptions{})
client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(ctx, pvc, metav1.CreateOptions{})
}
} }
if len(item.pvs) > 0 { for _, pv := range item.pvs {
for _, pv := range item.pvs { client.CoreV1().PersistentVolumes().Create(ctx, pv, metav1.CreateOptions{})
client.CoreV1().PersistentVolumes().Create(ctx, pv, metav1.CreateOptions{})
}
} }
caches := informerFactory.WaitForCacheSync(ctx.Done()) caches := informerFactory.WaitForCacheSync(ctx.Done())
for _, synced := range caches { for _, synced := range caches {

View File

@ -826,7 +826,7 @@ func setupTestSchedulerWithVolumeBinding(volumeBinder scheduling.SchedulerVolume
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
st.RegisterPluginAsExtensions(volumebinding.Name, func(plArgs runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { st.RegisterPluginAsExtensions(volumebinding.Name, func(plArgs runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
return &volumebinding.VolumeBinding{Binder: volumeBinder}, nil return &volumebinding.VolumeBinding{Binder: volumeBinder}, nil
}, "PreFilter", "Filter", "Reserve", "Unreserve", "PreBind", "PostBind"), }, "PreFilter", "Filter", "Reserve", "Unreserve", "PreBind"),
} }
s, bindingChan, errChan := setupTestScheduler(queuedPodStore, scache, informerFactory, broadcaster, fns...) s, bindingChan, errChan := setupTestScheduler(queuedPodStore, scache, informerFactory, broadcaster, fns...)
informerFactory.Start(stop) informerFactory.Start(stop)

View File

@ -148,7 +148,6 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"BindPlugin": {{Name: "DefaultBinder"}}, "BindPlugin": {{Name: "DefaultBinder"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
}, },
{ {
@ -243,7 +242,6 @@ kind: Policy
"UnreservePlugin": {{Name: "VolumeBinding"}}, "UnreservePlugin": {{Name: "VolumeBinding"}},
"PreBindPlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}},
"BindPlugin": {{Name: "DefaultBinder"}}, "BindPlugin": {{Name: "DefaultBinder"}},
"PostBindPlugin": {{Name: "VolumeBinding"}},
}, },
}, },
{ {