@@ -465,13 +465,14 @@ func (env *testEnv) validateAssume(t *testing.T, pod *v1.Pod, bindings []*bindin
465
465
}
466
466
}
467
467
468
- func (env * testEnv ) validateFailedAssume (t * testing.T , pod * v1.Pod , bindings []* bindingInfo , provisionings []* v1.PersistentVolumeClaim ) {
468
+ func (env * testEnv ) validateCacheRestored (t * testing.T , pod * v1.Pod , bindings []* bindingInfo , provisionings []* v1.PersistentVolumeClaim ) {
469
469
// All PVs have been unmodified in cache
470
470
pvCache := env .internalBinder .pvCache
471
471
for _ , b := range bindings {
472
472
pv , _ := pvCache .GetPV (b .pv .Name )
473
+ apiPV , _ := pvCache .GetAPIPV (b .pv .Name )
473
474
// PV could be nil if it's missing from cache
474
- if pv != nil && pv != b . pv {
475
+ if pv != nil && pv != apiPV {
475
476
t .Errorf ("PV %q was modified in cache" , b .pv .Name )
476
477
}
477
478
}
@@ -1237,7 +1238,7 @@ func TestAssumePodVolumes(t *testing.T) {
1237
1238
scenario .expectedProvisionings = scenario .provisionedPVCs
1238
1239
}
1239
1240
if scenario .shouldFail {
1240
- testEnv .validateFailedAssume (t , pod , scenario .expectedBindings , scenario .expectedProvisionings )
1241
+ testEnv .validateCacheRestored (t , pod , scenario .bindings , scenario .provisionedPVCs )
1241
1242
} else {
1242
1243
testEnv .validateAssume (t , pod , scenario .expectedBindings , scenario .expectedProvisionings )
1243
1244
}
@@ -1249,6 +1250,34 @@ func TestAssumePodVolumes(t *testing.T) {
1249
1250
}
1250
1251
}
1251
1252
1253
+ func TestRevertAssumedPodVolumes (t * testing.T ) {
1254
+ ctx , cancel := context .WithCancel (context .Background ())
1255
+ defer cancel ()
1256
+
1257
+ podPVCs := []* v1.PersistentVolumeClaim {unboundPVC , provisionedPVC }
1258
+ bindings := []* bindingInfo {makeBinding (unboundPVC , pvNode1a )}
1259
+ pvs := []* v1.PersistentVolume {pvNode1a }
1260
+ provisionedPVCs := []* v1.PersistentVolumeClaim {provisionedPVC }
1261
+ expectedBindings := []* bindingInfo {makeBinding (unboundPVC , pvNode1aBound )}
1262
+ expectedProvisionings := []* v1.PersistentVolumeClaim {selectedNodePVC }
1263
+
1264
+ // Setup
1265
+ testEnv := newTestBinder (t , ctx .Done ())
1266
+ testEnv .initClaims (podPVCs , podPVCs )
1267
+ pod := makePod (podPVCs )
1268
+ testEnv .initPodCache (pod , "node1" , bindings , provisionedPVCs )
1269
+ testEnv .initVolumes (pvs , pvs )
1270
+
1271
+ allbound , err := testEnv .binder .AssumePodVolumes (pod , "node1" )
1272
+ if allbound || err != nil {
1273
+ t .Errorf ("No volumes are assumed" )
1274
+ }
1275
+ testEnv .validateAssume (t , pod , expectedBindings , expectedProvisionings )
1276
+
1277
+ testEnv .binder .RevertAssumedPodVolumes (pod , "node1" )
1278
+ testEnv .validateCacheRestored (t , pod , bindings , provisionedPVCs )
1279
+ }
1280
+
1252
1281
func TestBindAPIUpdate (t * testing.T ) {
1253
1282
type scenarioType struct {
1254
1283
// Inputs
0 commit comments