@@ -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
}
@@ -1225,7 +1226,7 @@ func TestAssumePodVolumes(t *testing.T) {
1225
1226
scenario .expectedProvisionings = scenario .provisionedPVCs
1226
1227
}
1227
1228
if scenario .shouldFail {
1228
- testEnv .validateFailedAssume (t , pod , scenario .expectedBindings , scenario .expectedProvisionings )
1229
+ testEnv .validateCacheRestored (t , pod , scenario .bindings , scenario .provisionedPVCs )
1229
1230
} else {
1230
1231
testEnv .validateAssume (t , pod , scenario .expectedBindings , scenario .expectedProvisionings )
1231
1232
}
@@ -1237,6 +1238,34 @@ func TestAssumePodVolumes(t *testing.T) {
1237
1238
}
1238
1239
}
1239
1240
1241
+ func TestRevertAssumedPodVolumes (t * testing.T ) {
1242
+ ctx , cancel := context .WithCancel (context .Background ())
1243
+ defer cancel ()
1244
+
1245
+ podPVCs := []* v1.PersistentVolumeClaim {unboundPVC , provisionedPVC }
1246
+ bindings := []* bindingInfo {makeBinding (unboundPVC , pvNode1a )}
1247
+ pvs := []* v1.PersistentVolume {pvNode1a }
1248
+ provisionedPVCs := []* v1.PersistentVolumeClaim {provisionedPVC }
1249
+ expectedBindings := []* bindingInfo {makeBinding (unboundPVC , pvNode1aBound )}
1250
+ expectedProvisionings := []* v1.PersistentVolumeClaim {selectedNodePVC }
1251
+
1252
+ // Setup
1253
+ testEnv := newTestBinder (t , ctx .Done ())
1254
+ testEnv .initClaims (podPVCs , podPVCs )
1255
+ pod := makePod (podPVCs )
1256
+ testEnv .initPodCache (pod , "node1" , bindings , provisionedPVCs )
1257
+ testEnv .initVolumes (pvs , pvs )
1258
+
1259
+ allbound , err := testEnv .binder .AssumePodVolumes (pod , "node1" )
1260
+ if allbound || err != nil {
1261
+ t .Errorf ("No volumes are assumed" )
1262
+ }
1263
+ testEnv .validateAssume (t , pod , expectedBindings , expectedProvisionings )
1264
+
1265
+ testEnv .binder .RevertAssumedPodVolumes (pod , "node1" )
1266
+ testEnv .validateCacheRestored (t , pod , bindings , provisionedPVCs )
1267
+ }
1268
+
1240
1269
func TestBindAPIUpdate (t * testing.T ) {
1241
1270
type scenarioType struct {
1242
1271
// Inputs
0 commit comments