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