diff --git a/pkg/controller/volume/persistentvolume/binder_test.go b/pkg/controller/volume/persistentvolume/binder_test.go index 76ecc458ab5..67a70ee8cba 100644 --- a/pkg/controller/volume/persistentvolume/binder_test.go +++ b/pkg/controller/volume/persistentvolume/binder_test.go @@ -42,219 +42,250 @@ func TestSync(t *testing.T) { // volumes. { // syncClaim binds to a matching unbound volume. - "1-1 - successful bind", - newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume1-1", "1Gi", "uid1-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, nil), - newClaimArray("claim1-1", "uid1-1", "1Gi", "volume1-1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "1-1 - successful bind", + initialVolumes: newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume1-1", "1Gi", "uid1-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim1-1", "uid1-1", "1Gi", "volume1-1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim does not do anything when there is no matching volume. - "1-2 - noop", - newVolumeArray("volume1-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume1-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim1-2", "uid1-2", "10Gi", "", v1.ClaimPending, nil), - newClaimArray("claim1-2", "uid1-2", "10Gi", "", v1.ClaimPending, nil), - []string{"Normal FailedBinding"}, - noerrors, testSyncClaim, + name: "1-2 - noop", + initialVolumes: newVolumeArray("volume1-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume1-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim1-2", "uid1-2", "10Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim1-2", "uid1-2", "10Gi", "", v1.ClaimPending, nil), + expectedEvents: []string{"Normal FailedBinding"}, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim resets claim.Status to Pending when there is no // matching volume. - "1-3 - reset to Pending", - newVolumeArray("volume1-3", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume1-3", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim1-3", "uid1-3", "10Gi", "", v1.ClaimBound, nil), - newClaimArray("claim1-3", "uid1-3", "10Gi", "", v1.ClaimPending, nil), - []string{"Normal FailedBinding"}, - noerrors, testSyncClaim, + name: "1-3 - reset to Pending", + initialVolumes: newVolumeArray("volume1-3", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume1-3", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim1-3", "uid1-3", "10Gi", "", v1.ClaimBound, nil), + expectedClaims: newClaimArray("claim1-3", "uid1-3", "10Gi", "", v1.ClaimPending, nil), + expectedEvents: []string{"Normal FailedBinding"}, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim binds claims to the smallest matching volume - "1-4 - smallest volume", - []*v1.PersistentVolume{ + name: "1-4 - smallest volume", + initialVolumes: []*v1.PersistentVolume{ newVolume("volume1-4_1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-4_2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), }, - []*v1.PersistentVolume{ + expectedVolumes: []*v1.PersistentVolume{ newVolume("volume1-4_1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-4_2", "1Gi", "uid1-4", "claim1-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), }, - newClaimArray("claim1-4", "uid1-4", "1Gi", "", v1.ClaimPending, nil), - newClaimArray("claim1-4", "uid1-4", "1Gi", "volume1-4_2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + initialClaims: newClaimArray("claim1-4", "uid1-4", "1Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim1-4", "uid1-4", "1Gi", "volume1-4_2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim binds a claim only to volume that points to it (by // name), even though a smaller one is available. - "1-5 - prebound volume by name - success", - []*v1.PersistentVolume{ + name: "1-5 - prebound volume by name - success", + initialVolumes: []*v1.PersistentVolume{ newVolume("volume1-5_1", "10Gi", "", "claim1-5", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-5_2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), }, - []*v1.PersistentVolume{ + expectedVolumes: []*v1.PersistentVolume{ newVolume("volume1-5_1", "10Gi", "uid1-5", "claim1-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-5_2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), }, - newClaimArray("claim1-5", "uid1-5", "1Gi", "", v1.ClaimPending, nil), - withExpectedCapacity("10Gi", newClaimArray("claim1-5", "uid1-5", "1Gi", "volume1-5_1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + initialClaims: newClaimArray("claim1-5", "uid1-5", "1Gi", "", v1.ClaimPending, nil), + expectedClaims: withExpectedCapacity("10Gi", newClaimArray("claim1-5", "uid1-5", "1Gi", "volume1-5_1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim binds a claim only to volume that points to it (by // UID), even though a smaller one is available. - "1-6 - prebound volume by UID - success", - []*v1.PersistentVolume{ + name: "1-6 - prebound volume by UID - success", + initialVolumes: []*v1.PersistentVolume{ newVolume("volume1-6_1", "10Gi", "uid1-6", "claim1-6", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-6_2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), }, - []*v1.PersistentVolume{ + expectedVolumes: []*v1.PersistentVolume{ newVolume("volume1-6_1", "10Gi", "uid1-6", "claim1-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-6_2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), }, - newClaimArray("claim1-6", "uid1-6", "1Gi", "", v1.ClaimPending, nil), - withExpectedCapacity("10Gi", newClaimArray("claim1-6", "uid1-6", "1Gi", "volume1-6_1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + initialClaims: newClaimArray("claim1-6", "uid1-6", "1Gi", "", v1.ClaimPending, nil), + expectedClaims: withExpectedCapacity("10Gi", newClaimArray("claim1-6", "uid1-6", "1Gi", "volume1-6_1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim does not bind claim to a volume prebound to a claim with // same name and different UID - "1-7 - prebound volume to different claim", - newVolumeArray("volume1-7", "10Gi", "uid1-777", "claim1-7", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume1-7", "10Gi", "uid1-777", "claim1-7", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim1-7", "uid1-7", "1Gi", "", v1.ClaimPending, nil), - newClaimArray("claim1-7", "uid1-7", "1Gi", "", v1.ClaimPending, nil), - []string{"Normal FailedBinding"}, - noerrors, testSyncClaim, + name: "1-7 - prebound volume to different claim", + initialVolumes: newVolumeArray("volume1-7", "10Gi", "uid1-777", "claim1-7", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume1-7", "10Gi", "uid1-777", "claim1-7", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim1-7", "uid1-7", "1Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim1-7", "uid1-7", "1Gi", "", v1.ClaimPending, nil), + expectedEvents: []string{"Normal FailedBinding"}, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim completes binding - simulates controller crash after // PV.ClaimRef is saved - "1-8 - complete bind after crash - PV bound", - newVolumeArray("volume1-8", "1Gi", "uid1-8", "claim1-8", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume1-8", "1Gi", "uid1-8", "claim1-8", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newClaimArray("claim1-8", "uid1-8", "1Gi", "", v1.ClaimPending, nil), - newClaimArray("claim1-8", "uid1-8", "1Gi", "volume1-8", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "1-8 - complete bind after crash - PV bound", + initialVolumes: newVolumeArray("volume1-8", "1Gi", "uid1-8", "claim1-8", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume1-8", "1Gi", "uid1-8", "claim1-8", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: newClaimArray("claim1-8", "uid1-8", "1Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim1-8", "uid1-8", "1Gi", "volume1-8", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim completes binding - simulates controller crash after // PV.Status is saved - "1-9 - complete bind after crash - PV status saved", - newVolumeArray("volume1-9", "1Gi", "uid1-9", "claim1-9", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume1-9", "1Gi", "uid1-9", "claim1-9", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newClaimArray("claim1-9", "uid1-9", "1Gi", "", v1.ClaimPending, nil), - newClaimArray("claim1-9", "uid1-9", "1Gi", "volume1-9", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "1-9 - complete bind after crash - PV status saved", + initialVolumes: newVolumeArray("volume1-9", "1Gi", "uid1-9", "claim1-9", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume1-9", "1Gi", "uid1-9", "claim1-9", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: newClaimArray("claim1-9", "uid1-9", "1Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim1-9", "uid1-9", "1Gi", "volume1-9", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim completes binding - simulates controller crash after // PVC.VolumeName is saved - "1-10 - complete bind after crash - PVC bound", - newVolumeArray("volume1-10", "1Gi", "uid1-10", "claim1-10", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume1-10", "1Gi", "uid1-10", "claim1-10", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newClaimArray("claim1-10", "uid1-10", "1Gi", "volume1-10", v1.ClaimPending, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - newClaimArray("claim1-10", "uid1-10", "1Gi", "volume1-10", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "1-10 - complete bind after crash - PVC bound", + initialVolumes: newVolumeArray("volume1-10", "1Gi", "uid1-10", "claim1-10", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume1-10", "1Gi", "uid1-10", "claim1-10", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: newClaimArray("claim1-10", "uid1-10", "1Gi", "volume1-10", v1.ClaimPending, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedClaims: newClaimArray("claim1-10", "uid1-10", "1Gi", "volume1-10", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim binds a claim only when the label selector matches the volume - "1-11 - bind when selector matches", - withLabels(labels, newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withLabels(labels, newVolumeArray("volume1-1", "1Gi", "uid1-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withLabelSelector(labels, newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, nil)), - withLabelSelector(labels, newClaimArray("claim1-1", "uid1-1", "1Gi", "volume1-1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + name: "1-11 - bind when selector matches", + initialVolumes: withLabels(labels, newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + expectedVolumes: withLabels(labels, newVolumeArray("volume1-1", "1Gi", "uid1-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + initialClaims: withLabelSelector(labels, newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, nil)), + expectedClaims: withLabelSelector(labels, newClaimArray("claim1-1", "uid1-1", "1Gi", "volume1-1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim does not bind a claim when the label selector doesn't match - "1-12 - do not bind when selector does not match", - newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - withLabelSelector(labels, newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, nil)), - withLabelSelector(labels, newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, nil)), - []string{"Normal FailedBinding"}, - noerrors, testSyncClaim, + name: "1-12 - do not bind when selector does not match", + initialVolumes: newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: withLabelSelector(labels, newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, nil)), + expectedClaims: withLabelSelector(labels, newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, nil)), + expectedEvents: []string{"Normal FailedBinding"}, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim does not do anything when binding is delayed - "1-13 - delayed binding", - newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classWait), - newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classWait), - newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, &classWait), - newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, &classWait), - []string{"Normal WaitForFirstConsumer"}, - noerrors, testSyncClaim, + name: "1-13 - delayed binding", + initialVolumes: newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classWait), + expectedVolumes: newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classWait), + initialClaims: newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, &classWait), + expectedClaims: newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, &classWait), + expectedEvents: []string{"Normal WaitForFirstConsumer"}, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim binds when binding is delayed but PV is prebound to PVC - "1-14 - successful prebound PV", - newVolumeArray("volume1-1", "1Gi", "", "claim1-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classWait), - newVolumeArray("volume1-1", "1Gi", "uid1-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classWait), - newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, &classWait), - newClaimArray("claim1-1", "uid1-1", "1Gi", "volume1-1", v1.ClaimBound, &classWait, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "1-14 - successful prebound PV", + initialVolumes: newVolumeArray("volume1-1", "1Gi", "", "claim1-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classWait), + expectedVolumes: newVolumeArray("volume1-1", "1Gi", "uid1-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classWait), + initialClaims: newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, &classWait), + expectedClaims: newClaimArray("claim1-1", "uid1-1", "1Gi", "volume1-1", v1.ClaimBound, &classWait, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim binds pre-bound PVC only to the volume it points to, // even if there is smaller volume available - "1-15 - successful prebound PVC", - []*v1.PersistentVolume{ + name: "1-15 - successful prebound PVC", + initialVolumes: []*v1.PersistentVolume{ newVolume("volume1-15_1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-15_2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), }, - []*v1.PersistentVolume{ + expectedVolumes: []*v1.PersistentVolume{ newVolume("volume1-15_1", "10Gi", "uid1-15", "claim1-15", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), newVolume("volume1-15_2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), }, - newClaimArray("claim1-15", "uid1-15", "1Gi", "volume1-15_1", v1.ClaimPending, nil), - withExpectedCapacity("10Gi", newClaimArray("claim1-15", "uid1-15", "1Gi", "volume1-15_1", v1.ClaimBound, nil, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + initialClaims: newClaimArray("claim1-15", "uid1-15", "1Gi", "volume1-15_1", v1.ClaimPending, nil), + expectedClaims: withExpectedCapacity("10Gi", newClaimArray("claim1-15", "uid1-15", "1Gi", "volume1-15_1", v1.ClaimBound, nil, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim does not bind pre-bound PVC to PV with different AccessMode - "1-16 - successful prebound PVC", + name: "1-16 - successful prebound PVC", // PV has ReadWriteOnce - newVolumeArray("volume1-16", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume1-16", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - claimWithAccessMode([]v1.PersistentVolumeAccessMode{v1.ReadWriteMany}, newClaimArray("claim1-16", "uid1-16", "1Gi", "volume1-16", v1.ClaimPending, nil)), - claimWithAccessMode([]v1.PersistentVolumeAccessMode{v1.ReadWriteMany}, newClaimArray("claim1-16", "uid1-16", "1Gi", "volume1-16", v1.ClaimPending, nil)), - noevents, noerrors, testSyncClaim, + initialVolumes: newVolumeArray("volume1-16", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume1-16", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: claimWithAccessMode([]v1.PersistentVolumeAccessMode{v1.ReadWriteMany}, newClaimArray("claim1-16", "uid1-16", "1Gi", "volume1-16", v1.ClaimPending, nil)), + expectedClaims: claimWithAccessMode([]v1.PersistentVolumeAccessMode{v1.ReadWriteMany}, newClaimArray("claim1-16", "uid1-16", "1Gi", "volume1-16", v1.ClaimPending, nil)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim does not bind PVC to non-available PV if it's not pre-bind - "1-17 - skip non-available PV if it's not pre-bind", - []*v1.PersistentVolume{ + name: "1-17 - skip non-available PV if it's not pre-bind", + initialVolumes: []*v1.PersistentVolume{ newVolume("volume1-17-pending", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-17-failed", "1Gi", "", "", v1.VolumeFailed, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-17-released", "1Gi", "", "", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-17-empty", "1Gi", "", "", "", v1.PersistentVolumeReclaimRetain, classEmpty), }, - []*v1.PersistentVolume{ + expectedVolumes: []*v1.PersistentVolume{ newVolume("volume1-17-pending", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-17-failed", "1Gi", "", "", v1.VolumeFailed, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-17-released", "1Gi", "", "", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume1-17-empty", "1Gi", "", "", "", v1.PersistentVolumeReclaimRetain, classEmpty), }, - []*v1.PersistentVolumeClaim{ + initialClaims: []*v1.PersistentVolumeClaim{ newClaim("claim1-17", "uid1-17", "1Gi", "", v1.ClaimPending, nil), }, - []*v1.PersistentVolumeClaim{ + expectedClaims: []*v1.PersistentVolumeClaim{ newClaim("claim1-17", "uid1-17", "1Gi", "", v1.ClaimPending, nil), }, - noevents, noerrors, testSyncClaim, + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim that scheduled to a selected node - "1-18 - successful pre-bound PV to PVC provisioning", - newVolumeArray("volume1-18", "1Gi", "uid1-18", "claim1-18", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classWait), - newVolumeArray("volume1-18", "1Gi", "uid1-18", "claim1-18", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classWait), - claimWithAnnotation(volume.AnnSelectedNode, "node1", + name: "1-18 - successful pre-bound PV to PVC provisioning", + initialVolumes: newVolumeArray("volume1-18", "1Gi", "uid1-18", "claim1-18", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classWait), + expectedVolumes: newVolumeArray("volume1-18", "1Gi", "uid1-18", "claim1-18", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classWait), + initialClaims: claimWithAnnotation(volume.AnnSelectedNode, "node1", newClaimArray("claim1-18", "uid1-18", "1Gi", "", v1.ClaimPending, &classWait)), - claimWithAnnotation(volume.AnnSelectedNode, "node1", + expectedClaims: claimWithAnnotation(volume.AnnSelectedNode, "node1", newClaimArray("claim1-18", "uid1-18", "1Gi", "volume1-18", v1.ClaimBound, &classWait, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, // [Unit test set 2] User asked for a specific PV. @@ -262,390 +293,460 @@ func TestSync(t *testing.T) { // by user. { // syncClaim with claim pre-bound to a PV that does not exist - "2-1 - claim prebound to non-existing volume - noop", - novolumes, - novolumes, - newClaimArray("claim2-1", "uid2-1", "10Gi", "volume2-1", v1.ClaimPending, nil), - newClaimArray("claim2-1", "uid2-1", "10Gi", "volume2-1", v1.ClaimPending, nil), - noevents, noerrors, testSyncClaim, + name: "2-1 - claim prebound to non-existing volume - noop", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim2-1", "uid2-1", "10Gi", "volume2-1", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim2-1", "uid2-1", "10Gi", "volume2-1", v1.ClaimPending, nil), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim pre-bound to a PV that does not exist. // Check that the claim status is reset to Pending - "2-2 - claim prebound to non-existing volume - reset status", - novolumes, - novolumes, - newClaimArray("claim2-2", "uid2-2", "10Gi", "volume2-2", v1.ClaimBound, nil), - newClaimArray("claim2-2", "uid2-2", "10Gi", "volume2-2", v1.ClaimPending, nil), - noevents, noerrors, testSyncClaim, + name: "2-2 - claim prebound to non-existing volume - reset status", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim2-2", "uid2-2", "10Gi", "volume2-2", v1.ClaimBound, nil), + expectedClaims: newClaimArray("claim2-2", "uid2-2", "10Gi", "volume2-2", v1.ClaimPending, nil), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim pre-bound to a PV that exists and is // unbound. Check it gets bound and no volume.AnnBoundByController is set. - "2-3 - claim prebound to unbound volume", - newVolumeArray("volume2-3", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume2-3", "1Gi", "uid2-3", "claim2-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", v1.ClaimPending, nil), - newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", v1.ClaimBound, nil, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "2-3 - claim prebound to unbound volume", + initialVolumes: newVolumeArray("volume2-3", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume2-3", "1Gi", "uid2-3", "claim2-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", v1.ClaimBound, nil, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // claim with claim pre-bound to a PV that is pre-bound to the claim // by name. Check it gets bound and no volume.AnnBoundByController is set. - "2-4 - claim prebound to prebound volume by name", - newVolumeArray("volume2-4", "1Gi", "", "claim2-4", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume2-4", "1Gi", "uid2-4", "claim2-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim2-4", "uid2-4", "1Gi", "volume2-4", v1.ClaimPending, nil), - newClaimArray("claim2-4", "uid2-4", "1Gi", "volume2-4", v1.ClaimBound, nil, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "2-4 - claim prebound to prebound volume by name", + initialVolumes: newVolumeArray("volume2-4", "1Gi", "", "claim2-4", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume2-4", "1Gi", "uid2-4", "claim2-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim2-4", "uid2-4", "1Gi", "volume2-4", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim2-4", "uid2-4", "1Gi", "volume2-4", v1.ClaimBound, nil, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim pre-bound to a PV that is pre-bound to the // claim by UID. Check it gets bound and no volume.AnnBoundByController is // set. - "2-5 - claim prebound to prebound volume by UID", - newVolumeArray("volume2-5", "1Gi", "uid2-5", "claim2-5", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume2-5", "1Gi", "uid2-5", "claim2-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim2-5", "uid2-5", "1Gi", "volume2-5", v1.ClaimPending, nil), - newClaimArray("claim2-5", "uid2-5", "1Gi", "volume2-5", v1.ClaimBound, nil, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "2-5 - claim prebound to prebound volume by UID", + initialVolumes: newVolumeArray("volume2-5", "1Gi", "uid2-5", "claim2-5", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume2-5", "1Gi", "uid2-5", "claim2-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim2-5", "uid2-5", "1Gi", "volume2-5", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim2-5", "uid2-5", "1Gi", "volume2-5", v1.ClaimBound, nil, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim pre-bound to a PV that is bound to different // claim. Check it's reset to Pending. - "2-6 - claim prebound to already bound volume", - newVolumeArray("volume2-6", "1Gi", "uid2-6_1", "claim2-6_1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume2-6", "1Gi", "uid2-6_1", "claim2-6_1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim2-6", "uid2-6", "1Gi", "volume2-6", v1.ClaimBound, nil), - newClaimArray("claim2-6", "uid2-6", "1Gi", "volume2-6", v1.ClaimPending, nil), - noevents, noerrors, testSyncClaim, + name: "2-6 - claim prebound to already bound volume", + initialVolumes: newVolumeArray("volume2-6", "1Gi", "uid2-6_1", "claim2-6_1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume2-6", "1Gi", "uid2-6_1", "claim2-6_1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim2-6", "uid2-6", "1Gi", "volume2-6", v1.ClaimBound, nil), + expectedClaims: newClaimArray("claim2-6", "uid2-6", "1Gi", "volume2-6", v1.ClaimPending, nil), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim bound by controller to a PV that is bound to // different claim. Check it throws an error. - "2-7 - claim bound by controller to already bound volume", - newVolumeArray("volume2-7", "1Gi", "uid2-7_1", "claim2-7_1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume2-7", "1Gi", "uid2-7_1", "claim2-7_1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim2-7", "uid2-7", "1Gi", "volume2-7", v1.ClaimBound, nil, volume.AnnBoundByController), - newClaimArray("claim2-7", "uid2-7", "1Gi", "volume2-7", v1.ClaimBound, nil, volume.AnnBoundByController), - noevents, noerrors, testSyncClaimError, + name: "2-7 - claim bound by controller to already bound volume", + initialVolumes: newVolumeArray("volume2-7", "1Gi", "uid2-7_1", "claim2-7_1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume2-7", "1Gi", "uid2-7_1", "claim2-7_1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim2-7", "uid2-7", "1Gi", "volume2-7", v1.ClaimBound, nil, volume.AnnBoundByController), + expectedClaims: newClaimArray("claim2-7", "uid2-7", "1Gi", "volume2-7", v1.ClaimBound, nil, volume.AnnBoundByController), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaimError, }, { // syncClaim with claim pre-bound to a PV that exists and is // unbound, but does not match the selector. Check it gets bound // and no volume.AnnBoundByController is set. - "2-8 - claim prebound to unbound volume that does not match the selector", - newVolumeArray("volume2-8", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume2-8", "1Gi", "uid2-8", "claim2-8", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - withLabelSelector(labels, newClaimArray("claim2-8", "uid2-8", "1Gi", "volume2-8", v1.ClaimPending, nil)), - withLabelSelector(labels, newClaimArray("claim2-8", "uid2-8", "1Gi", "volume2-8", v1.ClaimBound, nil, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + name: "2-8 - claim prebound to unbound volume that does not match the selector", + initialVolumes: newVolumeArray("volume2-8", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume2-8", "1Gi", "uid2-8", "claim2-8", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: withLabelSelector(labels, newClaimArray("claim2-8", "uid2-8", "1Gi", "volume2-8", v1.ClaimPending, nil)), + expectedClaims: withLabelSelector(labels, newClaimArray("claim2-8", "uid2-8", "1Gi", "volume2-8", v1.ClaimBound, nil, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim pre-bound to a PV that exists and is // unbound, but its size is smaller than requested. //Check that the claim status is reset to Pending - "2-9 - claim prebound to unbound volume that size is smaller than requested", - newVolumeArray("volume2-9", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume2-9", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim2-9", "uid2-9", "2Gi", "volume2-9", v1.ClaimBound, nil), - newClaimArray("claim2-9", "uid2-9", "2Gi", "volume2-9", v1.ClaimPending, nil), - []string{"Warning VolumeMismatch"}, noerrors, testSyncClaim, + name: "2-9 - claim prebound to unbound volume that size is smaller than requested", + initialVolumes: newVolumeArray("volume2-9", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume2-9", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim2-9", "uid2-9", "2Gi", "volume2-9", v1.ClaimBound, nil), + expectedClaims: newClaimArray("claim2-9", "uid2-9", "2Gi", "volume2-9", v1.ClaimPending, nil), + expectedEvents: []string{"Warning VolumeMismatch"}, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim pre-bound to a PV that exists and is // unbound, but its class does not match. Check that the claim status is reset to Pending - "2-10 - claim prebound to unbound volume that class is different", - newVolumeArray("volume2-10", "1Gi", "1", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold), - newVolumeArray("volume2-10", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold), - newClaimArray("claim2-10", "uid2-10", "1Gi", "volume2-10", v1.ClaimBound, nil), - newClaimArray("claim2-10", "uid2-10", "1Gi", "volume2-10", v1.ClaimPending, nil), - []string{"Warning VolumeMismatch"}, noerrors, testSyncClaim, + name: "2-10 - claim prebound to unbound volume that class is different", + initialVolumes: newVolumeArray("volume2-10", "1Gi", "1", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold), + expectedVolumes: newVolumeArray("volume2-10", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold), + initialClaims: newClaimArray("claim2-10", "uid2-10", "1Gi", "volume2-10", v1.ClaimBound, nil), + expectedClaims: newClaimArray("claim2-10", "uid2-10", "1Gi", "volume2-10", v1.ClaimPending, nil), + expectedEvents: []string{"Warning VolumeMismatch"}, + errors: noerrors, + test: testSyncClaim, }, // [Unit test set 3] Syncing bound claim { // syncClaim with claim bound and its claim.Spec.VolumeName is // removed. Check it's marked as Lost. - "3-1 - bound claim with missing VolumeName", - novolumes, - novolumes, - newClaimArray("claim3-1", "uid3-1", "10Gi", "", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - newClaimArray("claim3-1", "uid3-1", "10Gi", "", v1.ClaimLost, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - []string{"Warning ClaimLost"}, noerrors, testSyncClaim, + name: "3-1 - bound claim with missing VolumeName", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim3-1", "uid3-1", "10Gi", "", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedClaims: newClaimArray("claim3-1", "uid3-1", "10Gi", "", v1.ClaimLost, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: []string{"Warning ClaimLost"}, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim bound to non-existing volume. Check it's // marked as Lost. - "3-2 - bound claim with missing volume", - novolumes, - novolumes, - newClaimArray("claim3-2", "uid3-2", "10Gi", "volume3-2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - newClaimArray("claim3-2", "uid3-2", "10Gi", "volume3-2", v1.ClaimLost, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - []string{"Warning ClaimLost"}, noerrors, testSyncClaim, + name: "3-2 - bound claim with missing volume", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim3-2", "uid3-2", "10Gi", "volume3-2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedClaims: newClaimArray("claim3-2", "uid3-2", "10Gi", "volume3-2", v1.ClaimLost, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: []string{"Warning ClaimLost"}, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim bound to unbound volume. Check it's bound. // Also check that Pending phase is set to Bound - "3-3 - bound claim with unbound volume", - newVolumeArray("volume3-3", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume3-3", "10Gi", "uid3-3", "claim3-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimPending, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "3-3 - bound claim with unbound volume", + initialVolumes: newVolumeArray("volume3-3", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume3-3", "10Gi", "uid3-3", "claim3-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimPending, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedClaims: newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim bound to volume with missing (or different) // volume.Spec.ClaimRef.UID. Check that the claim is marked as lost. - "3-4 - bound claim with prebound volume", - newVolumeArray("volume3-4", "10Gi", "claim3-4-x", "claim3-4", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume3-4", "10Gi", "claim3-4-x", "claim3-4", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim3-4", "uid3-4", "10Gi", "volume3-4", v1.ClaimPending, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - newClaimArray("claim3-4", "uid3-4", "10Gi", "volume3-4", v1.ClaimLost, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - []string{"Warning ClaimMisbound"}, noerrors, testSyncClaim, + name: "3-4 - bound claim with prebound volume", + initialVolumes: newVolumeArray("volume3-4", "10Gi", "claim3-4-x", "claim3-4", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume3-4", "10Gi", "claim3-4-x", "claim3-4", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim3-4", "uid3-4", "10Gi", "volume3-4", v1.ClaimPending, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedClaims: newClaimArray("claim3-4", "uid3-4", "10Gi", "volume3-4", v1.ClaimLost, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: []string{"Warning ClaimMisbound"}, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim bound to bound volume. Check that the // controller does not do anything. Also check that Pending phase is // set to Bound - "3-5 - bound claim with bound volume", - newVolumeArray("volume3-5", "10Gi", "uid3-5", "claim3-5", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume3-5", "10Gi", "uid3-5", "claim3-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim3-5", "uid3-5", "10Gi", "volume3-5", v1.ClaimPending, nil, volume.AnnBindCompleted), - newClaimArray("claim3-5", "uid3-5", "10Gi", "volume3-5", v1.ClaimBound, nil, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "3-5 - bound claim with bound volume", + initialVolumes: newVolumeArray("volume3-5", "10Gi", "uid3-5", "claim3-5", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume3-5", "10Gi", "uid3-5", "claim3-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim3-5", "uid3-5", "10Gi", "volume3-5", v1.ClaimPending, nil, volume.AnnBindCompleted), + expectedClaims: newClaimArray("claim3-5", "uid3-5", "10Gi", "volume3-5", v1.ClaimBound, nil, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim bound to a volume that is bound to different // claim. Check that the claim is marked as lost. // TODO: test that an event is emitted - "3-6 - bound claim with bound volume", - newVolumeArray("volume3-6", "10Gi", "uid3-6-x", "claim3-6-x", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume3-6", "10Gi", "uid3-6-x", "claim3-6-x", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim3-6", "uid3-6", "10Gi", "volume3-6", v1.ClaimPending, nil, volume.AnnBindCompleted), - newClaimArray("claim3-6", "uid3-6", "10Gi", "volume3-6", v1.ClaimLost, nil, volume.AnnBindCompleted), - []string{"Warning ClaimMisbound"}, noerrors, testSyncClaim, + name: "3-6 - bound claim with bound volume", + initialVolumes: newVolumeArray("volume3-6", "10Gi", "uid3-6-x", "claim3-6-x", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume3-6", "10Gi", "uid3-6-x", "claim3-6-x", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim3-6", "uid3-6", "10Gi", "volume3-6", v1.ClaimPending, nil, volume.AnnBindCompleted), + expectedClaims: newClaimArray("claim3-6", "uid3-6", "10Gi", "volume3-6", v1.ClaimLost, nil, volume.AnnBindCompleted), + expectedEvents: []string{"Warning ClaimMisbound"}, + errors: noerrors, + test: testSyncClaim, }, { // syncClaim with claim bound to unbound volume. Check it's bound // even if the claim's selector doesn't match the volume. Also // check that Pending phase is set to Bound - "3-7 - bound claim with unbound volume where selector doesn't match", - newVolumeArray("volume3-3", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume3-3", "10Gi", "uid3-3", "claim3-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - withLabelSelector(labels, newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimPending, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), - withLabelSelector(labels, newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + name: "3-7 - bound claim with unbound volume where selector doesn't match", + initialVolumes: newVolumeArray("volume3-3", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume3-3", "10Gi", "uid3-3", "claim3-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: withLabelSelector(labels, newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimPending, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedClaims: withLabelSelector(labels, newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, // [Unit test set 4] All syncVolume tests. { // syncVolume with pending volume. Check it's marked as Available. - "4-1 - pending volume", - newVolumeArray("volume4-1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume4-1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - noclaims, - noclaims, - noevents, noerrors, testSyncVolume, + name: "4-1 - pending volume", + initialVolumes: newVolumeArray("volume4-1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume4-1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume with prebound pending volume. Check it's marked as // Available. - "4-2 - pending prebound volume", - newVolumeArray("volume4-2", "10Gi", "", "claim4-2", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume4-2", "10Gi", "", "claim4-2", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - noclaims, - noclaims, - noevents, noerrors, testSyncVolume, + name: "4-2 - pending prebound volume", + initialVolumes: newVolumeArray("volume4-2", "10Gi", "", "claim4-2", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume4-2", "10Gi", "", "claim4-2", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume with volume bound to missing claim. // Check the volume gets Released - "4-3 - bound volume with missing claim", - newVolumeArray("volume4-3", "10Gi", "uid4-3", "claim4-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume4-3", "10Gi", "uid4-3", "claim4-3", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain, classEmpty), - noclaims, - noclaims, - noevents, noerrors, testSyncVolume, + name: "4-3 - bound volume with missing claim", + initialVolumes: newVolumeArray("volume4-3", "10Gi", "uid4-3", "claim4-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume4-3", "10Gi", "uid4-3", "claim4-3", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume with volume bound to claim with different UID. // Check the volume gets Released. - "4-4 - volume bound to claim with different UID", - newVolumeArray("volume4-4", "10Gi", "uid4-4", "claim4-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume4-4", "10Gi", "uid4-4", "claim4-4", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim4-4", "uid4-4-x", "10Gi", "volume4-4", v1.ClaimBound, nil, volume.AnnBindCompleted), - newClaimArray("claim4-4", "uid4-4-x", "10Gi", "volume4-4", v1.ClaimBound, nil, volume.AnnBindCompleted), - noevents, noerrors, testSyncVolume, + name: "4-4 - volume bound to claim with different UID", + initialVolumes: newVolumeArray("volume4-4", "10Gi", "uid4-4", "claim4-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume4-4", "10Gi", "uid4-4", "claim4-4", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim4-4", "uid4-4-x", "10Gi", "volume4-4", v1.ClaimBound, nil, volume.AnnBindCompleted), + expectedClaims: newClaimArray("claim4-4", "uid4-4-x", "10Gi", "volume4-4", v1.ClaimBound, nil, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume with volume bound by controller to unbound claim. // Check syncVolume does not do anything. - "4-5 - volume bound by controller to unbound claim", - newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending, nil), - newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending, nil), - noevents, noerrors, testSyncVolume, + name: "4-5 - volume bound by controller to unbound claim", + initialVolumes: newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending, nil), + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume with volume bound by user to unbound claim. // Check syncVolume does not do anything. - "4-5 - volume bound by user to bound claim", - newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending, nil), - newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending, nil), - noevents, noerrors, testSyncVolume, + name: "4-5 - volume bound by user to bound claim", + initialVolumes: newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending, nil), + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume with volume bound to bound claim. // Check that the volume is marked as Bound. - "4-6 - volume bound by to bound claim", - newVolumeArray("volume4-6", "10Gi", "uid4-6", "claim4-6", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume4-6", "10Gi", "uid4-6", "claim4-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim4-6", "uid4-6", "10Gi", "volume4-6", v1.ClaimBound, nil), - newClaimArray("claim4-6", "uid4-6", "10Gi", "volume4-6", v1.ClaimBound, nil), - noevents, noerrors, testSyncVolume, + name: "4-6 - volume bound by to bound claim", + initialVolumes: newVolumeArray("volume4-6", "10Gi", "uid4-6", "claim4-6", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume4-6", "10Gi", "uid4-6", "claim4-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim4-6", "uid4-6", "10Gi", "volume4-6", v1.ClaimBound, nil), + expectedClaims: newClaimArray("claim4-6", "uid4-6", "10Gi", "volume4-6", v1.ClaimBound, nil), + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume with volume bound by controller to claim bound to // another volume. Check that the volume is rolled back. - "4-7 - volume bound by controller to claim bound somewhere else", - newVolumeArray("volume4-7", "10Gi", "uid4-7", "claim4-7", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume4-7", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim4-7", "uid4-7", "10Gi", "volume4-7-x", v1.ClaimBound, nil), - newClaimArray("claim4-7", "uid4-7", "10Gi", "volume4-7-x", v1.ClaimBound, nil), - noevents, noerrors, testSyncVolume, + name: "4-7 - volume bound by controller to claim bound somewhere else", + initialVolumes: newVolumeArray("volume4-7", "10Gi", "uid4-7", "claim4-7", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume4-7", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim4-7", "uid4-7", "10Gi", "volume4-7-x", v1.ClaimBound, nil), + expectedClaims: newClaimArray("claim4-7", "uid4-7", "10Gi", "volume4-7-x", v1.ClaimBound, nil), + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume with volume bound by user to claim bound to // another volume. Check that the volume is marked as Available // and its UID is reset. - "4-8 - volume bound by user to claim bound somewhere else", - newVolumeArray("volume4-8", "10Gi", "uid4-8", "claim4-8", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume4-8", "10Gi", "", "claim4-8", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newClaimArray("claim4-8", "uid4-8", "10Gi", "volume4-8-x", v1.ClaimBound, nil), - newClaimArray("claim4-8", "uid4-8", "10Gi", "volume4-8-x", v1.ClaimBound, nil), - noevents, noerrors, testSyncVolume, + name: "4-8 - volume bound by user to claim bound somewhere else", + initialVolumes: newVolumeArray("volume4-8", "10Gi", "uid4-8", "claim4-8", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume4-8", "10Gi", "", "claim4-8", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + initialClaims: newClaimArray("claim4-8", "uid4-8", "10Gi", "volume4-8-x", v1.ClaimBound, nil), + expectedClaims: newClaimArray("claim4-8", "uid4-8", "10Gi", "volume4-8-x", v1.ClaimBound, nil), + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume with volume bound to bound claim. // Check that the volume is not deleted. - "4-9 - volume bound to bound claim, with PersistentVolumeReclaimDelete", - newVolumeArray("volume4-9", "10Gi", "uid4-9", "claim4-9", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty), - newVolumeArray("volume4-9", "10Gi", "uid4-9", "claim4-9", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), - newClaimArray("claim4-9", "uid4-9", "10Gi", "volume4-9", v1.ClaimBound, nil), - newClaimArray("claim4-9", "uid4-9", "10Gi", "volume4-9", v1.ClaimBound, nil), - noevents, noerrors, testSyncVolume, + name: "4-9 - volume bound to bound claim, with PersistentVolumeReclaimDelete", + initialVolumes: newVolumeArray("volume4-9", "10Gi", "uid4-9", "claim4-9", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty), + expectedVolumes: newVolumeArray("volume4-9", "10Gi", "uid4-9", "claim4-9", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), + initialClaims: newClaimArray("claim4-9", "uid4-9", "10Gi", "volume4-9", v1.ClaimBound, nil), + expectedClaims: newClaimArray("claim4-9", "uid4-9", "10Gi", "volume4-9", v1.ClaimBound, nil), + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume with volume bound to missing claim. // Check that a volume deletion is attempted. It fails because there is no deleter. - "4-10 - volume bound to missing claim", - newVolumeArray("volume4-10", "10Gi", "uid4-10", "claim4-10", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty), - func() []*v1.PersistentVolume { + name: "4-10 - volume bound to missing claim", + initialVolumes: newVolumeArray("volume4-10", "10Gi", "uid4-10", "claim4-10", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty), + expectedVolumes: func() []*v1.PersistentVolume { volumes := newVolumeArray("volume4-10", "10Gi", "uid4-10", "claim4-10", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete, classEmpty) volumes[0].Status.Message = `error getting deleter volume plugin for volume "volume4-10": no volume plugin matched` return volumes }(), - noclaims, - noclaims, - noevents, noerrors, testSyncVolume, + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume with volume bound to claim which exists in etcd but not in the local cache. // Check that nothing changes, in contrast to case 4-10 above. - "4-11 - volume bound to unknown claim", - newVolumeArray("volume4-11", "10Gi", "uid4-11", "claim4-11", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty), - newVolumeArray("volume4-11", "10Gi", "uid4-11", "claim4-11", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), - newClaimArray("claim4-11", "uid4-11", "10Gi", "volume4-11", v1.ClaimBound, nil, annSkipLocalStore), - newClaimArray("claim4-11", "uid4-11", "10Gi", "volume4-11", v1.ClaimBound, nil, annSkipLocalStore), - noevents, noerrors, testSyncVolume, + name: "4-11 - volume bound to unknown claim", + initialVolumes: newVolumeArray("volume4-11", "10Gi", "uid4-11", "claim4-11", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty), + expectedVolumes: newVolumeArray("volume4-11", "10Gi", "uid4-11", "claim4-11", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), + initialClaims: newClaimArray("claim4-11", "uid4-11", "10Gi", "volume4-11", v1.ClaimBound, nil, annSkipLocalStore), + expectedClaims: newClaimArray("claim4-11", "uid4-11", "10Gi", "volume4-11", v1.ClaimBound, nil, annSkipLocalStore), + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume with volume bound to claim which exists in etcd but not updated to local cache. - "4-12 - volume bound to newest claim but not updated to local cache", - newVolumeArray("volume4-12", "10Gi", "uid4-12-new", "claim4-12", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty), - newVolumeArray("volume4-12", "10Gi", "uid4-12-new", "claim4-12", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), - func() []*v1.PersistentVolumeClaim { + name: "4-12 - volume bound to newest claim but not updated to local cache", + initialVolumes: newVolumeArray("volume4-12", "10Gi", "uid4-12-new", "claim4-12", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty), + expectedVolumes: newVolumeArray("volume4-12", "10Gi", "uid4-12-new", "claim4-12", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), + initialClaims: func() []*v1.PersistentVolumeClaim { newClaim := newClaimArray("claim4-12", "uid4-12", "10Gi", "volume4-12", v1.ClaimBound, nil, "") // update uid to new-uid and not sync to cache. newClaim = append(newClaim, newClaimArray("claim4-12", "uid4-12-new", "10Gi", "volume4-12", v1.ClaimBound, nil, annSkipLocalStore)...) return newClaim }(), - newClaimArray("claim4-12", "uid4-12-new", "10Gi", "volume4-12", v1.ClaimBound, nil, annSkipLocalStore), - noevents, noerrors, testSyncVolume, + expectedClaims: newClaimArray("claim4-12", "uid4-12-new", "10Gi", "volume4-12", v1.ClaimBound, nil, annSkipLocalStore), + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, // PVC with class { // syncVolume binds a claim to requested class even if there is a // smaller PV available - "13-1 - binding to class", - []*v1.PersistentVolume{ + name: "13-1 - binding to class", + initialVolumes: []*v1.PersistentVolume{ newVolume("volume13-1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume13-1-2", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold), }, - []*v1.PersistentVolume{ + expectedVolumes: []*v1.PersistentVolume{ newVolume("volume13-1-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), newVolume("volume13-1-2", "10Gi", "uid13-1", "claim13-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classGold, volume.AnnBoundByController), }, - newClaimArray("claim13-1", "uid13-1", "1Gi", "", v1.ClaimPending, &classGold), - withExpectedCapacity("10Gi", newClaimArray("claim13-1", "uid13-1", "1Gi", "volume13-1-2", v1.ClaimBound, &classGold, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + initialClaims: newClaimArray("claim13-1", "uid13-1", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: withExpectedCapacity("10Gi", newClaimArray("claim13-1", "uid13-1", "1Gi", "volume13-1-2", v1.ClaimBound, &classGold, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncVolume binds a claim without a class even if there is a // smaller PV with a class available - "13-2 - binding without a class", - []*v1.PersistentVolume{ + name: "13-2 - binding without a class", + initialVolumes: []*v1.PersistentVolume{ newVolume("volume13-2-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold), newVolume("volume13-2-2", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), }, - []*v1.PersistentVolume{ + expectedVolumes: []*v1.PersistentVolume{ newVolume("volume13-2-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold), newVolume("volume13-2-2", "10Gi", "uid13-2", "claim13-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), }, - newClaimArray("claim13-2", "uid13-2", "1Gi", "", v1.ClaimPending, nil), - withExpectedCapacity("10Gi", newClaimArray("claim13-2", "uid13-2", "1Gi", "volume13-2-2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + initialClaims: newClaimArray("claim13-2", "uid13-2", "1Gi", "", v1.ClaimPending, nil), + expectedClaims: withExpectedCapacity("10Gi", newClaimArray("claim13-2", "uid13-2", "1Gi", "volume13-2-2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncVolume binds a claim with given class even if there is a // smaller PV with different class available - "13-3 - binding to specific a class", - []*v1.PersistentVolume{ + name: "13-3 - binding to specific a class", + initialVolumes: []*v1.PersistentVolume{ newVolume("volume13-3-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classSilver), newVolume("volume13-3-2", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold), }, - []*v1.PersistentVolume{ + expectedVolumes: []*v1.PersistentVolume{ newVolume("volume13-3-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classSilver), newVolume("volume13-3-2", "10Gi", "uid13-3", "claim13-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classGold, volume.AnnBoundByController), }, - newClaimArray("claim13-3", "uid13-3", "1Gi", "", v1.ClaimPending, &classGold), - withExpectedCapacity("10Gi", newClaimArray("claim13-3", "uid13-3", "1Gi", "volume13-3-2", v1.ClaimBound, &classGold, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + initialClaims: newClaimArray("claim13-3", "uid13-3", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: withExpectedCapacity("10Gi", newClaimArray("claim13-3", "uid13-3", "1Gi", "volume13-3-2", v1.ClaimBound, &classGold, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncVolume binds claim requesting class "" to claim to PV with // class="" - "13-4 - empty class", - newVolumeArray("volume13-4", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume13-4", "1Gi", "uid13-4", "claim13-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newClaimArray("claim13-4", "uid13-4", "1Gi", "", v1.ClaimPending, &classEmpty), - newClaimArray("claim13-4", "uid13-4", "1Gi", "volume13-4", v1.ClaimBound, &classEmpty, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "13-4 - empty class", + initialVolumes: newVolumeArray("volume13-4", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume13-4", "1Gi", "uid13-4", "claim13-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: newClaimArray("claim13-4", "uid13-4", "1Gi", "", v1.ClaimPending, &classEmpty), + expectedClaims: newClaimArray("claim13-4", "uid13-4", "1Gi", "volume13-4", v1.ClaimBound, &classEmpty, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncVolume binds claim requesting class nil to claim to PV with // class = "" - "13-5 - nil class", - newVolumeArray("volume13-5", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume13-5", "1Gi", "uid13-5", "claim13-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newClaimArray("claim13-5", "uid13-5", "1Gi", "", v1.ClaimPending, nil), - newClaimArray("claim13-5", "uid13-5", "1Gi", "volume13-5", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "13-5 - nil class", + initialVolumes: newVolumeArray("volume13-5", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume13-5", "1Gi", "uid13-5", "claim13-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: newClaimArray("claim13-5", "uid13-5", "1Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim13-5", "uid13-5", "1Gi", "volume13-5", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, } @@ -666,174 +767,201 @@ func TestSyncBlockVolume(t *testing.T) { // PVC with VolumeMode { // syncVolume binds a requested block claim to a block volume - "14-1 - binding to volumeMode block", - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-1", "10Gi", "uid14-1", "claim14-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-1", "uid14-1", "10Gi", "", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-1", "uid14-1", "10Gi", "volume14-1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + name: "14-1 - binding to volumeMode block", + initialVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + expectedVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-1", "10Gi", "uid14-1", "claim14-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + initialClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-1", "uid14-1", "10Gi", "", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-1", "uid14-1", "10Gi", "volume14-1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncVolume binds a requested filesystem claim to a filesystem volume - "14-2 - binding to volumeMode filesystem", - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-2", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-2", "10Gi", "uid14-2", "claim14-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-2", "uid14-2", "10Gi", "", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-2", "uid14-2", "10Gi", "volume14-2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + name: "14-2 - binding to volumeMode filesystem", + initialVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-2", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + expectedVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-2", "10Gi", "uid14-2", "claim14-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + initialClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-2", "uid14-2", "10Gi", "", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-2", "uid14-2", "10Gi", "volume14-2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // failed syncVolume do not bind to an unspecified volumemode for claim to a specified filesystem volume - "14-3 - do not bind pv volumeMode filesystem and pvc volumeMode block", - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-3", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-3", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-3", "uid14-3", "10Gi", "", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-3", "uid14-3", "10Gi", "", v1.ClaimPending, nil)), - []string{"Normal FailedBinding"}, - noerrors, testSyncClaim, + name: "14-3 - do not bind pv volumeMode filesystem and pvc volumeMode block", + initialVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-3", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + expectedVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-3", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + initialClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-3", "uid14-3", "10Gi", "", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-3", "uid14-3", "10Gi", "", v1.ClaimPending, nil)), + expectedEvents: []string{"Normal FailedBinding"}, + errors: noerrors, + test: testSyncClaim, }, { // failed syncVolume do not bind a requested filesystem claim to an unspecified volumeMode for volume - "14-4 - do not bind pv volumeMode block and pvc volumeMode filesystem", - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-4", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-4", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-4", "uid14-4", "10Gi", "", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-4", "uid14-4", "10Gi", "", v1.ClaimPending, nil)), - []string{"Normal FailedBinding"}, - noerrors, testSyncClaim, + name: "14-4 - do not bind pv volumeMode block and pvc volumeMode filesystem", + initialVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-4", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + expectedVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-4", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + initialClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-4", "uid14-4", "10Gi", "", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-4", "uid14-4", "10Gi", "", v1.ClaimPending, nil)), + expectedEvents: []string{"Normal FailedBinding"}, + errors: noerrors, + test: testSyncClaim, }, { // failed syncVolume do not bind when matching class but not matching volumeModes - "14-5 - do not bind when matching class but not volumeMode", - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-5", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold)), - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-5", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-5", "uid14-5", "10Gi", "", v1.ClaimPending, &classGold)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-5", "uid14-5", "10Gi", "", v1.ClaimPending, &classGold)), - []string{"Warning ProvisioningFailed"}, - noerrors, testSyncClaim, + name: "14-5 - do not bind when matching class but not volumeMode", + initialVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-5", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold)), + expectedVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-5", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold)), + initialClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-5", "uid14-5", "10Gi", "", v1.ClaimPending, &classGold)), + expectedClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-5", "uid14-5", "10Gi", "", v1.ClaimPending, &classGold)), + expectedEvents: []string{"Warning ProvisioningFailed"}, + errors: noerrors, + test: testSyncClaim, }, { // failed syncVolume do not bind when matching volumeModes but class does not match - "14-5-1 - do not bind when matching volumeModes but class does not match", - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-5-1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold)), - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-5-1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-5-1", "uid14-5-1", "10Gi", "", v1.ClaimPending, &classSilver)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-5-1", "uid14-5-1", "10Gi", "", v1.ClaimPending, &classSilver)), - []string{"Warning ProvisioningFailed"}, - noerrors, testSyncClaim, + name: "14-5-1 - do not bind when matching volumeModes but class does not match", + initialVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-5-1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold)), + expectedVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-5-1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold)), + initialClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-5-1", "uid14-5-1", "10Gi", "", v1.ClaimPending, &classSilver)), + expectedClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-5-1", "uid14-5-1", "10Gi", "", v1.ClaimPending, &classSilver)), + expectedEvents: []string{"Warning ProvisioningFailed"}, + errors: noerrors, + test: testSyncClaim, }, { // failed syncVolume do not bind when pvc is prebound to pv with matching volumeModes but class does not match - "14-5-2 - do not bind when pvc is prebound to pv with matching volumeModes but class does not match", - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-5-2", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold)), - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-5-2", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-5-2", "uid14-5-2", "10Gi", "volume14-5-2", v1.ClaimPending, &classSilver)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-5-2", "uid14-5-2", "10Gi", "volume14-5-2", v1.ClaimPending, &classSilver)), - []string{"Warning VolumeMismatch"}, - noerrors, testSyncClaim, + name: "14-5-2 - do not bind when pvc is prebound to pv with matching volumeModes but class does not match", + initialVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-5-2", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold)), + expectedVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-5-2", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold)), + initialClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-5-2", "uid14-5-2", "10Gi", "volume14-5-2", v1.ClaimPending, &classSilver)), + expectedClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-5-2", "uid14-5-2", "10Gi", "volume14-5-2", v1.ClaimPending, &classSilver)), + expectedEvents: []string{"Warning VolumeMismatch"}, + errors: noerrors, + test: testSyncClaim, }, { // syncVolume bind when pv is prebound and volumeModes match - "14-7 - bind when pv volume is prebound and volumeModes match", - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-7", "10Gi", "", "claim14-7", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-7", "10Gi", "uid14-7", "claim14-7", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-7", "uid14-7", "10Gi", "", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-7", "uid14-7", "10Gi", "volume14-7", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + name: "14-7 - bind when pv volume is prebound and volumeModes match", + initialVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-7", "10Gi", "", "claim14-7", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + expectedVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-7", "10Gi", "uid14-7", "claim14-7", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty)), + initialClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-7", "uid14-7", "10Gi", "", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-7", "uid14-7", "10Gi", "volume14-7", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // failed syncVolume do not bind when pvc is prebound to pv with mismatching volumeModes - "14-8 - do not bind when pvc is prebound to pv with mismatching volumeModes", - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-8", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-8", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-8", "uid14-8", "10Gi", "volume14-8", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-8", "uid14-8", "10Gi", "volume14-8", v1.ClaimPending, nil)), - []string{"Warning VolumeMismatch"}, - noerrors, testSyncClaim, + name: "14-8 - do not bind when pvc is prebound to pv with mismatching volumeModes", + initialVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-8", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + expectedVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-8", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + initialClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-8", "uid14-8", "10Gi", "volume14-8", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-8", "uid14-8", "10Gi", "volume14-8", v1.ClaimPending, nil)), + expectedEvents: []string{"Warning VolumeMismatch"}, + errors: noerrors, + test: testSyncClaim, }, { // failed syncVolume do not bind when pvc is prebound to pv with mismatching volumeModes - "14-8-1 - do not bind when pvc is prebound to pv with mismatching volumeModes", - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-8-1", "10Gi", "", "claim14-8-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-8-1", "10Gi", "", "claim14-8-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-8-1", "uid14-8-1", "10Gi", "", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-8-1", "uid14-8-1", "10Gi", "", v1.ClaimPending, nil)), - []string{"Normal FailedBinding"}, - noerrors, testSyncClaim, + name: "14-8-1 - do not bind when pvc is prebound to pv with mismatching volumeModes", + initialVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-8-1", "10Gi", "", "claim14-8-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + expectedVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-8-1", "10Gi", "", "claim14-8-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + initialClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-8-1", "uid14-8-1", "10Gi", "", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-8-1", "uid14-8-1", "10Gi", "", v1.ClaimPending, nil)), + expectedEvents: []string{"Normal FailedBinding"}, + errors: noerrors, + test: testSyncClaim, }, { // syncVolume binds when pvc is prebound to pv with matching volumeModes block - "14-9 - bind when pvc is prebound to pv with matching volumeModes block", - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-9", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-9", "10Gi", "uid14-9", "claim14-9", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-9", "uid14-9", "10Gi", "volume14-9", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-9", "uid14-9", "10Gi", "volume14-9", v1.ClaimBound, nil, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + name: "14-9 - bind when pvc is prebound to pv with matching volumeModes block", + initialVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-9", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + expectedVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-9", "10Gi", "uid14-9", "claim14-9", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + initialClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-9", "uid14-9", "10Gi", "volume14-9", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-9", "uid14-9", "10Gi", "volume14-9", v1.ClaimBound, nil, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncVolume binds when pv is prebound to pvc with matching volumeModes block - "14-10 - bind when pv is prebound to pvc with matching volumeModes block", - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-10", "10Gi", "", "claim14-10", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-10", "10Gi", "uid14-10", "claim14-10", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-10", "uid14-10", "10Gi", "", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-10", "uid14-10", "10Gi", "volume14-10", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + name: "14-10 - bind when pv is prebound to pvc with matching volumeModes block", + initialVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-10", "10Gi", "", "claim14-10", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + expectedVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-10", "10Gi", "uid14-10", "claim14-10", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty)), + initialClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-10", "uid14-10", "10Gi", "", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-10", "uid14-10", "10Gi", "volume14-10", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncVolume binds when pvc is prebound to pv with matching volumeModes filesystem - "14-11 - bind when pvc is prebound to pv with matching volumeModes filesystem", - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-11", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-11", "10Gi", "uid14-11", "claim14-11", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-11", "uid14-11", "10Gi", "volume14-11", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-11", "uid14-11", "10Gi", "volume14-11", v1.ClaimBound, nil, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + name: "14-11 - bind when pvc is prebound to pv with matching volumeModes filesystem", + initialVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-11", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + expectedVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-11", "10Gi", "uid14-11", "claim14-11", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + initialClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-11", "uid14-11", "10Gi", "volume14-11", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-11", "uid14-11", "10Gi", "volume14-11", v1.ClaimBound, nil, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncVolume binds when pv is prebound to pvc with matching volumeModes filesystem - "14-12 - bind when pv is prebound to pvc with matching volumeModes filesystem", - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-12", "10Gi", "", "claim14-12", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-12", "10Gi", "uid14-12", "claim14-12", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-12", "uid14-12", "10Gi", "", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-12", "uid14-12", "10Gi", "volume14-12", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, testSyncClaim, + name: "14-12 - bind when pv is prebound to pvc with matching volumeModes filesystem", + initialVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-12", "10Gi", "", "claim14-12", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty)), + expectedVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-12", "10Gi", "uid14-12", "claim14-12", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty)), + initialClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-12", "uid14-12", "10Gi", "", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-12", "uid14-12", "10Gi", "volume14-12", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // syncVolume output warning when pv is prebound to pvc with mismatching volumeMode - "14-13 - output warning when pv is prebound to pvc with different volumeModes", - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-13", "10Gi", "uid14-13", "claim14-13", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-13", "10Gi", "uid14-13", "claim14-13", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-13", "uid14-13", "10Gi", "", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-13", "uid14-13", "10Gi", "", v1.ClaimPending, nil)), - []string{"Warning VolumeMismatch"}, - noerrors, testSyncVolume, + name: "14-13 - output warning when pv is prebound to pvc with different volumeModes", + initialVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-13", "10Gi", "uid14-13", "claim14-13", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + expectedVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-13", "10Gi", "uid14-13", "claim14-13", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + initialClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-13", "uid14-13", "10Gi", "", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-13", "uid14-13", "10Gi", "", v1.ClaimPending, nil)), + expectedEvents: []string{"Warning VolumeMismatch"}, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume output warning when pv is prebound to pvc with mismatching volumeMode - "14-13-1 - output warning when pv is prebound to pvc with different volumeModes", - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-13-1", "10Gi", "uid14-13-1", "claim14-13-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-13-1", "10Gi", "uid14-13-1", "claim14-13-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-13-1", "uid14-13-1", "10Gi", "", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-13-1", "uid14-13-1", "10Gi", "", v1.ClaimPending, nil)), - []string{"Warning VolumeMismatch"}, - noerrors, testSyncVolume, + name: "14-13-1 - output warning when pv is prebound to pvc with different volumeModes", + initialVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-13-1", "10Gi", "uid14-13-1", "claim14-13-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + expectedVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-13-1", "10Gi", "uid14-13-1", "claim14-13-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + initialClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-13-1", "uid14-13-1", "10Gi", "", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-13-1", "uid14-13-1", "10Gi", "", v1.ClaimPending, nil)), + expectedEvents: []string{"Warning VolumeMismatch"}, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume waits for synClaim without warning when pv is prebound to pvc with matching volumeMode block - "14-14 - wait for synClaim without warning when pv is prebound to pvc with matching volumeModes block", - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-14", "10Gi", "uid14-14", "claim14-14", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-14", "10Gi", "uid14-14", "claim14-14", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-14", "uid14-14", "10Gi", "", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeBlock, newClaimArray("claim14-14", "uid14-14", "10Gi", "", v1.ClaimPending, nil)), - noevents, noerrors, testSyncVolume, + name: "14-14 - wait for synClaim without warning when pv is prebound to pvc with matching volumeModes block", + initialVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-14", "10Gi", "uid14-14", "claim14-14", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + expectedVolumes: withVolumeVolumeMode(&modeBlock, newVolumeArray("volume14-14", "10Gi", "uid14-14", "claim14-14", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + initialClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-14", "uid14-14", "10Gi", "", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeBlock, newClaimArray("claim14-14", "uid14-14", "10Gi", "", v1.ClaimPending, nil)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, { // syncVolume waits for synClaim without warning when pv is prebound to pvc with matching volumeMode file - "14-14-1 - wait for synClaim without warning when pv is prebound to pvc with matching volumeModes file", - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-14-1", "10Gi", "uid14-14-1", "claim14-14-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-14-1", "10Gi", "uid14-14-1", "claim14-14-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-14-1", "uid14-14-1", "10Gi", "", v1.ClaimPending, nil)), - withClaimVolumeMode(&modeFile, newClaimArray("claim14-14-1", "uid14-14-1", "10Gi", "", v1.ClaimPending, nil)), - noevents, noerrors, testSyncVolume, + name: "14-14-1 - wait for synClaim without warning when pv is prebound to pvc with matching volumeModes file", + initialVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-14-1", "10Gi", "uid14-14-1", "claim14-14-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + expectedVolumes: withVolumeVolumeMode(&modeFile, newVolumeArray("volume14-14-1", "10Gi", "uid14-14-1", "claim14-14-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + initialClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-14-1", "uid14-14-1", "10Gi", "", v1.ClaimPending, nil)), + expectedClaims: withClaimVolumeMode(&modeFile, newClaimArray("claim14-14-1", "uid14-14-1", "10Gi", "", v1.ClaimPending, nil)), + expectedEvents: noevents, + errors: noerrors, + test: testSyncVolume, }, } @@ -860,28 +988,32 @@ func TestMultiSync(t *testing.T) { // Test simple binding { // syncClaim binds to a matching unbound volume. - "10-1 - successful bind", - newVolumeArray("volume10-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume10-1", "1Gi", "uid10-1", "claim10-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newClaimArray("claim10-1", "uid10-1", "1Gi", "", v1.ClaimPending, nil), - newClaimArray("claim10-1", "uid10-1", "1Gi", "volume10-1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + name: "10-1 - successful bind", + initialVolumes: newVolumeArray("volume10-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume10-1", "1Gi", "uid10-1", "claim10-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: newClaimArray("claim10-1", "uid10-1", "1Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim10-1", "uid10-1", "1Gi", "volume10-1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, { // Two controllers bound two PVs to single claim. Test one of them // wins and the second rolls back. - "10-2 - bind PV race", - []*v1.PersistentVolume{ + name: "10-2 - bind PV race", + initialVolumes: []*v1.PersistentVolume{ newVolume("volume10-2-1", "1Gi", "uid10-2", "claim10-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), newVolume("volume10-2-2", "1Gi", "uid10-2", "claim10-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), }, - []*v1.PersistentVolume{ + expectedVolumes: []*v1.PersistentVolume{ newVolume("volume10-2-1", "1Gi", "uid10-2", "claim10-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), newVolume("volume10-2-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), }, - newClaimArray("claim10-2", "uid10-2", "1Gi", "volume10-2-1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - newClaimArray("claim10-2", "uid10-2", "1Gi", "volume10-2-1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, testSyncClaim, + initialClaims: newClaimArray("claim10-2", "uid10-2", "1Gi", "volume10-2-1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedClaims: newClaimArray("claim10-2", "uid10-2", "1Gi", "volume10-2-1", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: testSyncClaim, }, } diff --git a/pkg/controller/volume/persistentvolume/delete_test.go b/pkg/controller/volume/persistentvolume/delete_test.go index 0ff670c5fad..a07bc148bc5 100644 --- a/pkg/controller/volume/persistentvolume/delete_test.go +++ b/pkg/controller/volume/persistentvolume/delete_test.go @@ -40,66 +40,73 @@ func TestDeleteSync(t *testing.T) { tests := []controllerTest{ { // delete volume bound by controller - "8-1 - successful delete", - newVolumeArray("volume8-1", "1Gi", "uid8-1", "claim8-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnBoundByController), - novolumes, - noclaims, - noclaims, - noevents, noerrors, + name: "8-1 - successful delete", + initialVolumes: newVolumeArray("volume8-1", "1Gi", "uid8-1", "claim8-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnBoundByController), + expectedVolumes: novolumes, + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, // Inject deleter into the controller and call syncVolume. The // deleter simulates one delete() call that succeeds. - wrapTestWithReclaimCalls(operationDelete, []error{nil}, testSyncVolume), + test: wrapTestWithReclaimCalls(operationDelete, []error{nil}, testSyncVolume), }, { // delete volume bound by user - "8-2 - successful delete with prebound volume", - newVolumeArray("volume8-2", "1Gi", "uid8-2", "claim8-2", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), - novolumes, - noclaims, - noclaims, - noevents, noerrors, + name: "8-2 - successful delete with prebound volume", + initialVolumes: newVolumeArray("volume8-2", "1Gi", "uid8-2", "claim8-2", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), + expectedVolumes: novolumes, + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, // Inject deleter into the controller and call syncVolume. The // deleter simulates one delete() call that succeeds. - wrapTestWithReclaimCalls(operationDelete, []error{nil}, testSyncVolume), + test: wrapTestWithReclaimCalls(operationDelete, []error{nil}, testSyncVolume), }, { // delete failure - plugin not found - "8-3 - plugin not found", - newVolumeArray("volume8-3", "1Gi", "uid8-3", "claim8-3", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), - withMessage("error getting deleter volume plugin for volume \"volume8-3\": no volume plugin matched", newVolumeArray("volume8-3", "1Gi", "uid8-3", "claim8-3", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete, classEmpty)), - noclaims, - noclaims, - []string{"Warning VolumeFailedDelete"}, noerrors, testSyncVolume, + name: "8-3 - plugin not found", + initialVolumes: newVolumeArray("volume8-3", "1Gi", "uid8-3", "claim8-3", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), + expectedVolumes: withMessage("error getting deleter volume plugin for volume \"volume8-3\": no volume plugin matched", newVolumeArray("volume8-3", "1Gi", "uid8-3", "claim8-3", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete, classEmpty)), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: []string{"Warning VolumeFailedDelete"}, + errors: noerrors, + test: testSyncVolume, }, { // delete failure - newDeleter returns error - "8-4 - newDeleter returns error", - newVolumeArray("volume8-4", "1Gi", "uid8-4", "claim8-4", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), - withMessage("failed to create deleter for volume \"volume8-4\": Mock plugin error: no deleteCalls configured", newVolumeArray("volume8-4", "1Gi", "uid8-4", "claim8-4", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete, classEmpty)), - noclaims, - noclaims, - []string{"Warning VolumeFailedDelete"}, noerrors, - wrapTestWithReclaimCalls(operationDelete, []error{}, testSyncVolume), + name: "8-4 - newDeleter returns error", + initialVolumes: newVolumeArray("volume8-4", "1Gi", "uid8-4", "claim8-4", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), + expectedVolumes: withMessage("failed to create deleter for volume \"volume8-4\": Mock plugin error: no deleteCalls configured", newVolumeArray("volume8-4", "1Gi", "uid8-4", "claim8-4", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete, classEmpty)), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: []string{"Warning VolumeFailedDelete"}, + errors: noerrors, + test: wrapTestWithReclaimCalls(operationDelete, []error{}, testSyncVolume), }, { // delete failure - delete() returns error - "8-5 - delete returns error", - newVolumeArray("volume8-5", "1Gi", "uid8-5", "claim8-5", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), - withMessage("Mock delete error", newVolumeArray("volume8-5", "1Gi", "uid8-5", "claim8-5", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete, classEmpty)), - noclaims, - noclaims, - []string{"Warning VolumeFailedDelete"}, noerrors, - wrapTestWithReclaimCalls(operationDelete, []error{errors.New("Mock delete error")}, testSyncVolume), + name: "8-5 - delete returns error", + initialVolumes: newVolumeArray("volume8-5", "1Gi", "uid8-5", "claim8-5", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), + expectedVolumes: withMessage("Mock delete error", newVolumeArray("volume8-5", "1Gi", "uid8-5", "claim8-5", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete, classEmpty)), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: []string{"Warning VolumeFailedDelete"}, + errors: noerrors, + test: wrapTestWithReclaimCalls(operationDelete, []error{errors.New("Mock delete error")}, testSyncVolume), }, { // delete success(?) - volume is deleted before doDelete() starts - "8-6 - volume is deleted before deleting", - newVolumeArray("volume8-6", "1Gi", "uid8-6", "claim8-6", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), - novolumes, - noclaims, - noclaims, - noevents, noerrors, - wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationDelete, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { + name: "8-6 - volume is deleted before deleting", + initialVolumes: newVolumeArray("volume8-6", "1Gi", "uid8-6", "claim8-6", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), + expectedVolumes: novolumes, + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationDelete, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { // Delete the volume before delete operation starts reactor.DeleteVolume("volume8-6") }), @@ -108,13 +115,14 @@ func TestDeleteSync(t *testing.T) { // delete success(?) - volume is bound just at the time doDelete() // starts. This simulates "volume no longer needs recycling, // skipping". - "8-7 - volume is bound before deleting", - newVolumeArray("volume8-7", "1Gi", "uid8-7", "claim8-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume8-7", "1Gi", "uid8-7", "claim8-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnBoundByController), - noclaims, - newClaimArray("claim8-7", "uid8-7", "10Gi", "volume8-7", v1.ClaimBound, nil), - noevents, noerrors, - wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationDelete, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { + name: "8-7 - volume is bound before deleting", + initialVolumes: newVolumeArray("volume8-7", "1Gi", "uid8-7", "claim8-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume8-7", "1Gi", "uid8-7", "claim8-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnBoundByController), + initialClaims: noclaims, + expectedClaims: newClaimArray("claim8-7", "uid8-7", "10Gi", "volume8-7", v1.ClaimBound, nil), + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationDelete, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { // Bind the volume to resurrected claim (this should never // happen) claim := newClaim("claim8-7", "uid8-7", "10Gi", "volume8-7", v1.ClaimBound, nil) @@ -125,25 +133,27 @@ func TestDeleteSync(t *testing.T) { { // delete success - volume bound by user is deleted, while a new // claim is created with another UID. - "8-9 - prebound volume is deleted while the claim exists", - newVolumeArray("volume8-9", "1Gi", "uid8-9", "claim8-9", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), - novolumes, - newClaimArray("claim8-9", "uid8-9-x", "10Gi", "", v1.ClaimPending, nil), - newClaimArray("claim8-9", "uid8-9-x", "10Gi", "", v1.ClaimPending, nil), - noevents, noerrors, + name: "8-9 - prebound volume is deleted while the claim exists", + initialVolumes: newVolumeArray("volume8-9", "1Gi", "uid8-9", "claim8-9", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim8-9", "uid8-9-x", "10Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim8-9", "uid8-9-x", "10Gi", "", v1.ClaimPending, nil), + expectedEvents: noevents, + errors: noerrors, // Inject deleter into the controller and call syncVolume. The // deleter simulates one delete() call that succeeds. - wrapTestWithReclaimCalls(operationDelete, []error{nil}, testSyncVolume), + test: wrapTestWithReclaimCalls(operationDelete, []error{nil}, testSyncVolume), }, { // PV requires external deleter - "8-10 - external deleter", - []*v1.PersistentVolume{newExternalProvisionedVolume("volume8-10", "1Gi", "uid10-1", "claim10-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, gceDriver, nil, volume.AnnBoundByController)}, - []*v1.PersistentVolume{newExternalProvisionedVolume("volume8-10", "1Gi", "uid10-1", "claim10-1", v1.VolumeReleased, v1.PersistentVolumeReclaimDelete, classEmpty, gceDriver, nil, volume.AnnBoundByController)}, - noclaims, - noclaims, - noevents, noerrors, - func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { + name: "8-10 - external deleter", + initialVolumes: []*v1.PersistentVolume{newExternalProvisionedVolume("volume8-10", "1Gi", "uid10-1", "claim10-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, gceDriver, nil, volume.AnnBoundByController)}, + expectedVolumes: []*v1.PersistentVolume{newExternalProvisionedVolume("volume8-10", "1Gi", "uid10-1", "claim10-1", v1.VolumeReleased, v1.PersistentVolumeReclaimDelete, classEmpty, gceDriver, nil, volume.AnnBoundByController)}, + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, + test: func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { // Inject external deleter annotation test.initialVolumes[0].Annotations[volume.AnnDynamicallyProvisioned] = "external.io/test" test.expectedVolumes[0].Annotations[volume.AnnDynamicallyProvisioned] = "external.io/test" @@ -153,40 +163,42 @@ func TestDeleteSync(t *testing.T) { { // delete success - two PVs are provisioned for a single claim. // One of the PVs is deleted. - "8-11 - two PVs provisioned for a single claim", - []*v1.PersistentVolume{ + name: "8-11 - two PVs provisioned for a single claim", + initialVolumes: []*v1.PersistentVolume{ newVolume("volume8-11-1", "1Gi", "uid8-11", "claim8-11", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnDynamicallyProvisioned), newVolume("volume8-11-2", "1Gi", "uid8-11", "claim8-11", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnDynamicallyProvisioned), }, - []*v1.PersistentVolume{ + expectedVolumes: []*v1.PersistentVolume{ newVolume("volume8-11-2", "1Gi", "uid8-11", "claim8-11", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnDynamicallyProvisioned), }, // the claim is bound to volume8-11-2 -> volume8-11-1 has lost the race and will be deleted - newClaimArray("claim8-11", "uid8-11", "10Gi", "volume8-11-2", v1.ClaimBound, nil), - newClaimArray("claim8-11", "uid8-11", "10Gi", "volume8-11-2", v1.ClaimBound, nil), - noevents, noerrors, + initialClaims: newClaimArray("claim8-11", "uid8-11", "10Gi", "volume8-11-2", v1.ClaimBound, nil), + expectedClaims: newClaimArray("claim8-11", "uid8-11", "10Gi", "volume8-11-2", v1.ClaimBound, nil), + expectedEvents: noevents, + errors: noerrors, // Inject deleter into the controller and call syncVolume. The // deleter simulates one delete() call that succeeds. - wrapTestWithReclaimCalls(operationDelete, []error{nil}, testSyncVolume), + test: wrapTestWithReclaimCalls(operationDelete, []error{nil}, testSyncVolume), }, { // delete success - two PVs are externally provisioned for a single // claim. One of the PVs is marked as Released to be deleted by the // external provisioner. - "8-12 - two PVs externally provisioned for a single claim", - []*v1.PersistentVolume{ + name: "8-12 - two PVs externally provisioned for a single claim", + initialVolumes: []*v1.PersistentVolume{ newExternalProvisionedVolume("volume8-12-1", "1Gi", "uid8-12", "claim8-12", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, gceDriver, nil, volume.AnnDynamicallyProvisioned), newExternalProvisionedVolume("volume8-12-2", "1Gi", "uid8-12", "claim8-12", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, gceDriver, nil, volume.AnnDynamicallyProvisioned), }, - []*v1.PersistentVolume{ + expectedVolumes: []*v1.PersistentVolume{ newExternalProvisionedVolume("volume8-12-1", "1Gi", "uid8-12", "claim8-12", v1.VolumeReleased, v1.PersistentVolumeReclaimDelete, classEmpty, gceDriver, nil, volume.AnnDynamicallyProvisioned), newExternalProvisionedVolume("volume8-12-2", "1Gi", "uid8-12", "claim8-12", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, gceDriver, nil, volume.AnnDynamicallyProvisioned), }, // the claim is bound to volume8-12-2 -> volume8-12-1 has lost the race and will be "Released" - newClaimArray("claim8-12", "uid8-12", "10Gi", "volume8-12-2", v1.ClaimBound, nil), - newClaimArray("claim8-12", "uid8-12", "10Gi", "volume8-12-2", v1.ClaimBound, nil), - noevents, noerrors, - func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { + initialClaims: newClaimArray("claim8-12", "uid8-12", "10Gi", "volume8-12-2", v1.ClaimBound, nil), + expectedClaims: newClaimArray("claim8-12", "uid8-12", "10Gi", "volume8-12-2", v1.ClaimBound, nil), + expectedEvents: noevents, + errors: noerrors, + test: func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { // Inject external deleter annotation test.initialVolumes[0].Annotations[volume.AnnDynamicallyProvisioned] = "external.io/test" test.expectedVolumes[0].Annotations[volume.AnnDynamicallyProvisioned] = "external.io/test" @@ -195,13 +207,14 @@ func TestDeleteSync(t *testing.T) { }, { // delete success - volume has deletion timestamp before doDelete() starts - "8-13 - volume has deletion timestamp and processed", - volumesWithFinalizers(withVolumeDeletionTimestamp(newVolumeArray("volume8-13", "1Gi", "uid8-13", "claim8-13", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnBoundByController)), []string{volume.PVDeletionInTreeProtectionFinalizer}), - novolumes, - noclaims, - noclaims, - noevents, noerrors, - wrapTestWithReclaimCalls(operationDelete, []error{nil}, testSyncVolume), + name: "8-13 - volume has deletion timestamp and processed", + initialVolumes: volumesWithFinalizers(withVolumeDeletionTimestamp(newVolumeArray("volume8-13", "1Gi", "uid8-13", "claim8-13", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnBoundByController)), []string{volume.PVDeletionInTreeProtectionFinalizer}), + expectedVolumes: novolumes, + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithReclaimCalls(operationDelete, []error{nil}, testSyncVolume), }, } runSyncTests(t, tests, []*storage.StorageClass{}, []*v1.Pod{}) @@ -227,13 +240,14 @@ func TestDeleteMultiSync(t *testing.T) { { // delete failure - delete returns error. The controller should // try again. - "9-1 - delete returns error", - volumesWithFinalizers(newVolumeArray("volume9-1", "1Gi", "uid9-1", "claim9-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), []string{volume.PVDeletionInTreeProtectionFinalizer}), - novolumes, - noclaims, - noclaims, - []string{"Warning VolumeFailedDelete"}, noerrors, - wrapTestWithReclaimCalls(operationDelete, []error{errors.New("Mock delete error"), nil}, testSyncVolume), + name: "9-1 - delete returns error", + initialVolumes: volumesWithFinalizers(newVolumeArray("volume9-1", "1Gi", "uid9-1", "claim9-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), []string{volume.PVDeletionInTreeProtectionFinalizer}), + expectedVolumes: novolumes, + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: []string{"Warning VolumeFailedDelete"}, + errors: noerrors, + test: wrapTestWithReclaimCalls(operationDelete, []error{errors.New("Mock delete error"), nil}, testSyncVolume), }, } diff --git a/pkg/controller/volume/persistentvolume/provision_test.go b/pkg/controller/volume/persistentvolume/provision_test.go index 68903f450b3..a3a0b357877 100644 --- a/pkg/controller/volume/persistentvolume/provision_test.go +++ b/pkg/controller/volume/persistentvolume/provision_test.go @@ -19,6 +19,7 @@ package persistentvolume import ( "context" "errors" + utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" "k8s.io/kubernetes/pkg/features" @@ -175,67 +176,74 @@ func TestProvisionSync(t *testing.T) { tests := []controllerTest{ { // Provision a volume (with a default class) - "11-1 - successful provision with storage class 1", - novolumes, - volumesWithFinalizers(newVolumeArray("pvc-uid11-1", "1Gi", "uid11-1", "claim11-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned), []string{volume.PVDeletionInTreeProtectionFinalizer}), - newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, &classGold), + name: "11-1 - successful provision with storage class 1", + initialVolumes: novolumes, + expectedVolumes: volumesWithFinalizers(newVolumeArray("pvc-uid11-1", "1Gi", "uid11-1", "claim11-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned), []string{volume.PVDeletionInTreeProtectionFinalizer}), // Binding will be completed in the next syncClaim - newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), - []string{"Normal ProvisioningSucceeded"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), + initialClaims: newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), + expectedEvents: []string{"Normal ProvisioningSucceeded"}, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), }, { // Provision failure - plugin not found - "11-2 - plugin not found", - novolumes, - novolumes, - newClaimArray("claim11-2", "uid11-2", "1Gi", "", v1.ClaimPending, &classGold), - newClaimArray("claim11-2", "uid11-2", "1Gi", "", v1.ClaimPending, &classGold), - []string{"Warning ProvisioningFailed"}, noerrors, - testSyncClaim, + name: "11-2 - plugin not found", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-2", "uid11-2", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: newClaimArray("claim11-2", "uid11-2", "1Gi", "", v1.ClaimPending, &classGold), + expectedEvents: []string{"Warning ProvisioningFailed"}, + errors: noerrors, + test: testSyncClaim, }, { // Provision failure - newProvisioner returns error - "11-3 - newProvisioner failure", - novolumes, - novolumes, - newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, &classGold), - newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), - []string{"Warning ProvisioningFailed"}, noerrors, - wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), + name: "11-3 - newProvisioner failure", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), + expectedEvents: []string{"Warning ProvisioningFailed"}, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, { // Provision failure - Provision returns error - "11-4 - provision failure", - novolumes, - novolumes, - newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, &classGold), - newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), - []string{"Warning ProvisioningFailed"}, noerrors, - wrapTestWithProvisionCalls([]provisionCall{provision1Error}, testSyncClaim), + name: "11-4 - provision failure", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), + expectedEvents: []string{"Warning ProvisioningFailed"}, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{provision1Error}, testSyncClaim), }, { // No provisioning if there is a matching volume available - "11-6 - provisioning when there is a volume available", - newVolumeArray("volume11-6", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold), - newVolumeArray("volume11-6", "1Gi", "uid11-6", "claim11-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classGold, volume.AnnBoundByController), - newClaimArray("claim11-6", "uid11-6", "1Gi", "", v1.ClaimPending, &classGold), - newClaimArray("claim11-6", "uid11-6", "1Gi", "volume11-6", v1.ClaimBound, &classGold, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, + name: "11-6 - provisioning when there is a volume available", + initialVolumes: newVolumeArray("volume11-6", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classGold), + expectedVolumes: newVolumeArray("volume11-6", "1Gi", "uid11-6", "claim11-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classGold, volume.AnnBoundByController), + initialClaims: newClaimArray("claim11-6", "uid11-6", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: newClaimArray("claim11-6", "uid11-6", "1Gi", "volume11-6", v1.ClaimBound, &classGold, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, // No provisioning plugin confingure - makes the test fail when // the controller erroneously tries to provision something - wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), + test: wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), }, { // Provision success? - claim is bound before provisioner creates // a volume. - "11-7 - claim is bound before provisioning", - novolumes, - newVolumeArray("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned), - newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, &classGold), + name: "11-7 - claim is bound before provisioning", + initialVolumes: novolumes, + expectedVolumes: newVolumeArray("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned), + initialClaims: newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, &classGold), // The claim would be bound in next syncClaim - newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), - noevents, noerrors, - wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { + expectedClaims: newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { // Create a volume before provisionClaimOperation starts. // This similates a parallel controller provisioning the volume. volume := newVolume("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned) @@ -245,31 +253,31 @@ func TestProvisionSync(t *testing.T) { { // Provision success - cannot save provisioned PV once, // second retry succeeds - "11-8 - cannot save provisioned volume", - novolumes, - volumesWithFinalizers(newVolumeArray("pvc-uid11-8", "1Gi", "uid11-8", "claim11-8", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned), []string{volume.PVDeletionInTreeProtectionFinalizer}), - newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, &classGold), + name: "11-8 - cannot save provisioned volume", + initialVolumes: novolumes, + expectedVolumes: volumesWithFinalizers(newVolumeArray("pvc-uid11-8", "1Gi", "uid11-8", "claim11-8", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned), []string{volume.PVDeletionInTreeProtectionFinalizer}), + initialClaims: newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, &classGold), // Binding will be completed in the next syncClaim - newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), - []string{"Normal ProvisioningSucceeded"}, - []pvtesting.ReactorError{ + expectedClaims: newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), + expectedEvents: []string{"Normal ProvisioningSucceeded"}, + errors: []pvtesting.ReactorError{ // Inject error to the first // kubeclient.PersistentVolumes.Create() call. All other calls // will succeed. {Verb: "create", Resource: "persistentvolumes", Error: errors.New("Mock creation error")}, }, - wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), + test: wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), }, { // Provision success? - cannot save provisioned PV five times, // volume is deleted and delete succeeds - "11-9 - cannot save provisioned volume, delete succeeds", - novolumes, - novolumes, - newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, &classGold), - newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), - []string{"Warning ProvisioningFailed"}, - []pvtesting.ReactorError{ + name: "11-9 - cannot save provisioned volume, delete succeeds", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), + expectedEvents: []string{"Warning ProvisioningFailed"}, + errors: []pvtesting.ReactorError{ // Inject error to five kubeclient.PersistentVolumes.Create() // calls {Verb: "create", Resource: "persistentvolumes", Error: errors.New("Mock creation error1")}, @@ -278,7 +286,7 @@ func TestProvisionSync(t *testing.T) { {Verb: "create", Resource: "persistentvolumes", Error: errors.New("Mock creation error4")}, {Verb: "create", Resource: "persistentvolumes", Error: errors.New("Mock creation error5")}, }, - wrapTestWithPluginCalls( + test: wrapTestWithPluginCalls( nil, // recycle calls []error{nil}, // delete calls []provisionCall{provision1Success}, // provision calls @@ -288,13 +296,13 @@ func TestProvisionSync(t *testing.T) { { // Provision failure - cannot save provisioned PV five times, // volume delete failed - no plugin found - "11-10 - cannot save provisioned volume, no delete plugin found", - novolumes, - novolumes, - newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, &classGold), - newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), - []string{"Warning ProvisioningFailed", "Warning ProvisioningCleanupFailed"}, - []pvtesting.ReactorError{ + name: "11-10 - cannot save provisioned volume, no delete plugin found", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), + expectedEvents: []string{"Warning ProvisioningFailed", "Warning ProvisioningCleanupFailed"}, + errors: []pvtesting.ReactorError{ // Inject error to five kubeclient.PersistentVolumes.Create() // calls {Verb: "create", Resource: "persistentvolumes", Error: errors.New("Mock creation error1")}, @@ -304,18 +312,18 @@ func TestProvisionSync(t *testing.T) { {Verb: "create", Resource: "persistentvolumes", Error: errors.New("Mock creation error5")}, }, // No deleteCalls are configured, which results into no deleter plugin available for the volume - wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), + test: wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), }, { // Provision failure - cannot save provisioned PV five times, // volume delete failed - deleter returns error five times - "11-11 - cannot save provisioned volume, deleter fails", - novolumes, - novolumes, - newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, &classGold), - newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), - []string{"Warning ProvisioningFailed", "Warning ProvisioningCleanupFailed"}, - []pvtesting.ReactorError{ + name: "11-11 - cannot save provisioned volume, deleter fails", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), + expectedEvents: []string{"Warning ProvisioningFailed", "Warning ProvisioningCleanupFailed"}, + errors: []pvtesting.ReactorError{ // Inject error to five kubeclient.PersistentVolumes.Create() // calls {Verb: "create", Resource: "persistentvolumes", Error: errors.New("Mock creation error1")}, @@ -324,7 +332,7 @@ func TestProvisionSync(t *testing.T) { {Verb: "create", Resource: "persistentvolumes", Error: errors.New("Mock creation error4")}, {Verb: "create", Resource: "persistentvolumes", Error: errors.New("Mock creation error5")}, }, - wrapTestWithPluginCalls( + test: wrapTestWithPluginCalls( nil, // recycle calls []error{ // delete calls errors.New("Mock deletion error1"), @@ -339,13 +347,13 @@ func TestProvisionSync(t *testing.T) { { // Provision failure - cannot save provisioned PV five times, // volume delete succeeds 2nd time - "11-12 - cannot save provisioned volume, delete succeeds 2nd time", - novolumes, - novolumes, - newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, &classGold), - newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), - []string{"Warning ProvisioningFailed"}, - []pvtesting.ReactorError{ + name: "11-12 - cannot save provisioned volume, delete succeeds 2nd time", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, &classGold, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), + expectedEvents: []string{"Warning ProvisioningFailed"}, + errors: []pvtesting.ReactorError{ // Inject error to five kubeclient.PersistentVolumes.Create() // calls {Verb: "create", Resource: "persistentvolumes", Error: errors.New("Mock creation error1")}, @@ -354,7 +362,7 @@ func TestProvisionSync(t *testing.T) { {Verb: "create", Resource: "persistentvolumes", Error: errors.New("Mock creation error4")}, {Verb: "create", Resource: "persistentvolumes", Error: errors.New("Mock creation error5")}, }, - wrapTestWithPluginCalls( + test: wrapTestWithPluginCalls( nil, // recycle calls []error{ // delete calls errors.New("Mock deletion error1"), @@ -366,62 +374,72 @@ func TestProvisionSync(t *testing.T) { }, { // Provision a volume (with non-default class) - "11-13 - successful provision with storage class 2", - novolumes, - volumesWithFinalizers(newVolumeArray("pvc-uid11-13", "1Gi", "uid11-13", "claim11-13", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classSilver, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned), []string{volume.PVDeletionInTreeProtectionFinalizer}), - newClaimArray("claim11-13", "uid11-13", "1Gi", "", v1.ClaimPending, &classSilver), + name: "11-13 - successful provision with storage class 2", + initialVolumes: novolumes, + expectedVolumes: volumesWithFinalizers(newVolumeArray("pvc-uid11-13", "1Gi", "uid11-13", "claim11-13", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classSilver, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned), []string{volume.PVDeletionInTreeProtectionFinalizer}), + initialClaims: newClaimArray("claim11-13", "uid11-13", "1Gi", "", v1.ClaimPending, &classSilver), // Binding will be completed in the next syncClaim - newClaimArray("claim11-13", "uid11-13", "1Gi", "", v1.ClaimPending, &classSilver, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), - []string{"Normal ProvisioningSucceeded"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision2Success}, testSyncClaim), + expectedClaims: newClaimArray("claim11-13", "uid11-13", "1Gi", "", v1.ClaimPending, &classSilver, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), + expectedEvents: []string{"Normal ProvisioningSucceeded"}, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{provision2Success}, testSyncClaim), }, { // Provision error - non existing class - "11-14 - fail due to non-existing class", - novolumes, - novolumes, - newClaimArray("claim11-14", "uid11-14", "1Gi", "", v1.ClaimPending, &classNonExisting), - newClaimArray("claim11-14", "uid11-14", "1Gi", "", v1.ClaimPending, &classNonExisting), - noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), + name: "11-14 - fail due to non-existing class", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-14", "uid11-14", "1Gi", "", v1.ClaimPending, &classNonExisting), + expectedClaims: newClaimArray("claim11-14", "uid11-14", "1Gi", "", v1.ClaimPending, &classNonExisting), + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, { // No provisioning with class="" - "11-15 - no provisioning with class=''", - novolumes, - novolumes, - newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending, &classEmpty), - newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending, &classEmpty), - noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), + name: "11-15 - no provisioning with class=''", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending, &classEmpty), + expectedClaims: newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending, &classEmpty), + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, { // No provisioning with class=nil - "11-16 - no provisioning with class=nil", - novolumes, - novolumes, - newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending, nil), - newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending, nil), - noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), + name: "11-16 - no provisioning with class=nil", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending, nil), + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, { // No provisioning + normal event with external provisioner - "11-17 - external provisioner", - novolumes, - novolumes, - newClaimArray("claim11-17", "uid11-17", "1Gi", "", v1.ClaimPending, &classExternal), - claimWithAnnotation(volume.AnnBetaStorageProvisioner, "vendor.com/my-volume", + name: "11-17 - external provisioner", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-17", "uid11-17", "1Gi", "", v1.ClaimPending, &classExternal), + expectedClaims: claimWithAnnotation(volume.AnnBetaStorageProvisioner, "vendor.com/my-volume", claimWithAnnotation(volume.AnnStorageProvisioner, "vendor.com/my-volume", newClaimArray("claim11-17", "uid11-17", "1Gi", "", v1.ClaimPending, &classExternal))), - []string{"Normal ExternalProvisioning"}, - noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), + expectedEvents: []string{"Normal ExternalProvisioning"}, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, { // No provisioning + warning event with unknown internal provisioner - "11-18 - unknown internal provisioner", - novolumes, - novolumes, - newClaimArray("claim11-18", "uid11-18", "1Gi", "", v1.ClaimPending, &classUnknownInternal), - newClaimArray("claim11-18", "uid11-18", "1Gi", "", v1.ClaimPending, &classUnknownInternal), - []string{"Warning ProvisioningFailed"}, - noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), + name: "11-18 - unknown internal provisioner", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-18", "uid11-18", "1Gi", "", v1.ClaimPending, &classUnknownInternal), + expectedClaims: newClaimArray("claim11-18", "uid11-18", "1Gi", "", v1.ClaimPending, &classUnknownInternal), + expectedEvents: []string{"Warning ProvisioningFailed"}, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, { // Provision success - first save of a PV to API server fails (API @@ -455,22 +473,23 @@ func TestProvisionSync(t *testing.T) { }, { // No provisioning + warning event with unsupported storageClass.mountOptions - "11-20 - unsupported storageClass.mountOptions", - novolumes, - novolumes, - newClaimArray("claim11-20", "uid11-20", "1Gi", "", v1.ClaimPending, &classUnsupportedMountOptions), - newClaimArray("claim11-20", "uid11-20", "1Gi", "", v1.ClaimPending, &classUnsupportedMountOptions, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), + name: "11-20 - unsupported storageClass.mountOptions", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-20", "uid11-20", "1Gi", "", v1.ClaimPending, &classUnsupportedMountOptions), + expectedClaims: newClaimArray("claim11-20", "uid11-20", "1Gi", "", v1.ClaimPending, &classUnsupportedMountOptions, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), // Expect event to be prefixed with "Mount options" because saving PV will fail anyway - []string{"Warning ProvisioningFailed Mount options"}, - noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), + expectedEvents: []string{"Warning ProvisioningFailed Mount options"}, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, { // No provisioning due to CSI migration + normal event with external provisioner - "11-21 - external provisioner for CSI migration", - novolumes, - novolumes, - newClaimArray("claim11-21", "uid11-21", "1Gi", "", v1.ClaimPending, &classGold), - []*v1.PersistentVolumeClaim{ + name: "11-21 - external provisioner for CSI migration", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim11-21", "uid11-21", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: []*v1.PersistentVolumeClaim{ annotateClaim( newClaim("claim11-21", "uid11-21", "1Gi", "", v1.ClaimPending, &classGold), map[string]string{ @@ -479,19 +498,21 @@ func TestProvisionSync(t *testing.T) { volume.AnnMigratedTo: "vendor.com/MockCSIDriver", }), }, - []string{"Normal ExternalProvisioning"}, - noerrors, wrapTestWithCSIMigrationProvisionCalls(testSyncClaim), + expectedEvents: []string{"Normal ExternalProvisioning"}, + errors: noerrors, + test: wrapTestWithCSIMigrationProvisionCalls(testSyncClaim), }, { // volume provisioned and available // in this case, NO normal event with external provisioner should be issued - "11-22 - external provisioner with volume available", - newVolumeArray("volume11-22", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classExternal), - newVolumeArray("volume11-22", "1Gi", "uid11-22", "claim11-22", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classExternal, volume.AnnBoundByController), - newClaimArray("claim11-22", "uid11-22", "1Gi", "", v1.ClaimPending, &classExternal), - newClaimArray("claim11-22", "uid11-22", "1Gi", "volume11-22", v1.ClaimBound, &classExternal, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, - noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), + name: "11-22 - external provisioner with volume available", + initialVolumes: newVolumeArray("volume11-22", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classExternal), + expectedVolumes: newVolumeArray("volume11-22", "1Gi", "uid11-22", "claim11-22", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classExternal, volume.AnnBoundByController), + initialClaims: newClaimArray("claim11-22", "uid11-22", "1Gi", "", v1.ClaimPending, &classExternal), + expectedClaims: newClaimArray("claim11-22", "uid11-22", "1Gi", "volume11-22", v1.ClaimBound, &classExternal, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, { // volume provision for PVC scheduled @@ -517,28 +538,30 @@ func TestProvisionSync(t *testing.T) { }, { // volume provision for PVC that scheduled - "11-24 - skip finding PV and wait external provisioner for PVC annotated with AnnSelectedNode", - newVolumeArray("volume11-24", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classExternalWait), - newVolumeArray("volume11-24", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classExternalWait), - claimWithAnnotation(volume.AnnSelectedNode, "node1", + name: "11-24 - skip finding PV and wait external provisioner for PVC annotated with AnnSelectedNode", + initialVolumes: newVolumeArray("volume11-24", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classExternalWait), + expectedVolumes: newVolumeArray("volume11-24", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classExternalWait), + initialClaims: claimWithAnnotation(volume.AnnSelectedNode, "node1", newClaimArray("claim11-24", "uid11-24", "1Gi", "", v1.ClaimPending, &classExternalWait)), - claimWithAnnotation(volume.AnnBetaStorageProvisioner, "vendor.com/my-volume-wait", + expectedClaims: claimWithAnnotation(volume.AnnBetaStorageProvisioner, "vendor.com/my-volume-wait", claimWithAnnotation(volume.AnnStorageProvisioner, "vendor.com/my-volume-wait", claimWithAnnotation(volume.AnnSelectedNode, "node1", newClaimArray("claim11-24", "uid11-24", "1Gi", "", v1.ClaimPending, &classExternalWait)))), - []string{"Normal ExternalProvisioning"}, - noerrors, testSyncClaim, + expectedEvents: []string{"Normal ExternalProvisioning"}, + errors: noerrors, + test: testSyncClaim, }, { // Provision a volume with a data source will fail // for in-tree plugins - "11-25 - failed in-tree provision with data source", - novolumes, - novolumes, - claimWithDataSource("test-snap", "VolumeSnapshot", "snapshot.storage.k8s.io", newClaimArray("claim11-25", "uid11-25", "1Gi", "", v1.ClaimPending, &classGold)), - claimWithDataSource("test-snap", "VolumeSnapshot", "snapshot.storage.k8s.io", newClaimArray("claim11-25", "uid11-25", "1Gi", "", v1.ClaimPending, &classGold)), - []string{"Warning ProvisioningFailed"}, noerrors, - testSyncClaim, + name: "11-25 - failed in-tree provision with data source", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: claimWithDataSource("test-snap", "VolumeSnapshot", "snapshot.storage.k8s.io", newClaimArray("claim11-25", "uid11-25", "1Gi", "", v1.ClaimPending, &classGold)), + expectedClaims: claimWithDataSource("test-snap", "VolumeSnapshot", "snapshot.storage.k8s.io", newClaimArray("claim11-25", "uid11-25", "1Gi", "", v1.ClaimPending, &classGold)), + expectedEvents: []string{"Warning ProvisioningFailed"}, + errors: noerrors, + test: testSyncClaim, }, { // Provision a volume with a data source will proceed @@ -551,7 +574,8 @@ func TestProvisionSync(t *testing.T) { claimWithAnnotation(volume.AnnStorageProvisioner, "mydriver.csi.k8s.io", claimWithDataSource("test-snap", "VolumeSnapshot", "snapshot.storage.k8s.io", newClaimArray("claim11-26", "uid11-26", "1Gi", "", v1.ClaimPending, &classCSI))), []string{"Normal ExternalProvisioning"}, - noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), + noerrors, + wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, } runSyncTests(t, tests, storageClasses, []*v1.Pod{}) @@ -576,25 +600,27 @@ func TestProvisionMultiSync(t *testing.T) { tests := []controllerTest{ { // Provision a volume with binding - "12-1 - successful provision", - novolumes, - newVolumeArray("pvc-uid12-1", "1Gi", "uid12-1", "claim12-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned), - newClaimArray("claim12-1", "uid12-1", "1Gi", "", v1.ClaimPending, &classGold), - newClaimArray("claim12-1", "uid12-1", "1Gi", "pvc-uid12-1", v1.ClaimBound, &classGold, volume.AnnBoundByController, volume.AnnBindCompleted, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), - noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), + name: "12-1 - successful provision", + initialVolumes: novolumes, + expectedVolumes: newVolumeArray("pvc-uid12-1", "1Gi", "uid12-1", "claim12-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned), + initialClaims: newClaimArray("claim12-1", "uid12-1", "1Gi", "", v1.ClaimPending, &classGold), + expectedClaims: newClaimArray("claim12-1", "uid12-1", "1Gi", "pvc-uid12-1", v1.ClaimBound, &classGold, volume.AnnBoundByController, volume.AnnBindCompleted, volume.AnnStorageProvisioner, volume.AnnBetaStorageProvisioner), + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), }, { // provision a volume (external provisioner) and binding + normal event with external provisioner - "12-2 - external provisioner with volume provisioned success", - novolumes, - newVolumeArray("pvc-uid12-2", "1Gi", "uid12-2", "claim12-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classExternal, volume.AnnBoundByController), - newClaimArray("claim12-2", "uid12-2", "1Gi", "", v1.ClaimPending, &classExternal), - claimWithAnnotation(volume.AnnBetaStorageProvisioner, "vendor.com/my-volume", + name: "12-2 - external provisioner with volume provisioned success", + initialVolumes: novolumes, + expectedVolumes: newVolumeArray("pvc-uid12-2", "1Gi", "uid12-2", "claim12-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classExternal, volume.AnnBoundByController), + initialClaims: newClaimArray("claim12-2", "uid12-2", "1Gi", "", v1.ClaimPending, &classExternal), + expectedClaims: claimWithAnnotation(volume.AnnBetaStorageProvisioner, "vendor.com/my-volume", claimWithAnnotation(volume.AnnStorageProvisioner, "vendor.com/my-volume", newClaimArray("claim12-2", "uid12-2", "1Gi", "pvc-uid12-2", v1.ClaimBound, &classExternal, volume.AnnBoundByController, volume.AnnBindCompleted))), - []string{"Normal ExternalProvisioning"}, - noerrors, - wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { + expectedEvents: []string{"Normal ExternalProvisioning"}, + errors: noerrors, + test: wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { // Create a volume before syncClaim tries to bind a PV to PVC // This simulates external provisioner creating a volume while the controller // is waiting for a volume to bind to the existed claim @@ -611,29 +637,29 @@ func TestProvisionMultiSync(t *testing.T) { }, { // provision a volume (external provisioner) but binding will not happen + normal event with external provisioner - "12-3 - external provisioner with volume to be provisioned", - novolumes, - novolumes, - newClaimArray("claim12-3", "uid12-3", "1Gi", "", v1.ClaimPending, &classExternal), - claimWithAnnotation(volume.AnnBetaStorageProvisioner, "vendor.com/my-volume", + name: "12-3 - external provisioner with volume to be provisioned", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim12-3", "uid12-3", "1Gi", "", v1.ClaimPending, &classExternal), + expectedClaims: claimWithAnnotation(volume.AnnBetaStorageProvisioner, "vendor.com/my-volume", claimWithAnnotation(volume.AnnStorageProvisioner, "vendor.com/my-volume", newClaimArray("claim12-3", "uid12-3", "1Gi", "", v1.ClaimPending, &classExternal))), - []string{"Normal ExternalProvisioning"}, - noerrors, - wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), + expectedEvents: []string{"Normal ExternalProvisioning"}, + errors: noerrors, + test: wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), }, { // provision a volume (external provisioner) and binding + normal event with external provisioner - "12-4 - external provisioner with volume provisioned/bound success", - novolumes, - newVolumeArray("pvc-uid12-4", "1Gi", "uid12-4", "claim12-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classExternal, volume.AnnBoundByController), - newClaimArray("claim12-4", "uid12-4", "1Gi", "", v1.ClaimPending, &classExternal), - claimWithAnnotation(volume.AnnBetaStorageProvisioner, "vendor.com/my-volume", + name: "12-4 - external provisioner with volume provisioned/bound success", + initialVolumes: novolumes, + expectedVolumes: newVolumeArray("pvc-uid12-4", "1Gi", "uid12-4", "claim12-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classExternal, volume.AnnBoundByController), + initialClaims: newClaimArray("claim12-4", "uid12-4", "1Gi", "", v1.ClaimPending, &classExternal), + expectedClaims: claimWithAnnotation(volume.AnnBetaStorageProvisioner, "vendor.com/my-volume", claimWithAnnotation(volume.AnnStorageProvisioner, "vendor.com/my-volume", newClaimArray("claim12-4", "uid12-4", "1Gi", "pvc-uid12-4", v1.ClaimBound, &classExternal, volume.AnnBoundByController, volume.AnnBindCompleted))), - []string{"Normal ExternalProvisioning"}, - noerrors, - wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { + expectedEvents: []string{"Normal ExternalProvisioning"}, + errors: noerrors, + test: wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { // Create a volume before syncClaim tries to bind a PV to PVC // This simulates external provisioner creating a volume while the controller // is waiting for a volume to bind to the existed claim diff --git a/pkg/controller/volume/persistentvolume/pv_controller_test.go b/pkg/controller/volume/persistentvolume/pv_controller_test.go index 85e7ebd8af6..7d11120d023 100644 --- a/pkg/controller/volume/persistentvolume/pv_controller_test.go +++ b/pkg/controller/volume/persistentvolume/pv_controller_test.go @@ -61,51 +61,55 @@ func TestControllerSync(t *testing.T) { // sent to add/update/delete Claim/Volume as real controller would do. { // addClaim gets a new claim. Check it's bound to a volume. - "5-2 - complete bind", - newVolumeArray("volume5-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume5-2", "1Gi", "uid5-2", "claim5-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - noclaims, /* added in testAddClaim5_2 */ - newClaimArray("claim5-2", "uid5-2", "1Gi", "volume5-2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, + name: "5-2 - complete bind", + initialVolumes: newVolumeArray("volume5-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume5-2", "1Gi", "uid5-2", "claim5-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: noclaims, /* added in testAddClaim5_2 */ + expectedClaims: newClaimArray("claim5-2", "uid5-2", "1Gi", "volume5-2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, // Custom test function that generates an add event - func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { + test: func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { claim := newClaim("claim5-2", "uid5-2", "1Gi", "", v1.ClaimPending, nil) reactor.AddClaimEvent(claim) return nil }, }, { - "5-2-2 - complete bind when PV and PVC both exist", - newVolumeArray("volume5-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), - newVolumeArray("volume5-2", "1Gi", "uid5-2", "claim5-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newClaimArray("claim5-2", "uid5-2", "1Gi", "", v1.ClaimPending, nil), - newClaimArray("claim5-2", "uid5-2", "1Gi", "volume5-2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - noevents, noerrors, - func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { + name: "5-2-2 - complete bind when PV and PVC both exist", + initialVolumes: newVolumeArray("volume5-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: newVolumeArray("volume5-2", "1Gi", "uid5-2", "claim5-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: newClaimArray("claim5-2", "uid5-2", "1Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim5-2", "uid5-2", "1Gi", "volume5-2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: noevents, + errors: noerrors, + test: func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { return nil }, }, { - "5-2-3 - complete bind when PV and PVC both exist and PV has AnnPreResizeCapacity annotation", - volumesWithAnnotation(util.AnnPreResizeCapacity, "1Gi", newVolumeArray("volume5-2", "2Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - volumesWithAnnotation(util.AnnPreResizeCapacity, "1Gi", newVolumeArray("volume5-2", "2Gi", "uid5-2", "claim5-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), - withExpectedCapacity("2Gi", newClaimArray("claim5-2", "uid5-2", "2Gi", "", v1.ClaimPending, nil)), - withExpectedCapacity("1Gi", newClaimArray("claim5-2", "uid5-2", "2Gi", "volume5-2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), - noevents, noerrors, - func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { + name: "5-2-3 - complete bind when PV and PVC both exist and PV has AnnPreResizeCapacity annotation", + initialVolumes: volumesWithAnnotation(util.AnnPreResizeCapacity, "1Gi", newVolumeArray("volume5-2", "2Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + expectedVolumes: volumesWithAnnotation(util.AnnPreResizeCapacity, "1Gi", newVolumeArray("volume5-2", "2Gi", "uid5-2", "claim5-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController)), + initialClaims: withExpectedCapacity("2Gi", newClaimArray("claim5-2", "uid5-2", "2Gi", "", v1.ClaimPending, nil)), + expectedClaims: withExpectedCapacity("1Gi", newClaimArray("claim5-2", "uid5-2", "2Gi", "volume5-2", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted)), + expectedEvents: noevents, + errors: noerrors, + test: func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { return nil }, }, { // deleteClaim with a bound claim makes bound volume released. - "5-3 - delete claim", - newVolumeArray("volume5-3", "10Gi", "uid5-3", "claim5-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume5-3", "10Gi", "uid5-3", "claim5-3", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), - newClaimArray("claim5-3", "uid5-3", "1Gi", "volume5-3", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - noclaims, - noevents, noerrors, + name: "5-3 - delete claim", + initialVolumes: newVolumeArray("volume5-3", "10Gi", "uid5-3", "claim5-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume5-3", "10Gi", "uid5-3", "claim5-3", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain, classEmpty, volume.AnnBoundByController), + initialClaims: newClaimArray("claim5-3", "uid5-3", "1Gi", "volume5-3", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, // Custom test function that generates a delete event - func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { + test: func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { obj := ctrl.claims.List()[0] claim := obj.(*v1.PersistentVolumeClaim) reactor.DeleteClaimEvent(claim) @@ -114,14 +118,15 @@ func TestControllerSync(t *testing.T) { }, { // deleteVolume with a bound volume. Check the claim is Lost. - "5-4 - delete volume", - newVolumeArray("volume5-4", "1Gi", "uid5-4", "claim5-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), - novolumes, - newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", v1.ClaimLost, nil, volume.AnnBoundByController, volume.AnnBindCompleted), - []string{"Warning ClaimLost"}, noerrors, + name: "5-4 - delete volume", + initialVolumes: newVolumeArray("volume5-4", "1Gi", "uid5-4", "claim5-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + expectedVolumes: novolumes, + initialClaims: newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", v1.ClaimBound, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedClaims: newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", v1.ClaimLost, nil, volume.AnnBoundByController, volume.AnnBindCompleted), + expectedEvents: []string{"Warning ClaimLost"}, + errors: noerrors, // Custom test function that generates a delete event - func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { + test: func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { obj := ctrl.volumes.store.List()[0] volume := obj.(*v1.PersistentVolume) reactor.DeleteVolumeEvent(volume) @@ -131,18 +136,19 @@ func TestControllerSync(t *testing.T) { { // deleteClaim with a bound claim makes bound volume released with external deleter. // delete the corresponding volume from apiserver, and report latency metric - "5-5 - delete claim and delete volume report metric", - volumesWithAnnotation(volume.AnnDynamicallyProvisioned, "gcr.io/vendor-csi", + name: "5-5 - delete claim and delete volume report metric", + initialVolumes: volumesWithAnnotation(volume.AnnDynamicallyProvisioned, "gcr.io/vendor-csi", newVolumeArray("volume5-5", "10Gi", "uid5-5", "claim5-5", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classExternal, volume.AnnBoundByController)), - novolumes, - claimWithAnnotation(volume.AnnStorageProvisioner, "gcr.io/vendor-csi", + expectedVolumes: novolumes, + initialClaims: claimWithAnnotation(volume.AnnStorageProvisioner, "gcr.io/vendor-csi", newClaimArray("claim5-5", "uid5-5", "1Gi", "volume5-5", v1.ClaimBound, &classExternal, volume.AnnBoundByController, volume.AnnBindCompleted)), - noclaims, - noevents, noerrors, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, // Custom test function that generates a delete claim event which should have been caught by // "deleteClaim" to remove the claim from controller's cache, after that, a volume deleted // event will be generated to trigger "deleteVolume" call for metric reporting - func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { + test: func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { test.initialVolumes[0].Annotations[volume.AnnDynamicallyProvisioned] = "gcr.io/vendor-csi" obj := ctrl.claims.List()[0] claim := obj.(*v1.PersistentVolumeClaim) @@ -162,16 +168,17 @@ func TestControllerSync(t *testing.T) { { // deleteClaim with a bound claim makes bound volume released with external deleter pending // there should be an entry in operation timestamps cache in controller - "5-6 - delete claim and waiting for external volume deletion", - volumesWithAnnotation(volume.AnnDynamicallyProvisioned, "gcr.io/vendor-csi", []*v1.PersistentVolume{newExternalProvisionedVolume("volume5-6", "10Gi", "uid5-6", "claim5-6", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classExternal, "fake.driver.csi", nil, volume.AnnBoundByController)}), - volumesWithAnnotation(volume.AnnDynamicallyProvisioned, "gcr.io/vendor-csi", []*v1.PersistentVolume{newExternalProvisionedVolume("volume5-6", "10Gi", "uid5-6", "claim5-6", v1.VolumeReleased, v1.PersistentVolumeReclaimDelete, classExternal, "fake.driver.csi", nil, volume.AnnBoundByController)}), - claimWithAnnotation(volume.AnnStorageProvisioner, "gcr.io/vendor-csi", + name: "5-6 - delete claim and waiting for external volume deletion", + initialVolumes: volumesWithAnnotation(volume.AnnDynamicallyProvisioned, "gcr.io/vendor-csi", []*v1.PersistentVolume{newExternalProvisionedVolume("volume5-6", "10Gi", "uid5-6", "claim5-6", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classExternal, "fake.driver.csi", nil, volume.AnnBoundByController)}), + expectedVolumes: volumesWithAnnotation(volume.AnnDynamicallyProvisioned, "gcr.io/vendor-csi", []*v1.PersistentVolume{newExternalProvisionedVolume("volume5-6", "10Gi", "uid5-6", "claim5-6", v1.VolumeReleased, v1.PersistentVolumeReclaimDelete, classExternal, "fake.driver.csi", nil, volume.AnnBoundByController)}), + initialClaims: claimWithAnnotation(volume.AnnStorageProvisioner, "gcr.io/vendor-csi", newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", v1.ClaimBound, &classExternal, volume.AnnBoundByController, volume.AnnBindCompleted)), - noclaims, - noevents, noerrors, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, // Custom test function that generates a delete claim event which should have been caught by // "deleteClaim" to remove the claim from controller's cache and mark bound volume to be released - func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { + test: func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { // should have been provisioned by external provisioner obj := ctrl.claims.List()[0] claim := obj.(*v1.PersistentVolumeClaim) @@ -197,17 +204,17 @@ func TestControllerSync(t *testing.T) { { // deleteVolume event issued before deleteClaim, no metric should have been reported // and no delete operation start timestamp should be inserted into controller.operationTimestamps cache - "5-7 - delete volume event makes claim lost, delete claim event will not report metric", - newVolumeArray("volume5-7", "10Gi", "uid5-7", "claim5-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classExternal, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned), - novolumes, - claimWithAnnotation(volume.AnnStorageProvisioner, "gcr.io/vendor-csi", + name: "5-7 - delete volume event makes claim lost, delete claim event will not report metric", + initialVolumes: newVolumeArray("volume5-7", "10Gi", "uid5-7", "claim5-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classExternal, volume.AnnBoundByController, volume.AnnDynamicallyProvisioned), + expectedVolumes: novolumes, + initialClaims: claimWithAnnotation(volume.AnnStorageProvisioner, "gcr.io/vendor-csi", newClaimArray("claim5-7", "uid5-7", "1Gi", "volume5-7", v1.ClaimBound, &classExternal, volume.AnnBoundByController, volume.AnnBindCompleted)), - noclaims, - []string{"Warning ClaimLost"}, - noerrors, + expectedClaims: noclaims, + expectedEvents: []string{"Warning ClaimLost"}, + errors: noerrors, // Custom test function that generates a delete claim event which should have been caught by // "deleteClaim" to remove the claim from controller's cache and mark bound volume to be released - func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { + test: func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { volume := ctrl.volumes.store.List()[0].(*v1.PersistentVolume) reactor.DeleteVolumeEvent(volume) err := wait.Poll(10*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) { @@ -248,17 +255,17 @@ func TestControllerSync(t *testing.T) { }, { // delete a claim waiting for being bound cleans up provision(volume ref == "") entry from timestamp cache - "5-8 - delete claim cleans up operation timestamp cache for provision", - novolumes, - novolumes, - claimWithAnnotation(volume.AnnStorageProvisioner, "gcr.io/vendor-csi", + name: "5-8 - delete claim cleans up operation timestamp cache for provision", + initialVolumes: novolumes, + expectedVolumes: novolumes, + initialClaims: claimWithAnnotation(volume.AnnStorageProvisioner, "gcr.io/vendor-csi", newClaimArray("claim5-8", "uid5-8", "1Gi", "", v1.ClaimPending, &classExternal)), - noclaims, - []string{"Normal ExternalProvisioning"}, - noerrors, + expectedClaims: noclaims, + expectedEvents: []string{"Normal ExternalProvisioning"}, + errors: noerrors, // Custom test function that generates a delete claim event which should have been caught by // "deleteClaim" to remove the claim from controller's cache and mark bound volume to be released - func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { + test: func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { // wait until the provision timestamp has been inserted err := wait.Poll(10*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) { return ctrl.operationTimestamps.Has("default/claim5-8"), nil @@ -287,18 +294,18 @@ func TestControllerSync(t *testing.T) { { // Test that the finalizer gets removed if CSI migration is disabled. The in-tree finalizer is added // back on the PV since migration is disabled. - "5-9 - volume has its external PV deletion protection finalizer removed as CSI migration is disabled", - volumesWithFinalizers( + name: "5-9 - volume has its external PV deletion protection finalizer removed as CSI migration is disabled", + initialVolumes: volumesWithFinalizers( volumesWithAnnotation(volume.AnnMigratedTo, "pd.csi.storage.gke.io", newVolumeArray("volume-5-9", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnDynamicallyProvisioned)), []string{volume.PVDeletionProtectionFinalizer}, ), - volumesWithFinalizers(newVolumeArray("volume-5-9", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnDynamicallyProvisioned), []string{volume.PVDeletionInTreeProtectionFinalizer}), - noclaims, - noclaims, - noevents, - noerrors, - func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { + expectedVolumes: volumesWithFinalizers(newVolumeArray("volume-5-9", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty, volume.AnnDynamicallyProvisioned), []string{volume.PVDeletionInTreeProtectionFinalizer}), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, + test: func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error { return nil }, }, diff --git a/pkg/controller/volume/persistentvolume/recycle_test.go b/pkg/controller/volume/persistentvolume/recycle_test.go index 015248922a3..c1d0c86b24e 100644 --- a/pkg/controller/volume/persistentvolume/recycle_test.go +++ b/pkg/controller/volume/persistentvolume/recycle_test.go @@ -73,66 +73,73 @@ func TestRecycleSync(t *testing.T) { tests := []controllerTest{ { // recycle volume bound by controller - "6-1 - successful recycle", - newVolumeArray("volume6-1", "1Gi", "uid6-1", "claim6-1", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume6-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), - noclaims, - noclaims, - noevents, noerrors, + name: "6-1 - successful recycle", + initialVolumes: newVolumeArray("volume6-1", "1Gi", "uid6-1", "claim6-1", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume6-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, // Inject recycler into the controller and call syncVolume. The // recycler simulates one recycle() call that succeeds. - wrapTestWithReclaimCalls(operationRecycle, []error{nil}, testSyncVolume), + test: wrapTestWithReclaimCalls(operationRecycle, []error{nil}, testSyncVolume), }, { // recycle volume bound by user - "6-2 - successful recycle with prebound volume", - newVolumeArray("volume6-2", "1Gi", "uid6-2", "claim6-2", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), - newVolumeArray("volume6-2", "1Gi", "", "claim6-2", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), - noclaims, - noclaims, - noevents, noerrors, + name: "6-2 - successful recycle with prebound volume", + initialVolumes: newVolumeArray("volume6-2", "1Gi", "uid6-2", "claim6-2", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), + expectedVolumes: newVolumeArray("volume6-2", "1Gi", "", "claim6-2", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, // Inject recycler into the controller and call syncVolume. The // recycler simulates one recycle() call that succeeds. - wrapTestWithReclaimCalls(operationRecycle, []error{nil}, testSyncVolume), + test: wrapTestWithReclaimCalls(operationRecycle, []error{nil}, testSyncVolume), }, { // recycle failure - plugin not found - "6-3 - plugin not found", - newVolumeArray("volume6-3", "1Gi", "uid6-3", "claim6-3", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), - withMessage("No recycler plugin found for the volume!", newVolumeArray("volume6-3", "1Gi", "uid6-3", "claim6-3", v1.VolumeFailed, v1.PersistentVolumeReclaimRecycle, classEmpty)), - noclaims, - noclaims, - []string{"Warning VolumeFailedRecycle"}, noerrors, testSyncVolume, + name: "6-3 - plugin not found", + initialVolumes: newVolumeArray("volume6-3", "1Gi", "uid6-3", "claim6-3", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), + expectedVolumes: withMessage("No recycler plugin found for the volume!", newVolumeArray("volume6-3", "1Gi", "uid6-3", "claim6-3", v1.VolumeFailed, v1.PersistentVolumeReclaimRecycle, classEmpty)), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: []string{"Warning VolumeFailedRecycle"}, + errors: noerrors, + test: testSyncVolume, }, { // recycle failure - Recycle returns error - "6-4 - newRecycler returns error", - newVolumeArray("volume6-4", "1Gi", "uid6-4", "claim6-4", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), - withMessage("Recycle failed: Mock plugin error: no recycleCalls configured", newVolumeArray("volume6-4", "1Gi", "uid6-4", "claim6-4", v1.VolumeFailed, v1.PersistentVolumeReclaimRecycle, classEmpty)), - noclaims, - noclaims, - []string{"Warning VolumeFailedRecycle"}, noerrors, - wrapTestWithReclaimCalls(operationRecycle, []error{}, testSyncVolume), + name: "6-4 - newRecycler returns error", + initialVolumes: newVolumeArray("volume6-4", "1Gi", "uid6-4", "claim6-4", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), + expectedVolumes: withMessage("Recycle failed: Mock plugin error: no recycleCalls configured", newVolumeArray("volume6-4", "1Gi", "uid6-4", "claim6-4", v1.VolumeFailed, v1.PersistentVolumeReclaimRecycle, classEmpty)), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: []string{"Warning VolumeFailedRecycle"}, + errors: noerrors, + test: wrapTestWithReclaimCalls(operationRecycle, []error{}, testSyncVolume), }, { // recycle failure - recycle returns error - "6-5 - recycle returns error", - newVolumeArray("volume6-5", "1Gi", "uid6-5", "claim6-5", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), - withMessage("Recycle failed: Mock recycle error", newVolumeArray("volume6-5", "1Gi", "uid6-5", "claim6-5", v1.VolumeFailed, v1.PersistentVolumeReclaimRecycle, classEmpty)), - noclaims, - noclaims, - []string{"Warning VolumeFailedRecycle"}, noerrors, - wrapTestWithReclaimCalls(operationRecycle, []error{errors.New("Mock recycle error")}, testSyncVolume), + name: "6-5 - recycle returns error", + initialVolumes: newVolumeArray("volume6-5", "1Gi", "uid6-5", "claim6-5", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), + expectedVolumes: withMessage("Recycle failed: Mock recycle error", newVolumeArray("volume6-5", "1Gi", "uid6-5", "claim6-5", v1.VolumeFailed, v1.PersistentVolumeReclaimRecycle, classEmpty)), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: []string{"Warning VolumeFailedRecycle"}, + errors: noerrors, + test: wrapTestWithReclaimCalls(operationRecycle, []error{errors.New("Mock recycle error")}, testSyncVolume), }, { // recycle success(?) - volume is deleted before doRecycle() starts - "6-6 - volume is deleted before recycling", - newVolumeArray("volume6-6", "1Gi", "uid6-6", "claim6-6", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), - novolumes, - noclaims, - noclaims, - noevents, noerrors, - wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationRecycle, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { + name: "6-6 - volume is deleted before recycling", + initialVolumes: newVolumeArray("volume6-6", "1Gi", "uid6-6", "claim6-6", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), + expectedVolumes: novolumes, + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationRecycle, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { // Delete the volume before recycle operation starts reactor.DeleteVolume("volume6-6") }), @@ -141,13 +148,14 @@ func TestRecycleSync(t *testing.T) { // recycle success(?) - volume is recycled by previous recycler just // at the time new doRecycle() starts. This simulates "volume no // longer needs recycling, skipping". - "6-7 - volume is deleted before recycling", - newVolumeArray("volume6-7", "1Gi", "uid6-7", "claim6-7", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume6-7", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), - noclaims, - noclaims, - noevents, noerrors, - wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationRecycle, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { + name: "6-7 - volume is deleted before recycling", + initialVolumes: newVolumeArray("volume6-7", "1Gi", "uid6-7", "claim6-7", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume6-7", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationRecycle, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { // Mark the volume as Available before the recycler starts reactor.MarkVolumeAvailable("volume6-7") }), @@ -157,13 +165,14 @@ func TestRecycleSync(t *testing.T) { // recycler just at the time new doRecycle() starts. This simulates // "volume no longer needs recycling, skipping" with volume bound by // user. - "6-8 - prebound volume is deleted before recycling", - newVolumeArray("volume6-8", "1Gi", "uid6-8", "claim6-8", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), - newVolumeArray("volume6-8", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), - noclaims, - noclaims, - noevents, noerrors, - wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationRecycle, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { + name: "6-8 - prebound volume is deleted before recycling", + initialVolumes: newVolumeArray("volume6-8", "1Gi", "uid6-8", "claim6-8", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), + expectedVolumes: newVolumeArray("volume6-8", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationRecycle, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { // Mark the volume as Available before the recycler starts reactor.MarkVolumeAvailable("volume6-8") }), @@ -171,64 +180,73 @@ func TestRecycleSync(t *testing.T) { { // recycle success - volume bound by user is recycled, while a new // claim is created with another UID. - "6-9 - prebound volume is recycled while the claim exists", - newVolumeArray("volume6-9", "1Gi", "uid6-9", "claim6-9", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), - newVolumeArray("volume6-9", "1Gi", "", "claim6-9", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), - newClaimArray("claim6-9", "uid6-9-x", "10Gi", "", v1.ClaimPending, nil), - newClaimArray("claim6-9", "uid6-9-x", "10Gi", "", v1.ClaimPending, nil), - noevents, noerrors, + name: "6-9 - prebound volume is recycled while the claim exists", + initialVolumes: newVolumeArray("volume6-9", "1Gi", "uid6-9", "claim6-9", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), + expectedVolumes: newVolumeArray("volume6-9", "1Gi", "", "claim6-9", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), + initialClaims: newClaimArray("claim6-9", "uid6-9-x", "10Gi", "", v1.ClaimPending, nil), + expectedClaims: newClaimArray("claim6-9", "uid6-9-x", "10Gi", "", v1.ClaimPending, nil), + expectedEvents: noevents, + errors: noerrors, // Inject recycler into the controller and call syncVolume. The // recycler simulates one recycle() call that succeeds. - wrapTestWithReclaimCalls(operationRecycle, []error{nil}, testSyncVolume), + test: wrapTestWithReclaimCalls(operationRecycle, []error{nil}, testSyncVolume), }, { // volume has unknown reclaim policy - failure expected - "6-10 - unknown reclaim policy", - newVolumeArray("volume6-10", "1Gi", "uid6-10", "claim6-10", v1.VolumeBound, "Unknown", classEmpty), - withMessage("Volume has unrecognized PersistentVolumeReclaimPolicy", newVolumeArray("volume6-10", "1Gi", "uid6-10", "claim6-10", v1.VolumeFailed, "Unknown", classEmpty)), - noclaims, - noclaims, - []string{"Warning VolumeUnknownReclaimPolicy"}, noerrors, testSyncVolume, + name: "6-10 - unknown reclaim policy", + initialVolumes: newVolumeArray("volume6-10", "1Gi", "uid6-10", "claim6-10", v1.VolumeBound, "Unknown", classEmpty), + expectedVolumes: withMessage("Volume has unrecognized PersistentVolumeReclaimPolicy", newVolumeArray("volume6-10", "1Gi", "uid6-10", "claim6-10", v1.VolumeFailed, "Unknown", classEmpty)), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: []string{"Warning VolumeUnknownReclaimPolicy"}, + errors: noerrors, + test: testSyncVolume, }, { // volume is used by a running pod - failure expected - "6-11 - used by running pod", - newVolumeArray("volume6-11", "1Gi", "uid6-11", "runningClaim", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume6-11", "1Gi", "uid6-11", "runningClaim", v1.VolumeReleased, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), - noclaims, - noclaims, - []string{"Normal VolumeFailedRecycle"}, noerrors, testSyncVolume, + name: "6-11 - used by running pod", + initialVolumes: newVolumeArray("volume6-11", "1Gi", "uid6-11", "runningClaim", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume6-11", "1Gi", "uid6-11", "runningClaim", v1.VolumeReleased, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: []string{"Normal VolumeFailedRecycle"}, + errors: noerrors, + test: testSyncVolume, }, { // volume is used by a pending pod - failure expected - "6-12 - used by pending pod", - newVolumeArray("volume6-12", "1Gi", "uid6-12", "pendingClaim", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume6-12", "1Gi", "uid6-12", "pendingClaim", v1.VolumeReleased, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), - noclaims, - noclaims, - []string{"Normal VolumeFailedRecycle"}, noerrors, testSyncVolume, + name: "6-12 - used by pending pod", + initialVolumes: newVolumeArray("volume6-12", "1Gi", "uid6-12", "pendingClaim", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume6-12", "1Gi", "uid6-12", "pendingClaim", v1.VolumeReleased, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: []string{"Normal VolumeFailedRecycle"}, + errors: noerrors, + test: testSyncVolume, }, { // volume is used by a completed pod - recycle succeeds - "6-13 - used by completed pod", - newVolumeArray("volume6-13", "1Gi", "uid6-13", "completedClaim", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume6-13", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), - noclaims, - noclaims, - noevents, noerrors, + name: "6-13 - used by completed pod", + initialVolumes: newVolumeArray("volume6-13", "1Gi", "uid6-13", "completedClaim", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume6-13", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), + initialClaims: noclaims, + expectedClaims: noclaims, + expectedEvents: noevents, + errors: noerrors, // Inject recycler into the controller and call syncVolume. The // recycler simulates one recycle() call that succeeds. - wrapTestWithReclaimCalls(operationRecycle, []error{nil}, testSyncVolume), + test: wrapTestWithReclaimCalls(operationRecycle, []error{nil}, testSyncVolume), }, { // volume is used by a completed pod, pod using claim with the same name bound to different pv is running, should recycle - "6-14 - seemingly used by running pod", - newVolumeArray("volume6-14", "1Gi", "uid6-14", "completedClaim", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), - newVolumeArray("volume6-14", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), - newClaimArray("completedClaim", "uid6-14-x", "10Gi", "", v1.ClaimBound, nil), - newClaimArray("completedClaim", "uid6-14-x", "10Gi", "", v1.ClaimBound, nil), - noevents, noerrors, - wrapTestWithReclaimCalls(operationRecycle, []error{nil}, testSyncVolume), + name: "6-14 - seemingly used by running pod", + initialVolumes: newVolumeArray("volume6-14", "1Gi", "uid6-14", "completedClaim", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, volume.AnnBoundByController), + expectedVolumes: newVolumeArray("volume6-14", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), + initialClaims: newClaimArray("completedClaim", "uid6-14-x", "10Gi", "", v1.ClaimBound, nil), + expectedClaims: newClaimArray("completedClaim", "uid6-14-x", "10Gi", "", v1.ClaimBound, nil), + expectedEvents: noevents, + errors: noerrors, + test: wrapTestWithReclaimCalls(operationRecycle, []error{nil}, testSyncVolume), }, } runSyncTests(t, tests, []*storage.StorageClass{}, pods)