@@ -36,7 +36,6 @@ import (
36
36
"k8s.io/kubernetes/pkg/features"
37
37
"k8s.io/kubernetes/pkg/volume"
38
38
"k8s.io/kubernetes/pkg/volume/csi"
39
- "k8s.io/kubernetes/pkg/volume/gcepd"
40
39
"k8s.io/kubernetes/pkg/volume/util"
41
40
)
42
41
@@ -351,17 +350,18 @@ func attachDetachRecoveryTestCase(t *testing.T, extraPods1 []*v1.Pod, extraPods2
351
350
}
352
351
353
352
type vaTest struct {
354
- testName string
355
- volName string
356
- podName string
357
- podNodeName string
358
- pvName string
359
- vaName string
360
- vaNodeName string
361
- vaAttachStatus bool
362
- csiMigration bool
363
- expected_attaches map [string ][]string
364
- expected_detaches map [string ][]string
353
+ testName string
354
+ volName string
355
+ podName string
356
+ podNodeName string
357
+ pvName string
358
+ vaName string
359
+ vaNodeName string
360
+ vaAttachStatus bool
361
+ csiMigration bool
362
+ expected_attaches map [string ][]string
363
+ expected_detaches map [string ][]string
364
+ expectedASWAttachState cache.AttachState
365
365
}
366
366
367
367
func Test_ADC_VolumeAttachmentRecovery (t * testing.T ) {
@@ -398,15 +398,26 @@ func Test_ADC_VolumeAttachmentRecovery(t *testing.T) {
398
398
expected_attaches : map [string ][]string {},
399
399
expected_detaches : map [string ][]string {"mynode-1" : {"vol1" }},
400
400
},
401
- {
402
- testName : "CSI Migration" ,
403
- volName : "vol1" ,
404
- podNodeName : "mynode-1" ,
405
- pvName : "pv1" ,
406
- vaName : "va1" ,
407
- vaNodeName : "mynode-1" ,
408
- vaAttachStatus : false ,
409
- csiMigration : true ,
401
+ { // pod is scheduled, volume is migrated, attach status:false, verify volume is marked as attached
402
+ testName : "Scheduled Pod with migrated PV" ,
403
+ volName : "vol1" ,
404
+ podNodeName : "mynode-1" ,
405
+ pvName : "pv1" ,
406
+ vaName : "va1" ,
407
+ vaNodeName : "mynode-1" ,
408
+ vaAttachStatus : false ,
409
+ csiMigration : true ,
410
+ expectedASWAttachState : cache .AttachStateAttached ,
411
+ },
412
+ { // pod is deleted, volume is migrated, attach status:false, verify volume is marked as uncertain
413
+ testName : "Deleted Pod with migrated PV" ,
414
+ volName : "vol1" ,
415
+ pvName : "pv1" ,
416
+ vaName : "va1" ,
417
+ vaNodeName : "mynode-1" ,
418
+ vaAttachStatus : false ,
419
+ csiMigration : true ,
420
+ expectedASWAttachState : cache .AttachStateUncertain ,
410
421
},
411
422
} {
412
423
t .Run (tc .testName , func (t * testing.T ) {
@@ -424,7 +435,7 @@ func volumeAttachmentRecoveryTestCase(t *testing.T, tc vaTest) {
424
435
defer featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .CSIMigrationGCE , tc .csiMigration )()
425
436
defer featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .CSIMigrationGCEComplete , tc .csiMigration )()
426
437
427
- plugins = gcepd . ProbeVolumePlugins ()
438
+ // if InTreePluginGCEUnregister is enabled, only the CSI plugin is registered but not the in-tree one
428
439
plugins = append (plugins , csi .ProbeVolumePlugins ()... )
429
440
} else {
430
441
plugins = controllervolumetesting .CreateTestPlugin ()
@@ -569,8 +580,8 @@ func verifyExpectedVolumeState(t *testing.T, adc *attachDetachController, tc vaT
569
580
// Since csi migration is turned on, the attach state for the PV should be in CSI format.
570
581
attachedState := adc .actualStateOfWorld .GetAttachState (
571
582
v1 .UniqueVolumeName (csiPDUniqueNamePrefix + tc .volName ), types .NodeName (tc .vaNodeName ))
572
- if attachedState != cache . AttachStateAttached {
573
- t .Fatalf ("Expected attachedState %v, but it is %v" , cache . AttachStateAttached , attachedState )
583
+ if attachedState != tc . expectedASWAttachState {
584
+ t .Fatalf ("Expected attachedState %v, but it is %v" , tc . expectedASWAttachState , attachedState )
574
585
}
575
586
576
587
// kubernetes.io/gce-pd/<volName> should not be marked when CSI Migration is on
0 commit comments