From 52adaa16e07dfd4cd93fb23e73217a6a2fad4cec Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Thu, 2 Mar 2017 10:23:56 +0100 Subject: [PATCH] PV controller: use attributes instead of beta annotations in unit tests --- .../volume/persistentvolume/binder_test.go | 362 +++++++++--------- .../volume/persistentvolume/delete_test.go | 60 +-- .../volume/persistentvolume/framework_test.go | 51 +-- .../volume/persistentvolume/index_test.go | 20 +- .../volume/persistentvolume/provision_test.go | 104 ++--- .../persistentvolume/pv_controller_test.go | 54 +-- .../volume/persistentvolume/recycle_test.go | 46 +-- 7 files changed, 331 insertions(+), 366 deletions(-) diff --git a/pkg/controller/volume/persistentvolume/binder_test.go b/pkg/controller/volume/persistentvolume/binder_test.go index 63e2852fed1..07fe19ca306 100644 --- a/pkg/controller/volume/persistentvolume/binder_test.go +++ b/pkg/controller/volume/persistentvolume/binder_test.go @@ -41,19 +41,19 @@ func TestSync(t *testing.T) { { // syncClaim binds to a matching unbound volume. "1-1 - successful bind", - newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume1-1", "1Gi", "uid1-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending), - newClaimArray("claim1-1", "uid1-1", "1Gi", "volume1-1", v1.ClaimBound, annBoundByController, annBindCompleted), + newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume1-1", "1Gi", "uid1-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending, nil), + newClaimArray("claim1-1", "uid1-1", "1Gi", "volume1-1", v1.ClaimBound, nil, annBoundByController, annBindCompleted), noevents, noerrors, testSyncClaim, }, { // syncClaim does not do anything when there is no matching volume. "1-2 - noop", - newVolumeArray("volume1-2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume1-2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim1-2", "uid1-2", "10Gi", "", v1.ClaimPending), - newClaimArray("claim1-2", "uid1-2", "10Gi", "", v1.ClaimPending), + newVolumeArray("volume1-2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume1-2", "1Gi", "", "", v1.VolumePending, 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, }, @@ -61,10 +61,10 @@ func TestSync(t *testing.T) { // syncClaim resets claim.Status to Pending when there is no // matching volume. "1-3 - reset to Pending", - newVolumeArray("volume1-3", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume1-3", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim1-3", "uid1-3", "10Gi", "", v1.ClaimBound), - newClaimArray("claim1-3", "uid1-3", "10Gi", "", v1.ClaimPending), + newVolumeArray("volume1-3", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume1-3", "1Gi", "", "", v1.VolumePending, 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, }, @@ -72,15 +72,15 @@ func TestSync(t *testing.T) { // syncClaim binds claims to the smallest matching volume "1-4 - smallest volume", []*v1.PersistentVolume{ - newVolume("volume1-4_1", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("volume1-4_2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), + newVolume("volume1-4_1", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolume("volume1-4_2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), }, []*v1.PersistentVolume{ - newVolume("volume1-4_1", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("volume1-4_2", "1Gi", "uid1-4", "claim1-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), + newVolume("volume1-4_1", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolume("volume1-4_2", "1Gi", "uid1-4", "claim1-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), }, - newClaimArray("claim1-4", "uid1-4", "1Gi", "", v1.ClaimPending), - newClaimArray("claim1-4", "uid1-4", "1Gi", "volume1-4_2", v1.ClaimBound, annBoundByController, annBindCompleted), + newClaimArray("claim1-4", "uid1-4", "1Gi", "", v1.ClaimPending, nil), + newClaimArray("claim1-4", "uid1-4", "1Gi", "volume1-4_2", v1.ClaimBound, nil, annBoundByController, annBindCompleted), noevents, noerrors, testSyncClaim, }, { @@ -88,15 +88,15 @@ func TestSync(t *testing.T) { // name), even though a smaller one is available. "1-5 - prebound volume by name - success", []*v1.PersistentVolume{ - newVolume("volume1-5_1", "10Gi", "", "claim1-5", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("volume1-5_2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), + newVolume("volume1-5_1", "10Gi", "", "claim1-5", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolume("volume1-5_2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), }, []*v1.PersistentVolume{ - newVolume("volume1-5_1", "10Gi", "uid1-5", "claim1-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain), - newVolume("volume1-5_2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), + newVolume("volume1-5_1", "10Gi", "uid1-5", "claim1-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolume("volume1-5_2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), }, - newClaimArray("claim1-5", "uid1-5", "1Gi", "", v1.ClaimPending), - withExpectedCapacity("10Gi", newClaimArray("claim1-5", "uid1-5", "1Gi", "volume1-5_1", v1.ClaimBound, annBoundByController, annBindCompleted)), + newClaimArray("claim1-5", "uid1-5", "1Gi", "", v1.ClaimPending, nil), + withExpectedCapacity("10Gi", newClaimArray("claim1-5", "uid1-5", "1Gi", "volume1-5_1", v1.ClaimBound, nil, annBoundByController, annBindCompleted)), noevents, noerrors, testSyncClaim, }, { @@ -104,25 +104,25 @@ func TestSync(t *testing.T) { // UID), even though a smaller one is available. "1-6 - prebound volume by UID - success", []*v1.PersistentVolume{ - newVolume("volume1-6_1", "10Gi", "uid1-6", "claim1-6", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("volume1-6_2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), + newVolume("volume1-6_1", "10Gi", "uid1-6", "claim1-6", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolume("volume1-6_2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), }, []*v1.PersistentVolume{ - newVolume("volume1-6_1", "10Gi", "uid1-6", "claim1-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain), - newVolume("volume1-6_2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), + newVolume("volume1-6_1", "10Gi", "uid1-6", "claim1-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolume("volume1-6_2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), }, - newClaimArray("claim1-6", "uid1-6", "1Gi", "", v1.ClaimPending), - withExpectedCapacity("10Gi", newClaimArray("claim1-6", "uid1-6", "1Gi", "volume1-6_1", v1.ClaimBound, annBoundByController, annBindCompleted)), + newClaimArray("claim1-6", "uid1-6", "1Gi", "", v1.ClaimPending, nil), + withExpectedCapacity("10Gi", newClaimArray("claim1-6", "uid1-6", "1Gi", "volume1-6_1", v1.ClaimBound, nil, annBoundByController, annBindCompleted)), noevents, noerrors, 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.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume1-7", "10Gi", "uid1-777", "claim1-7", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim1-7", "uid1-7", "1Gi", "", v1.ClaimPending), - newClaimArray("claim1-7", "uid1-7", "1Gi", "", v1.ClaimPending), + newVolumeArray("volume1-7", "10Gi", "uid1-777", "claim1-7", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume1-7", "10Gi", "uid1-777", "claim1-7", v1.VolumePending, 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, }, @@ -130,48 +130,48 @@ func TestSync(t *testing.T) { // 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.VolumePending, v1.PersistentVolumeReclaimRetain, annBoundByController), - newVolumeArray("volume1-8", "1Gi", "uid1-8", "claim1-8", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - newClaimArray("claim1-8", "uid1-8", "1Gi", "", v1.ClaimPending), - newClaimArray("claim1-8", "uid1-8", "1Gi", "volume1-8", v1.ClaimBound, annBoundByController, annBindCompleted), + newVolumeArray("volume1-8", "1Gi", "uid1-8", "claim1-8", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newVolumeArray("volume1-8", "1Gi", "uid1-8", "claim1-8", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newClaimArray("claim1-8", "uid1-8", "1Gi", "", v1.ClaimPending, nil), + newClaimArray("claim1-8", "uid1-8", "1Gi", "volume1-8", v1.ClaimBound, nil, annBoundByController, annBindCompleted), noevents, noerrors, 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, annBoundByController), - newVolumeArray("volume1-9", "1Gi", "uid1-9", "claim1-9", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - newClaimArray("claim1-9", "uid1-9", "1Gi", "", v1.ClaimPending), - newClaimArray("claim1-9", "uid1-9", "1Gi", "volume1-9", v1.ClaimBound, annBoundByController, annBindCompleted), + newVolumeArray("volume1-9", "1Gi", "uid1-9", "claim1-9", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newVolumeArray("volume1-9", "1Gi", "uid1-9", "claim1-9", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newClaimArray("claim1-9", "uid1-9", "1Gi", "", v1.ClaimPending, nil), + newClaimArray("claim1-9", "uid1-9", "1Gi", "volume1-9", v1.ClaimBound, nil, annBoundByController, annBindCompleted), noevents, noerrors, 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, annBoundByController), - newVolumeArray("volume1-10", "1Gi", "uid1-10", "claim1-10", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - newClaimArray("claim1-10", "uid1-10", "1Gi", "volume1-10", v1.ClaimPending, annBoundByController, annBindCompleted), - newClaimArray("claim1-10", "uid1-10", "1Gi", "volume1-10", v1.ClaimBound, annBoundByController, annBindCompleted), + newVolumeArray("volume1-10", "1Gi", "uid1-10", "claim1-10", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newVolumeArray("volume1-10", "1Gi", "uid1-10", "claim1-10", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newClaimArray("claim1-10", "uid1-10", "1Gi", "volume1-10", v1.ClaimPending, nil, annBoundByController, annBindCompleted), + newClaimArray("claim1-10", "uid1-10", "1Gi", "volume1-10", v1.ClaimBound, nil, annBoundByController, annBindCompleted), noevents, noerrors, 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.VolumePending, v1.PersistentVolumeReclaimRetain)), - withLabels(labels, newVolumeArray("volume1-1", "1Gi", "uid1-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController)), - withLabelSelector(labels, newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending)), - withLabelSelector(labels, newClaimArray("claim1-1", "uid1-1", "1Gi", "volume1-1", v1.ClaimBound, annBoundByController, annBindCompleted)), + withLabels(labels, newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty)), + withLabels(labels, newVolumeArray("volume1-1", "1Gi", "uid1-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, 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, annBoundByController, annBindCompleted)), noevents, noerrors, 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.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - withLabelSelector(labels, newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending)), - withLabelSelector(labels, newClaimArray("claim1-1", "uid1-1", "1Gi", "", v1.ClaimPending)), + newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume1-1", "1Gi", "", "", v1.VolumePending, 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, }, @@ -184,8 +184,8 @@ func TestSync(t *testing.T) { "2-1 - claim prebound to non-existing volume - noop", novolumes, novolumes, - newClaimArray("claim2-1", "uid2-1", "10Gi", "volume2-1", v1.ClaimPending), - newClaimArray("claim2-1", "uid2-1", "10Gi", "volume2-1", v1.ClaimPending), + 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, }, { @@ -194,28 +194,28 @@ func TestSync(t *testing.T) { "2-2 - claim prebound to non-existing volume - reset status", novolumes, novolumes, - newClaimArray("claim2-2", "uid2-2", "10Gi", "volume2-2", v1.ClaimBound), - newClaimArray("claim2-2", "uid2-2", "10Gi", "volume2-2", v1.ClaimPending), + 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, }, { // syncClaim with claim pre-bound to a PV that exists and is // unbound. Check it gets bound and no annBoundByController is set. "2-3 - claim prebound to unbound volume", - newVolumeArray("volume2-3", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume2-3", "1Gi", "uid2-3", "claim2-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", v1.ClaimPending), - newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", v1.ClaimBound, annBindCompleted), + newVolumeArray("volume2-3", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume2-3", "1Gi", "uid2-3", "claim2-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", v1.ClaimPending, nil), + newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", v1.ClaimBound, nil, annBindCompleted), noevents, noerrors, testSyncClaim, }, { // claim with claim pre-bound to a PV that is pre-bound to the claim // by name. Check it gets bound and no annBoundByController is set. "2-4 - claim prebound to prebound volume by name", - newVolumeArray("volume2-4", "1Gi", "", "claim2-4", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume2-4", "1Gi", "uid2-4", "claim2-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim2-4", "uid2-4", "1Gi", "volume2-4", v1.ClaimPending), - newClaimArray("claim2-4", "uid2-4", "1Gi", "volume2-4", v1.ClaimBound, annBindCompleted), + newVolumeArray("volume2-4", "1Gi", "", "claim2-4", v1.VolumePending, 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, annBindCompleted), noevents, noerrors, testSyncClaim, }, { @@ -223,30 +223,30 @@ func TestSync(t *testing.T) { // claim by UID. Check it gets bound and no annBoundByController is // set. "2-5 - claim prebound to prebound volume by UID", - newVolumeArray("volume2-5", "1Gi", "uid2-5", "claim2-5", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume2-5", "1Gi", "uid2-5", "claim2-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim2-5", "uid2-5", "1Gi", "volume2-5", v1.ClaimPending), - newClaimArray("claim2-5", "uid2-5", "1Gi", "volume2-5", v1.ClaimBound, annBindCompleted), + newVolumeArray("volume2-5", "1Gi", "uid2-5", "claim2-5", v1.VolumePending, 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, annBindCompleted), noevents, noerrors, 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), - newVolumeArray("volume2-6", "1Gi", "uid2-6_1", "claim2-6_1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim2-6", "uid2-6", "1Gi", "volume2-6", v1.ClaimBound), - newClaimArray("claim2-6", "uid2-6", "1Gi", "volume2-6", v1.ClaimPending), + 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, }, { // 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), - newVolumeArray("volume2-7", "1Gi", "uid2-7_1", "claim2-7_1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim2-7", "uid2-7", "1Gi", "volume2-7", v1.ClaimBound, annBoundByController), - newClaimArray("claim2-7", "uid2-7", "1Gi", "volume2-7", v1.ClaimBound, annBoundByController), + 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, annBoundByController), + newClaimArray("claim2-7", "uid2-7", "1Gi", "volume2-7", v1.ClaimBound, nil, annBoundByController), noevents, noerrors, testSyncClaimError, }, { @@ -254,10 +254,10 @@ func TestSync(t *testing.T) { // unbound, but does not match the selector. Check it gets bound // and no annBoundByController is set. "2-8 - claim prebound to unbound volume that does not match the selector", - newVolumeArray("volume2-3", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume2-3", "1Gi", "uid2-3", "claim2-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - withLabelSelector(labels, newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", v1.ClaimPending)), - withLabelSelector(labels, newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", v1.ClaimBound, annBindCompleted)), + newVolumeArray("volume2-3", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume2-3", "1Gi", "uid2-3", "claim2-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + withLabelSelector(labels, newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", v1.ClaimPending, nil)), + withLabelSelector(labels, newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", v1.ClaimBound, nil, annBindCompleted)), noevents, noerrors, testSyncClaim, }, @@ -268,8 +268,8 @@ func TestSync(t *testing.T) { "3-1 - bound claim with missing VolumeName", novolumes, novolumes, - newClaimArray("claim3-1", "uid3-1", "10Gi", "", v1.ClaimBound, annBoundByController, annBindCompleted), - newClaimArray("claim3-1", "uid3-1", "10Gi", "", v1.ClaimLost, annBoundByController, annBindCompleted), + newClaimArray("claim3-1", "uid3-1", "10Gi", "", v1.ClaimBound, nil, annBoundByController, annBindCompleted), + newClaimArray("claim3-1", "uid3-1", "10Gi", "", v1.ClaimLost, nil, annBoundByController, annBindCompleted), []string{"Warning ClaimLost"}, noerrors, testSyncClaim, }, { @@ -278,28 +278,28 @@ func TestSync(t *testing.T) { "3-2 - bound claim with missing volume", novolumes, novolumes, - newClaimArray("claim3-2", "uid3-2", "10Gi", "volume3-2", v1.ClaimBound, annBoundByController, annBindCompleted), - newClaimArray("claim3-2", "uid3-2", "10Gi", "volume3-2", v1.ClaimLost, annBoundByController, annBindCompleted), + newClaimArray("claim3-2", "uid3-2", "10Gi", "volume3-2", v1.ClaimBound, nil, annBoundByController, annBindCompleted), + newClaimArray("claim3-2", "uid3-2", "10Gi", "volume3-2", v1.ClaimLost, nil, annBoundByController, annBindCompleted), []string{"Warning ClaimLost"}, noerrors, 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.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume3-3", "10Gi", "uid3-3", "claim3-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimPending, annBoundByController, annBindCompleted), - newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimBound, annBoundByController, annBindCompleted), + newVolumeArray("volume3-3", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume3-3", "10Gi", "uid3-3", "claim3-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimPending, nil, annBoundByController, annBindCompleted), + newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimBound, nil, annBoundByController, annBindCompleted), noevents, noerrors, 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.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume3-4", "10Gi", "claim3-4-x", "claim3-4", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim3-4", "uid3-4", "10Gi", "volume3-4", v1.ClaimPending, annBoundByController, annBindCompleted), - newClaimArray("claim3-4", "uid3-4", "10Gi", "volume3-4", v1.ClaimLost, annBoundByController, annBindCompleted), + newVolumeArray("volume3-4", "10Gi", "claim3-4-x", "claim3-4", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume3-4", "10Gi", "claim3-4-x", "claim3-4", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newClaimArray("claim3-4", "uid3-4", "10Gi", "volume3-4", v1.ClaimPending, nil, annBoundByController, annBindCompleted), + newClaimArray("claim3-4", "uid3-4", "10Gi", "volume3-4", v1.ClaimLost, nil, annBoundByController, annBindCompleted), []string{"Warning ClaimMisbound"}, noerrors, testSyncClaim, }, { @@ -307,10 +307,10 @@ func TestSync(t *testing.T) { // 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.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume3-5", "10Gi", "uid3-5", "claim3-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim3-5", "uid3-5", "10Gi", "volume3-5", v1.ClaimPending, annBindCompleted), - newClaimArray("claim3-5", "uid3-5", "10Gi", "volume3-5", v1.ClaimBound, annBindCompleted), + newVolumeArray("volume3-5", "10Gi", "uid3-5", "claim3-5", v1.VolumePending, 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, annBindCompleted), + newClaimArray("claim3-5", "uid3-5", "10Gi", "volume3-5", v1.ClaimBound, nil, annBindCompleted), noevents, noerrors, testSyncClaim, }, { @@ -318,10 +318,10 @@ func TestSync(t *testing.T) { // 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.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume3-6", "10Gi", "uid3-6-x", "claim3-6-x", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim3-6", "uid3-6", "10Gi", "volume3-6", v1.ClaimPending, annBindCompleted), - newClaimArray("claim3-6", "uid3-6", "10Gi", "volume3-6", v1.ClaimLost, annBindCompleted), + newVolumeArray("volume3-6", "10Gi", "uid3-6-x", "claim3-6-x", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume3-6", "10Gi", "uid3-6-x", "claim3-6-x", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newClaimArray("claim3-6", "uid3-6", "10Gi", "volume3-6", v1.ClaimPending, nil, annBindCompleted), + newClaimArray("claim3-6", "uid3-6", "10Gi", "volume3-6", v1.ClaimLost, nil, annBindCompleted), []string{"Warning ClaimMisbound"}, noerrors, testSyncClaim, }, { @@ -329,18 +329,18 @@ func TestSync(t *testing.T) { // 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.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume3-3", "10Gi", "uid3-3", "claim3-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - withLabelSelector(labels, newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimPending, annBoundByController, annBindCompleted)), - withLabelSelector(labels, newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimBound, annBoundByController, annBindCompleted)), + newVolumeArray("volume3-3", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume3-3", "10Gi", "uid3-3", "claim3-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + withLabelSelector(labels, newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimPending, nil, annBoundByController, annBindCompleted)), + withLabelSelector(labels, newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", v1.ClaimBound, nil, annBoundByController, annBindCompleted)), noevents, noerrors, 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.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume4-1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain), + newVolumeArray("volume4-1", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume4-1", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), noclaims, noclaims, noevents, noerrors, testSyncVolume, @@ -349,8 +349,8 @@ func TestSync(t *testing.T) { // syncVolume with prebound pending volume. Check it's marked as // Available. "4-2 - pending prebound volume", - newVolumeArray("volume4-2", "10Gi", "", "claim4-2", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume4-2", "10Gi", "", "claim4-2", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain), + newVolumeArray("volume4-2", "10Gi", "", "claim4-2", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume4-2", "10Gi", "", "claim4-2", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), noclaims, noclaims, noevents, noerrors, testSyncVolume, @@ -359,8 +359,8 @@ func TestSync(t *testing.T) { // 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), - newVolumeArray("volume4-3", "10Gi", "uid4-3", "claim4-3", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain), + 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, @@ -369,50 +369,50 @@ func TestSync(t *testing.T) { // 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), - newVolumeArray("volume4-4", "10Gi", "uid4-4", "claim4-4", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim4-4", "uid4-4-x", "10Gi", "volume4-4", v1.ClaimBound, annBindCompleted), - newClaimArray("claim4-4", "uid4-4-x", "10Gi", "volume4-4", v1.ClaimBound, annBindCompleted), + 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, annBindCompleted), + newClaimArray("claim4-4", "uid4-4-x", "10Gi", "volume4-4", v1.ClaimBound, nil, annBindCompleted), noevents, noerrors, 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, annBoundByController), - newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending), - newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending), + newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending, nil), + newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending, nil), noevents, noerrors, 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), - newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending), - newClaimArray("claim4-5", "uid4-5", "10Gi", "", v1.ClaimPending), + 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, }, { // 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), - newVolumeArray("volume4-6", "10Gi", "uid4-6", "claim4-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim4-6", "uid4-6", "10Gi", "volume4-6", v1.ClaimBound), - newClaimArray("claim4-6", "uid4-6", "10Gi", "volume4-6", v1.ClaimBound), + 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, }, { // 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, annBoundByController), - newVolumeArray("volume4-7", "10Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim4-7", "uid4-7", "10Gi", "volume4-7-x", v1.ClaimBound), - newClaimArray("claim4-7", "uid4-7", "10Gi", "volume4-7-x", v1.ClaimBound), + newVolumeArray("volume4-7", "10Gi", "uid4-7", "claim4-7", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, 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, }, { @@ -420,10 +420,10 @@ func TestSync(t *testing.T) { // 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), - newVolumeArray("volume4-8", "10Gi", "", "claim4-8", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain), - newClaimArray("claim4-8", "uid4-8", "10Gi", "volume4-8-x", v1.ClaimBound), - newClaimArray("claim4-8", "uid4-8", "10Gi", "volume4-8-x", v1.ClaimBound), + 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, }, @@ -433,15 +433,15 @@ func TestSync(t *testing.T) { // smaller PV available "13-1 - binding to class", []*v1.PersistentVolume{ - newVolume("volume13-1-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("volume13-1-2", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, v1.BetaStorageClassAnnotation), + newVolume("volume13-1-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolume("volume13-1-2", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classGold), }, []*v1.PersistentVolume{ - newVolume("volume13-1-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("volume13-1-2", "10Gi", "uid13-1", "claim13-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController, v1.BetaStorageClassAnnotation), + newVolume("volume13-1-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolume("volume13-1-2", "10Gi", "uid13-1", "claim13-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classGold, annBoundByController), }, - newClaimArray("claim13-1", "uid13-1", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), - withExpectedCapacity("10Gi", newClaimArray("claim13-1", "uid13-1", "1Gi", "volume13-1-2", v1.ClaimBound, annBoundByController, v1.BetaStorageClassAnnotation, annBindCompleted)), + newClaimArray("claim13-1", "uid13-1", "1Gi", "", v1.ClaimPending, &classGold), + withExpectedCapacity("10Gi", newClaimArray("claim13-1", "uid13-1", "1Gi", "volume13-1-2", v1.ClaimBound, &classGold, annBoundByController, annBindCompleted)), noevents, noerrors, testSyncClaim, }, { @@ -449,61 +449,51 @@ func TestSync(t *testing.T) { // smaller PV with a class available "13-2 - binding without a class", []*v1.PersistentVolume{ - newVolume("volume13-2-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, v1.BetaStorageClassAnnotation), - newVolume("volume13-2-2", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), + newVolume("volume13-2-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classGold), + newVolume("volume13-2-2", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), }, []*v1.PersistentVolume{ - newVolume("volume13-2-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, v1.BetaStorageClassAnnotation), - newVolume("volume13-2-2", "10Gi", "uid13-2", "claim13-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), + newVolume("volume13-2-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classGold), + newVolume("volume13-2-2", "10Gi", "uid13-2", "claim13-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), }, - newClaimArray("claim13-2", "uid13-2", "1Gi", "", v1.ClaimPending), - withExpectedCapacity("10Gi", newClaimArray("claim13-2", "uid13-2", "1Gi", "volume13-2-2", v1.ClaimBound, annBoundByController, annBindCompleted)), + newClaimArray("claim13-2", "uid13-2", "1Gi", "", v1.ClaimPending, nil), + withExpectedCapacity("10Gi", newClaimArray("claim13-2", "uid13-2", "1Gi", "volume13-2-2", v1.ClaimBound, nil, annBoundByController, annBindCompleted)), noevents, noerrors, 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", - volumeWithClass("silver", []*v1.PersistentVolume{ - newVolume("volume13-3-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("volume13-3-2", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, v1.BetaStorageClassAnnotation), - }), - volumeWithClass("silver", []*v1.PersistentVolume{ - newVolume("volume13-3-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("volume13-3-2", "10Gi", "uid13-3", "claim13-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController, v1.BetaStorageClassAnnotation), - }), - newClaimArray("claim13-3", "uid13-3", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), - withExpectedCapacity("10Gi", newClaimArray("claim13-3", "uid13-3", "1Gi", "volume13-3-2", v1.ClaimBound, annBoundByController, annBindCompleted, v1.BetaStorageClassAnnotation)), + []*v1.PersistentVolume{ + newVolume("volume13-3-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classSilver), + newVolume("volume13-3-2", "10Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classGold), + }, + []*v1.PersistentVolume{ + newVolume("volume13-3-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classSilver), + newVolume("volume13-3-2", "10Gi", "uid13-3", "claim13-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classGold, annBoundByController), + }, + newClaimArray("claim13-3", "uid13-3", "1Gi", "", v1.ClaimPending, &classGold), + withExpectedCapacity("10Gi", newClaimArray("claim13-3", "uid13-3", "1Gi", "volume13-3-2", v1.ClaimBound, &classGold, annBoundByController, annBindCompleted)), noevents, noerrors, testSyncClaim, }, { // syncVolume binds claim requesting class "" to claim to PV with // class="" "13-4 - empty class", - volumeWithClass("", newVolumeArray("volume13-4", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain)), - volumeWithClass("", newVolumeArray("volume13-4", "1Gi", "uid13-4", "claim13-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController)), - claimWithClass("", newClaimArray("claim13-4", "uid13-4", "1Gi", "", v1.ClaimPending)), - claimWithClass("", newClaimArray("claim13-4", "uid13-4", "1Gi", "volume13-4", v1.ClaimBound, annBoundByController, annBindCompleted)), + newVolumeArray("volume13-4", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume13-4", "1Gi", "uid13-4", "claim13-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newClaimArray("claim13-4", "uid13-4", "1Gi", "", v1.ClaimPending, &classEmpty), + newClaimArray("claim13-4", "uid13-4", "1Gi", "volume13-4", v1.ClaimBound, &classEmpty, annBoundByController, annBindCompleted), noevents, noerrors, testSyncClaim, }, { // syncVolume binds claim requesting class nil to claim to PV with // class = "" "13-5 - nil class", - volumeWithClass("", newVolumeArray("volume13-5", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain)), - volumeWithClass("", newVolumeArray("volume13-5", "1Gi", "uid13-5", "claim13-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController)), - newClaimArray("claim13-5", "uid13-5", "1Gi", "", v1.ClaimPending), - newClaimArray("claim13-5", "uid13-5", "1Gi", "volume13-5", v1.ClaimBound, annBoundByController, annBindCompleted), - noevents, noerrors, testSyncClaim, - }, - { - // syncVolume binds claim requesting class "" to claim to PV with - // class=nil - "13-6 - nil class in PV, '' class in claim", - newVolumeArray("volume13-6", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume13-6", "1Gi", "uid13-6", "claim13-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - claimWithClass("", newClaimArray("claim13-6", "uid13-6", "1Gi", "", v1.ClaimPending)), - claimWithClass("", newClaimArray("claim13-6", "uid13-6", "1Gi", "volume13-6", v1.ClaimBound, annBoundByController, annBindCompleted)), + newVolumeArray("volume13-5", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume13-5", "1Gi", "uid13-5", "claim13-5", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newClaimArray("claim13-5", "uid13-5", "1Gi", "", v1.ClaimPending, nil), + newClaimArray("claim13-5", "uid13-5", "1Gi", "volume13-5", v1.ClaimBound, nil, annBoundByController, annBindCompleted), noevents, noerrors, testSyncClaim, }, } @@ -530,10 +520,10 @@ func TestMultiSync(t *testing.T) { { // syncClaim binds to a matching unbound volume. "10-1 - successful bind", - newVolumeArray("volume10-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume10-1", "1Gi", "uid10-1", "claim10-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - newClaimArray("claim10-1", "uid10-1", "1Gi", "", v1.ClaimPending), - newClaimArray("claim10-1", "uid10-1", "1Gi", "volume10-1", v1.ClaimBound, annBoundByController, annBindCompleted), + newVolumeArray("volume10-1", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume10-1", "1Gi", "uid10-1", "claim10-1", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newClaimArray("claim10-1", "uid10-1", "1Gi", "", v1.ClaimPending, nil), + newClaimArray("claim10-1", "uid10-1", "1Gi", "volume10-1", v1.ClaimBound, nil, annBoundByController, annBindCompleted), noevents, noerrors, testSyncClaim, }, { @@ -541,15 +531,15 @@ func TestMultiSync(t *testing.T) { // wins and the second rolls back. "10-2 - bind PV race", []*v1.PersistentVolume{ - newVolume("volume10-2-1", "1Gi", "uid10-2", "claim10-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - newVolume("volume10-2-2", "1Gi", "uid10-2", "claim10-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), + newVolume("volume10-2-1", "1Gi", "uid10-2", "claim10-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newVolume("volume10-2-2", "1Gi", "uid10-2", "claim10-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), }, []*v1.PersistentVolume{ - newVolume("volume10-2-1", "1Gi", "uid10-2", "claim10-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), - newVolume("volume10-2-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain), + newVolume("volume10-2-1", "1Gi", "uid10-2", "claim10-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newVolume("volume10-2-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), }, - newClaimArray("claim10-2", "uid10-2", "1Gi", "volume10-2-1", v1.ClaimBound, annBoundByController, annBindCompleted), - newClaimArray("claim10-2", "uid10-2", "1Gi", "volume10-2-1", v1.ClaimBound, annBoundByController, annBindCompleted), + newClaimArray("claim10-2", "uid10-2", "1Gi", "volume10-2-1", v1.ClaimBound, nil, annBoundByController, annBindCompleted), + newClaimArray("claim10-2", "uid10-2", "1Gi", "volume10-2-1", v1.ClaimBound, nil, annBoundByController, annBindCompleted), noevents, noerrors, testSyncClaim, }, } diff --git a/pkg/controller/volume/persistentvolume/delete_test.go b/pkg/controller/volume/persistentvolume/delete_test.go index b4c3effc420..592c51ab941 100644 --- a/pkg/controller/volume/persistentvolume/delete_test.go +++ b/pkg/controller/volume/persistentvolume/delete_test.go @@ -33,7 +33,7 @@ func TestDeleteSync(t *testing.T) { { // delete volume bound by controller "8-1 - successful delete", - newVolumeArray("volume8-1", "1Gi", "uid8-1", "claim8-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController), + newVolumeArray("volume8-1", "1Gi", "uid8-1", "claim8-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, annBoundByController), novolumes, noclaims, noclaims, @@ -45,7 +45,7 @@ func TestDeleteSync(t *testing.T) { { // delete volume bound by user "8-2 - successful delete with prebound volume", - newVolumeArray("volume8-2", "1Gi", "uid8-2", "claim8-2", v1.VolumeBound, v1.PersistentVolumeReclaimDelete), + newVolumeArray("volume8-2", "1Gi", "uid8-2", "claim8-2", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), novolumes, noclaims, noclaims, @@ -57,8 +57,8 @@ func TestDeleteSync(t *testing.T) { { // delete failure - plugin not found "8-3 - plugin not found", - newVolumeArray("volume8-3", "1Gi", "uid8-3", "claim8-3", v1.VolumeBound, v1.PersistentVolumeReclaimDelete), - 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)), + 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, @@ -66,8 +66,8 @@ func TestDeleteSync(t *testing.T) { { // delete failure - newDeleter returns error "8-4 - newDeleter returns error", - newVolumeArray("volume8-4", "1Gi", "uid8-4", "claim8-4", v1.VolumeBound, v1.PersistentVolumeReclaimDelete), - 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)), + 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, @@ -76,8 +76,8 @@ func TestDeleteSync(t *testing.T) { { // delete failure - delete() returns error "8-5 - delete returns error", - newVolumeArray("volume8-5", "1Gi", "uid8-5", "claim8-5", v1.VolumeBound, v1.PersistentVolumeReclaimDelete), - withMessage("Mock delete error", newVolumeArray("volume8-5", "1Gi", "uid8-5", "claim8-5", v1.VolumeFailed, v1.PersistentVolumeReclaimDelete)), + 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, @@ -86,7 +86,7 @@ func TestDeleteSync(t *testing.T) { { // 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), + newVolumeArray("volume8-6", "1Gi", "uid8-6", "claim8-6", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), novolumes, noclaims, noclaims, @@ -103,17 +103,17 @@ func TestDeleteSync(t *testing.T) { // 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, annBoundByController), - newVolumeArray("volume8-7", "1Gi", "uid8-7", "claim8-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController), + newVolumeArray("volume8-7", "1Gi", "uid8-7", "claim8-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, annBoundByController), + newVolumeArray("volume8-7", "1Gi", "uid8-7", "claim8-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, annBoundByController), noclaims, - newClaimArray("claim8-7", "uid8-7", "10Gi", "volume8-7", v1.ClaimBound), + newClaimArray("claim8-7", "uid8-7", "10Gi", "volume8-7", v1.ClaimBound, nil), noevents, noerrors, wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationDelete, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *volumeReactor) { reactor.lock.Lock() defer reactor.lock.Unlock() // Bind the volume to resurrected claim (this should never // happen) - claim := newClaim("claim8-7", "uid8-7", "10Gi", "volume8-7", v1.ClaimBound) + claim := newClaim("claim8-7", "uid8-7", "10Gi", "volume8-7", v1.ClaimBound, nil) reactor.claims[claim.Name] = claim ctrl.claims.Add(claim) volume := reactor.volumes["volume8-7"] @@ -124,10 +124,10 @@ 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), + newVolumeArray("volume8-9", "1Gi", "uid8-9", "claim8-9", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), novolumes, - newClaimArray("claim8-9", "uid8-9-x", "10Gi", "", v1.ClaimPending), - newClaimArray("claim8-9", "uid8-9-x", "10Gi", "", v1.ClaimPending), + newClaimArray("claim8-9", "uid8-9-x", "10Gi", "", v1.ClaimPending, nil), + newClaimArray("claim8-9", "uid8-9-x", "10Gi", "", v1.ClaimPending, nil), noevents, noerrors, // Inject deleter into the controller and call syncVolume. The // deleter simulates one delete() call that succeeds. @@ -136,8 +136,8 @@ func TestDeleteSync(t *testing.T) { { // PV requires external deleter "8-10 - external deleter", - newVolumeArray("volume8-10", "1Gi", "uid10-1", "claim10-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController), - newVolumeArray("volume8-10", "1Gi", "uid10-1", "claim10-1", v1.VolumeReleased, v1.PersistentVolumeReclaimDelete, annBoundByController), + newVolumeArray("volume8-10", "1Gi", "uid10-1", "claim10-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, annBoundByController), + newVolumeArray("volume8-10", "1Gi", "uid10-1", "claim10-1", v1.VolumeReleased, v1.PersistentVolumeReclaimDelete, classEmpty, annBoundByController), noclaims, noclaims, noevents, noerrors, @@ -153,15 +153,15 @@ func TestDeleteSync(t *testing.T) { // One of the PVs is deleted. "8-11 - two PVs provisioned for a single claim", []*v1.PersistentVolume{ - newVolume("volume8-11-1", "1Gi", "uid8-11", "claim8-11", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annDynamicallyProvisioned), - newVolume("volume8-11-2", "1Gi", "uid8-11", "claim8-11", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annDynamicallyProvisioned), + newVolume("volume8-11-1", "1Gi", "uid8-11", "claim8-11", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, annDynamicallyProvisioned), + newVolume("volume8-11-2", "1Gi", "uid8-11", "claim8-11", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, annDynamicallyProvisioned), }, []*v1.PersistentVolume{ - newVolume("volume8-11-2", "1Gi", "uid8-11", "claim8-11", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annDynamicallyProvisioned), + newVolume("volume8-11-2", "1Gi", "uid8-11", "claim8-11", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, 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), - newClaimArray("claim8-11", "uid8-11", "10Gi", "volume8-11-2", v1.ClaimBound), + 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, // Inject deleter into the controller and call syncVolume. The // deleter simulates one delete() call that succeeds. @@ -173,16 +173,16 @@ func TestDeleteSync(t *testing.T) { // external provisioner. "8-12 - two PVs externally provisioned for a single claim", []*v1.PersistentVolume{ - newVolume("volume8-12-1", "1Gi", "uid8-12", "claim8-12", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annDynamicallyProvisioned), - newVolume("volume8-12-2", "1Gi", "uid8-12", "claim8-12", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annDynamicallyProvisioned), + newVolume("volume8-12-1", "1Gi", "uid8-12", "claim8-12", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, annDynamicallyProvisioned), + newVolume("volume8-12-2", "1Gi", "uid8-12", "claim8-12", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, annDynamicallyProvisioned), }, []*v1.PersistentVolume{ - newVolume("volume8-12-1", "1Gi", "uid8-12", "claim8-12", v1.VolumeReleased, v1.PersistentVolumeReclaimDelete, annDynamicallyProvisioned), - newVolume("volume8-12-2", "1Gi", "uid8-12", "claim8-12", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annDynamicallyProvisioned), + newVolume("volume8-12-1", "1Gi", "uid8-12", "claim8-12", v1.VolumeReleased, v1.PersistentVolumeReclaimDelete, classEmpty, annDynamicallyProvisioned), + newVolume("volume8-12-2", "1Gi", "uid8-12", "claim8-12", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, 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), - newClaimArray("claim8-12", "uid8-12", "10Gi", "volume8-12-2", v1.ClaimBound), + 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 *volumeReactor, test controllerTest) error { // Inject external deleter annotation @@ -215,7 +215,7 @@ func TestDeleteMultiSync(t *testing.T) { // delete failure - delete returns error. The controller should // try again. "9-1 - delete returns error", - newVolumeArray("volume9-1", "1Gi", "uid9-1", "claim9-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete), + newVolumeArray("volume9-1", "1Gi", "uid9-1", "claim9-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), novolumes, noclaims, noclaims, diff --git a/pkg/controller/volume/persistentvolume/framework_test.go b/pkg/controller/volume/persistentvolume/framework_test.go index 6903bd7516a..d3725074d2d 100644 --- a/pkg/controller/volume/persistentvolume/framework_test.go +++ b/pkg/controller/volume/persistentvolume/framework_test.go @@ -620,7 +620,7 @@ func newTestController(kubeClient clientset.Interface, informerFactory informers } // newVolume returns a new volume with given attributes -func newVolume(name, capacity, boundToClaimUID, boundToClaimName string, phase v1.PersistentVolumePhase, reclaimPolicy v1.PersistentVolumeReclaimPolicy, annotations ...string) *v1.PersistentVolume { +func newVolume(name, capacity, boundToClaimUID, boundToClaimName string, phase v1.PersistentVolumePhase, reclaimPolicy v1.PersistentVolumeReclaimPolicy, class string, annotations ...string) *v1.PersistentVolume { volume := v1.PersistentVolume{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -635,6 +635,7 @@ func newVolume(name, capacity, boundToClaimUID, boundToClaimName string, phase v }, AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce, v1.ReadOnlyMany}, PersistentVolumeReclaimPolicy: reclaimPolicy, + StorageClassName: class, }, Status: v1.PersistentVolumeStatus{ Phase: phase, @@ -657,8 +658,6 @@ func newVolume(name, capacity, boundToClaimUID, boundToClaimName string, phase v switch a { case annDynamicallyProvisioned: volume.Annotations[a] = mockPluginName - case v1.BetaStorageClassAnnotation: - volume.Annotations[a] = "gold" default: volume.Annotations[a] = "yes" } @@ -706,27 +705,16 @@ func withMessage(message string, volumes []*v1.PersistentVolume) []*v1.Persisten return volumes } -// volumeWithClass saves given class into storage.StorageClassAnnotation annotation. -// Meant to be used to compose claims specified inline in a test. -func volumeWithClass(className string, volumes []*v1.PersistentVolume) []*v1.PersistentVolume { - if volumes[0].Annotations == nil { - volumes[0].Annotations = map[string]string{v1.BetaStorageClassAnnotation: className} - } else { - volumes[0].Annotations[v1.BetaStorageClassAnnotation] = className - } - return volumes -} - // newVolumeArray returns array with a single volume that would be returned by // newVolume() with the same parameters. -func newVolumeArray(name, capacity, boundToClaimUID, boundToClaimName string, phase v1.PersistentVolumePhase, reclaimPolicy v1.PersistentVolumeReclaimPolicy, annotations ...string) []*v1.PersistentVolume { +func newVolumeArray(name, capacity, boundToClaimUID, boundToClaimName string, phase v1.PersistentVolumePhase, reclaimPolicy v1.PersistentVolumeReclaimPolicy, class string, annotations ...string) []*v1.PersistentVolume { return []*v1.PersistentVolume{ - newVolume(name, capacity, boundToClaimUID, boundToClaimName, phase, reclaimPolicy, annotations...), + newVolume(name, capacity, boundToClaimUID, boundToClaimName, phase, reclaimPolicy, class, annotations...), } } // newClaim returns a new claim with given attributes -func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.PersistentVolumeClaimPhase, annotations ...string) *v1.PersistentVolumeClaim { +func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.PersistentVolumeClaimPhase, class *string, annotations ...string) *v1.PersistentVolumeClaim { claim := v1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -741,7 +729,8 @@ func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.Persisten v1.ResourceName(v1.ResourceStorage): resource.MustParse(capacity), }, }, - VolumeName: boundToVolume, + VolumeName: boundToVolume, + StorageClassName: class, }, Status: v1.PersistentVolumeClaimStatus{ Phase: phase, @@ -754,8 +743,6 @@ func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.Persisten claim.Annotations = make(map[string]string) for _, a := range annotations { switch a { - case v1.BetaStorageClassAnnotation: - claim.Annotations[a] = "gold" case annStorageProvisioner: claim.Annotations[a] = mockPluginName default: @@ -777,23 +764,12 @@ func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.Persisten // newClaimArray returns array with a single claim that would be returned by // newClaim() with the same parameters. -func newClaimArray(name, claimUID, capacity, boundToVolume string, phase v1.PersistentVolumeClaimPhase, annotations ...string) []*v1.PersistentVolumeClaim { +func newClaimArray(name, claimUID, capacity, boundToVolume string, phase v1.PersistentVolumeClaimPhase, class *string, annotations ...string) []*v1.PersistentVolumeClaim { return []*v1.PersistentVolumeClaim{ - newClaim(name, claimUID, capacity, boundToVolume, phase, annotations...), + newClaim(name, claimUID, capacity, boundToVolume, phase, class, annotations...), } } -// claimWithClass saves given class into storage.StorageClassAnnotation annotation. -// Meant to be used to compose claims specified inline in a test. -func claimWithClass(className string, claims []*v1.PersistentVolumeClaim) []*v1.PersistentVolumeClaim { - if claims[0].Annotations == nil { - claims[0].Annotations = map[string]string{v1.BetaStorageClassAnnotation: className} - } else { - claims[0].Annotations[v1.BetaStorageClassAnnotation] = className - } - return claims -} - // claimWithAnnotation saves given annotation into given claims. // Meant to be used to compose claims specified inline in a test. func claimWithAnnotation(name, value string, claims []*v1.PersistentVolumeClaim) []*v1.PersistentVolumeClaim { @@ -827,6 +803,15 @@ type operationType string const operationDelete = "Delete" const operationRecycle = "Recycle" +var ( + classGold string = "gold" + classSilver string = "silver" + classEmpty string = "" + classNonExisting string = "non-existing" + classExternal string = "external" + classUnknownInternal string = "unknown-internal" +) + // wrapTestWithPluginCalls returns a testCall that: // - configures controller with a volume plugin that implements recycler, // deleter and provisioner. The plugin retunrs provided errors when a volume diff --git a/pkg/controller/volume/persistentvolume/index_test.go b/pkg/controller/volume/persistentvolume/index_test.go index 995bd05003b..f8ffb7c07ba 100644 --- a/pkg/controller/volume/persistentvolume/index_test.go +++ b/pkg/controller/volume/persistentvolume/index_test.go @@ -111,24 +111,20 @@ func TestMatchVolume(t *testing.T) { "successful-match-with-class": { expectedMatch: "gce-pd-silver1", claim: makePVC("1G", func(pvc *v1.PersistentVolumeClaim) { - pvc.ObjectMeta.Annotations = map[string]string{ - v1.BetaStorageClassAnnotation: "silver", - } pvc.Spec.Selector = &metav1.LabelSelector{ MatchLabels: map[string]string{ "should-exist": "true", }, } pvc.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce} + pvc.Spec.StorageClassName = &classSilver }), }, "successful-match-with-class-and-labels": { expectedMatch: "gce-pd-silver2", claim: makePVC("1G", func(pvc *v1.PersistentVolumeClaim) { - pvc.ObjectMeta.Annotations = map[string]string{ - v1.BetaStorageClassAnnotation: "silver", - } pvc.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce} + pvc.Spec.StorageClassName = &classSilver }), }, } @@ -541,9 +537,6 @@ func createTestVolumes() []*v1.PersistentVolume { Labels: map[string]string{ "should-exist": "true", }, - Annotations: map[string]string{ - v1.BetaStorageClassAnnotation: "silver", - }, }, Spec: v1.PersistentVolumeSpec{ Capacity: v1.ResourceList{ @@ -555,15 +548,13 @@ func createTestVolumes() []*v1.PersistentVolume { AccessModes: []v1.PersistentVolumeAccessMode{ v1.ReadWriteOnce, }, + StorageClassName: classSilver, }, }, { ObjectMeta: metav1.ObjectMeta{ UID: "gce-pd-silver2", Name: "gce0024", - Annotations: map[string]string{ - v1.BetaStorageClassAnnotation: "silver", - }, }, Spec: v1.PersistentVolumeSpec{ Capacity: v1.ResourceList{ @@ -575,15 +566,13 @@ func createTestVolumes() []*v1.PersistentVolume { AccessModes: []v1.PersistentVolumeAccessMode{ v1.ReadWriteOnce, }, + StorageClassName: classSilver, }, }, { ObjectMeta: metav1.ObjectMeta{ UID: "gce-pd-gold", Name: "gce0025", - Annotations: map[string]string{ - v1.BetaStorageClassAnnotation: "gold", - }, }, Spec: v1.PersistentVolumeSpec{ Capacity: v1.ResourceList{ @@ -595,6 +584,7 @@ func createTestVolumes() []*v1.PersistentVolume { AccessModes: []v1.PersistentVolumeAccessMode{ v1.ReadWriteOnce, }, + StorageClassName: classGold, }, }, } diff --git a/pkg/controller/volume/persistentvolume/provision_test.go b/pkg/controller/volume/persistentvolume/provision_test.go index 9827bb2d3df..20996919f4e 100644 --- a/pkg/controller/volume/persistentvolume/provision_test.go +++ b/pkg/controller/volume/persistentvolume/provision_test.go @@ -108,10 +108,10 @@ func TestProvisionSync(t *testing.T) { // Provision a volume (with a default class) "11-1 - successful provision with storage class 1", novolumes, - newVolumeArray("pvc-uid11-1", "1Gi", "uid11-1", "claim11-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, v1.BetaStorageClassAnnotation), - newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newVolumeArray("pvc-uid11-1", "1Gi", "uid11-1", "claim11-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, annBoundByController, annDynamicallyProvisioned), + newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, &classGold), // Binding will be completed in the next syncClaim - newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, &classGold, annStorageProvisioner), []string{"Normal ProvisioningSucceeded"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), }, { @@ -119,8 +119,8 @@ func TestProvisionSync(t *testing.T) { "11-2 - plugin not found", novolumes, novolumes, - newClaimArray("claim11-2", "uid11-2", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), - newClaimArray("claim11-2", "uid11-2", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newClaimArray("claim11-2", "uid11-2", "1Gi", "", v1.ClaimPending, &classGold), + newClaimArray("claim11-2", "uid11-2", "1Gi", "", v1.ClaimPending, &classGold), []string{"Warning ProvisioningFailed"}, noerrors, testSyncClaim, }, @@ -129,8 +129,8 @@ func TestProvisionSync(t *testing.T) { "11-3 - newProvisioner failure", novolumes, novolumes, - newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), - newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, &classGold), + newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, &classGold, annStorageProvisioner), []string{"Warning ProvisioningFailed"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, @@ -139,18 +139,18 @@ func TestProvisionSync(t *testing.T) { "11-4 - provision failure", novolumes, novolumes, - newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), - newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, &classGold), + newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, &classGold, annStorageProvisioner), []string{"Warning ProvisioningFailed"}, noerrors, 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.VolumePending, v1.PersistentVolumeReclaimRetain, v1.BetaStorageClassAnnotation), - newVolumeArray("volume11-6", "1Gi", "uid11-6", "claim11-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController, v1.BetaStorageClassAnnotation), - newClaimArray("claim11-6", "uid11-6", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), - newClaimArray("claim11-6", "uid11-6", "1Gi", "volume11-6", v1.ClaimBound, v1.BetaStorageClassAnnotation, annBoundByController, annBindCompleted), + newVolumeArray("volume11-6", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classGold), + newVolumeArray("volume11-6", "1Gi", "uid11-6", "claim11-6", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classGold, annBoundByController), + newClaimArray("claim11-6", "uid11-6", "1Gi", "", v1.ClaimPending, &classGold), + newClaimArray("claim11-6", "uid11-6", "1Gi", "volume11-6", v1.ClaimBound, &classGold, annBoundByController, annBindCompleted), noevents, noerrors, // No provisioning plugin confingure - makes the test fail when // the controller errorneously tries to provision something @@ -161,16 +161,16 @@ func TestProvisionSync(t *testing.T) { // a volume. "11-7 - claim is bound before provisioning", novolumes, - newVolumeArray("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, v1.BetaStorageClassAnnotation), - newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newVolumeArray("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, annBoundByController, annDynamicallyProvisioned), + 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, v1.BetaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, &classGold, annStorageProvisioner), noevents, noerrors, wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *volumeReactor) { // Create a volume before provisionClaimOperation starts. // This similates a parallel controller provisioning the volume. reactor.lock.Lock() - volume := newVolume("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, v1.BetaStorageClassAnnotation) + volume := newVolume("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, annBoundByController, annDynamicallyProvisioned) reactor.volumes[volume.Name] = volume reactor.lock.Unlock() }), @@ -180,10 +180,10 @@ func TestProvisionSync(t *testing.T) { // second retry succeeds "11-8 - cannot save provisioned volume", novolumes, - newVolumeArray("pvc-uid11-8", "1Gi", "uid11-8", "claim11-8", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, v1.BetaStorageClassAnnotation), - newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), + newVolumeArray("pvc-uid11-8", "1Gi", "uid11-8", "claim11-8", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, annBoundByController, annDynamicallyProvisioned), + 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, v1.BetaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, &classGold, annStorageProvisioner), []string{"Normal ProvisioningSucceeded"}, []reactorError{ // Inject error to the first @@ -199,8 +199,8 @@ func TestProvisionSync(t *testing.T) { "11-9 - cannot save provisioned volume, delete succeeds", novolumes, novolumes, - newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), - newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, &classGold), + newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, &classGold, annStorageProvisioner), []string{"Warning ProvisioningFailed"}, []reactorError{ // Inject error to five kubeclient.PersistentVolumes.Create() @@ -224,8 +224,8 @@ func TestProvisionSync(t *testing.T) { "11-10 - cannot save provisioned volume, no delete plugin found", novolumes, novolumes, - newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), - newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, &classGold), + newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, &classGold, annStorageProvisioner), []string{"Warning ProvisioningFailed", "Warning ProvisioningCleanupFailed"}, []reactorError{ // Inject error to five kubeclient.PersistentVolumes.Create() @@ -245,8 +245,8 @@ func TestProvisionSync(t *testing.T) { "11-11 - cannot save provisioned volume, deleter fails", novolumes, novolumes, - newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), - newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, &classGold), + newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, &classGold, annStorageProvisioner), []string{"Warning ProvisioningFailed", "Warning ProvisioningCleanupFailed"}, []reactorError{ // Inject error to five kubeclient.PersistentVolumes.Create() @@ -275,8 +275,8 @@ func TestProvisionSync(t *testing.T) { "11-12 - cannot save provisioned volume, delete succeeds 2nd time", novolumes, novolumes, - newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), - newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, &classGold), + newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, &classGold, annStorageProvisioner), []string{"Warning ProvisioningFailed"}, []reactorError{ // Inject error to five kubeclient.PersistentVolumes.Create() @@ -301,10 +301,10 @@ func TestProvisionSync(t *testing.T) { // Provision a volume (with non-default class) "11-13 - successful provision with storage class 2", novolumes, - volumeWithClass("silver", newVolumeArray("pvc-uid11-13", "1Gi", "uid11-13", "claim11-13", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned)), - claimWithClass("silver", newClaimArray("claim11-13", "uid11-13", "1Gi", "", v1.ClaimPending)), + newVolumeArray("pvc-uid11-13", "1Gi", "uid11-13", "claim11-13", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classSilver, annBoundByController, annDynamicallyProvisioned), + newClaimArray("claim11-13", "uid11-13", "1Gi", "", v1.ClaimPending, &classSilver), // Binding will be completed in the next syncClaim - claimWithClass("silver", newClaimArray("claim11-13", "uid11-13", "1Gi", "", v1.ClaimPending, annStorageProvisioner)), + newClaimArray("claim11-13", "uid11-13", "1Gi", "", v1.ClaimPending, &classSilver, annStorageProvisioner), []string{"Normal ProvisioningSucceeded"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision2Success}, testSyncClaim), }, { @@ -312,8 +312,8 @@ func TestProvisionSync(t *testing.T) { "11-14 - fail due to non-existing class", novolumes, novolumes, - claimWithClass("non-existing", newClaimArray("claim11-14", "uid11-14", "1Gi", "", v1.ClaimPending)), - claimWithClass("non-existing", newClaimArray("claim11-14", "uid11-14", "1Gi", "", v1.ClaimPending)), + newClaimArray("claim11-14", "uid11-14", "1Gi", "", v1.ClaimPending, &classNonExisting), + newClaimArray("claim11-14", "uid11-14", "1Gi", "", v1.ClaimPending, &classNonExisting), noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, { @@ -321,8 +321,8 @@ func TestProvisionSync(t *testing.T) { "11-15 - no provisioning with class=''", novolumes, novolumes, - claimWithClass("", newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending)), - claimWithClass("", newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending)), + newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending, &classEmpty), + newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending, &classEmpty), noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, { @@ -330,8 +330,8 @@ func TestProvisionSync(t *testing.T) { "11-16 - no provisioning with class=nil", novolumes, novolumes, - newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending), - newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending), + newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending, nil), + newClaimArray("claim11-15", "uid11-15", "1Gi", "", v1.ClaimPending, nil), noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, { @@ -339,9 +339,9 @@ func TestProvisionSync(t *testing.T) { "11-17 - external provisioner", novolumes, novolumes, - claimWithClass("external", newClaimArray("claim11-17", "uid11-17", "1Gi", "", v1.ClaimPending)), + newClaimArray("claim11-17", "uid11-17", "1Gi", "", v1.ClaimPending, &classExternal), claimWithAnnotation(annStorageProvisioner, "vendor.com/my-volume", - claimWithClass("external", newClaimArray("claim11-17", "uid11-17", "1Gi", "", v1.ClaimPending))), + newClaimArray("claim11-17", "uid11-17", "1Gi", "", v1.ClaimPending, &classExternal)), []string{"Normal ExternalProvisioning"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), }, @@ -350,8 +350,8 @@ func TestProvisionSync(t *testing.T) { "11-18 - unknown internal provisioner", novolumes, novolumes, - claimWithClass("unknown-internal", newClaimArray("claim11-18", "uid11-18", "1Gi", "", v1.ClaimPending)), - claimWithClass("unknown-internal", newClaimArray("claim11-18", "uid11-18", "1Gi", "", v1.ClaimPending)), + 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), }, @@ -365,24 +365,24 @@ func TestAlphaProvisionSync(t *testing.T) { // Provision a volume with alpha annotation "14-1 - successful alpha provisioning", novolumes, - newVolumeArray("pvc-uid14-1", "1Gi", "uid14-1", "claim14-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned), - newClaimArray("claim14-1", "uid14-1", "1Gi", "", v1.ClaimPending, v1.AlphaStorageClassAnnotation), + newVolumeArray("pvc-uid14-1", "1Gi", "uid14-1", "claim14-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, annBoundByController, annDynamicallyProvisioned), + newClaimArray("claim14-1", "uid14-1", "1Gi", "", v1.ClaimPending, nil, v1.AlphaStorageClassAnnotation), // Binding will be completed in the next syncClaim - newClaimArray("claim14-1", "uid14-1", "1Gi", "", v1.ClaimPending, v1.AlphaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim14-1", "uid14-1", "1Gi", "", v1.ClaimPending, nil, v1.AlphaStorageClassAnnotation, annStorageProvisioner), noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{provisionAlphaSuccess}, testSyncClaim), }, { // Provision success - there is already a volume available, still // we provision a new one when requested. "14-2 - no alpha provisioning when there is a volume available", - newVolumeArray("volume14-2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), + newVolumeArray("volume14-2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), []*v1.PersistentVolume{ - newVolume("volume14-2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain), - newVolume("pvc-uid14-2", "1Gi", "uid14-2", "claim14-2", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned), + newVolume("volume14-2", "1Gi", "", "", v1.VolumePending, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolume("pvc-uid14-2", "1Gi", "uid14-2", "claim14-2", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty, annBoundByController, annDynamicallyProvisioned), }, - newClaimArray("claim14-2", "uid14-2", "1Gi", "", v1.ClaimPending, v1.AlphaStorageClassAnnotation), + newClaimArray("claim14-2", "uid14-2", "1Gi", "", v1.ClaimPending, nil, v1.AlphaStorageClassAnnotation), // Binding will be completed in the next syncClaim - newClaimArray("claim14-2", "uid14-2", "1Gi", "", v1.ClaimPending, v1.AlphaStorageClassAnnotation, annStorageProvisioner), + newClaimArray("claim14-2", "uid14-2", "1Gi", "", v1.ClaimPending, nil, v1.AlphaStorageClassAnnotation, annStorageProvisioner), noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{provisionAlphaSuccess}, testSyncClaim), }, } @@ -409,9 +409,9 @@ func TestProvisionMultiSync(t *testing.T) { // Provision a volume with binding "12-1 - successful provision", novolumes, - newVolumeArray("pvc-uid12-1", "1Gi", "uid12-1", "claim12-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, annBoundByController, annDynamicallyProvisioned, v1.BetaStorageClassAnnotation), - newClaimArray("claim12-1", "uid12-1", "1Gi", "", v1.ClaimPending, v1.BetaStorageClassAnnotation), - newClaimArray("claim12-1", "uid12-1", "1Gi", "pvc-uid12-1", v1.ClaimBound, v1.BetaStorageClassAnnotation, annBoundByController, annBindCompleted, annStorageProvisioner), + newVolumeArray("pvc-uid12-1", "1Gi", "uid12-1", "claim12-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, annBoundByController, annDynamicallyProvisioned), + newClaimArray("claim12-1", "uid12-1", "1Gi", "", v1.ClaimPending, &classGold), + newClaimArray("claim12-1", "uid12-1", "1Gi", "pvc-uid12-1", v1.ClaimBound, &classGold, annBoundByController, annBindCompleted, annStorageProvisioner), noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), }, } diff --git a/pkg/controller/volume/persistentvolume/pv_controller_test.go b/pkg/controller/volume/persistentvolume/pv_controller_test.go index 903b0b3610f..caa29acfbbf 100644 --- a/pkg/controller/volume/persistentvolume/pv_controller_test.go +++ b/pkg/controller/volume/persistentvolume/pv_controller_test.go @@ -45,14 +45,14 @@ func TestControllerSync(t *testing.T) { { // addClaim gets a new claim. Check it's bound to a volume. "5-2 - complete bind", - newVolumeArray("volume5-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain), - newVolumeArray("volume5-2", "1Gi", "uid5-2", "claim5-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), + newVolumeArray("volume5-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty), + newVolumeArray("volume5-2", "1Gi", "uid5-2", "claim5-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), noclaims, /* added in testAddClaim5_2 */ - newClaimArray("claim5-2", "uid5-2", "1Gi", "volume5-2", v1.ClaimBound, annBoundByController, annBindCompleted), + newClaimArray("claim5-2", "uid5-2", "1Gi", "volume5-2", v1.ClaimBound, nil, annBoundByController, annBindCompleted), noevents, noerrors, // Custom test function that generates an add event func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error { - claim := newClaim("claim5-2", "uid5-2", "1Gi", "", v1.ClaimPending) + claim := newClaim("claim5-2", "uid5-2", "1Gi", "", v1.ClaimPending, nil) reactor.addClaimEvent(claim) return nil }, @@ -60,9 +60,9 @@ func TestControllerSync(t *testing.T) { { // 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, annBoundByController), - newVolumeArray("volume5-3", "10Gi", "uid5-3", "claim5-3", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain, annBoundByController), - newClaimArray("claim5-3", "uid5-3", "1Gi", "volume5-3", v1.ClaimBound, annBoundByController, annBindCompleted), + newVolumeArray("volume5-3", "10Gi", "uid5-3", "claim5-3", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newVolumeArray("volume5-3", "10Gi", "uid5-3", "claim5-3", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController), + newClaimArray("claim5-3", "uid5-3", "1Gi", "volume5-3", v1.ClaimBound, nil, annBoundByController, annBindCompleted), noclaims, noevents, noerrors, // Custom test function that generates a delete event @@ -76,10 +76,10 @@ 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), + newVolumeArray("volume5-4", "1Gi", "uid5-4", "claim5-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty), novolumes, - newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", v1.ClaimBound, annBoundByController, annBindCompleted), - newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", v1.ClaimLost, annBoundByController, annBindCompleted), + newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", v1.ClaimBound, nil, annBoundByController, annBindCompleted), + newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", v1.ClaimLost, nil, annBoundByController, annBindCompleted), []string{"Warning ClaimLost"}, noerrors, // Custom test function that generates a delete event func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error { @@ -94,13 +94,13 @@ func TestControllerSync(t *testing.T) { // is expected - it should stay bound. "5-5 - add bound volume from 1.2", novolumes, - []*v1.PersistentVolume{addVolumeAnnotation(newVolume("volume5-5", "1Gi", "uid5-5", "claim5-5", v1.VolumeBound, v1.PersistentVolumeReclaimDelete), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)}, - newClaimArray("claim5-5", "uid5-5", "1Gi", "", v1.ClaimPending), - newClaimArray("claim5-5", "uid5-5", "1Gi", "volume5-5", v1.ClaimBound, annBindCompleted, annBoundByController), + []*v1.PersistentVolume{addVolumeAnnotation(newVolume("volume5-5", "1Gi", "uid5-5", "claim5-5", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)}, + newClaimArray("claim5-5", "uid5-5", "1Gi", "", v1.ClaimPending, nil), + newClaimArray("claim5-5", "uid5-5", "1Gi", "volume5-5", v1.ClaimBound, nil, annBindCompleted, annBoundByController), noevents, noerrors, // Custom test function that generates a add event func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error { - volume := newVolume("volume5-5", "1Gi", "uid5-5", "claim5-5", v1.VolumeBound, v1.PersistentVolumeReclaimDelete) + volume := newVolume("volume5-5", "1Gi", "uid5-5", "claim5-5", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty) volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue) reactor.addVolumeEvent(volume) return nil @@ -110,14 +110,14 @@ func TestControllerSync(t *testing.T) { // updateVolume with provisioned volume from Kubernetes 1.2. No // "action" is expected - it should stay bound. "5-6 - update bound volume from 1.2", - []*v1.PersistentVolume{addVolumeAnnotation(newVolume("volume5-6", "1Gi", "uid5-6", "claim5-6", v1.VolumeBound, v1.PersistentVolumeReclaimDelete), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)}, - []*v1.PersistentVolume{addVolumeAnnotation(newVolume("volume5-6", "1Gi", "uid5-6", "claim5-6", v1.VolumeBound, v1.PersistentVolumeReclaimDelete), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)}, - newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", v1.ClaimBound), - newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", v1.ClaimBound, annBindCompleted), + []*v1.PersistentVolume{addVolumeAnnotation(newVolume("volume5-6", "1Gi", "uid5-6", "claim5-6", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)}, + []*v1.PersistentVolume{addVolumeAnnotation(newVolume("volume5-6", "1Gi", "uid5-6", "claim5-6", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)}, + newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", v1.ClaimBound, nil), + newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", v1.ClaimBound, nil, annBindCompleted), noevents, noerrors, // Custom test function that generates a add event func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error { - volume := newVolume("volume5-6", "1Gi", "uid5-6", "claim5-6", v1.VolumeBound, v1.PersistentVolumeReclaimDelete) + volume := newVolume("volume5-6", "1Gi", "uid5-6", "claim5-6", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty) volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue) reactor.modifyVolumeEvent(volume) return nil @@ -129,12 +129,12 @@ func TestControllerSync(t *testing.T) { "5-7 - add unprovisioned volume from 1.2", novolumes, novolumes, - newClaimArray("claim5-7", "uid5-7", "1Gi", "", v1.ClaimPending), - newClaimArray("claim5-7", "uid5-7", "1Gi", "", v1.ClaimPending), + newClaimArray("claim5-7", "uid5-7", "1Gi", "", v1.ClaimPending, nil), + newClaimArray("claim5-7", "uid5-7", "1Gi", "", v1.ClaimPending, nil), noevents, noerrors, // Custom test function that generates a add event func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error { - volume := newVolume("volume5-7", "1Gi", "uid5-7", "claim5-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete) + volume := newVolume("volume5-7", "1Gi", "uid5-7", "claim5-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty) volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, "yes") reactor.addVolumeEvent(volume) return nil @@ -146,12 +146,12 @@ func TestControllerSync(t *testing.T) { "5-8 - update bound volume from 1.2", novolumes, novolumes, - newClaimArray("claim5-8", "uid5-8", "1Gi", "", v1.ClaimPending), - newClaimArray("claim5-8", "uid5-8", "1Gi", "", v1.ClaimPending), + newClaimArray("claim5-8", "uid5-8", "1Gi", "", v1.ClaimPending, nil), + newClaimArray("claim5-8", "uid5-8", "1Gi", "", v1.ClaimPending, nil), noevents, noerrors, // Custom test function that generates a add event func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error { - volume := newVolume("volume5-8", "1Gi", "uid5-8", "claim5-8", v1.VolumeBound, v1.PersistentVolumeReclaimDelete) + volume := newVolume("volume5-8", "1Gi", "uid5-8", "claim5-8", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty) volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, "yes") reactor.modifyVolumeEvent(volume) return nil @@ -224,7 +224,7 @@ func TestControllerSync(t *testing.T) { } func storeVersion(t *testing.T, prefix string, c cache.Store, version string, expectedReturn bool) { - pv := newVolume("pvName", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete) + pv := newVolume("pvName", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty) pv.ResourceVersion = version ret, err := storeObjectUpdate(c, pv, "volume") if err != nil { @@ -283,7 +283,7 @@ func TestControllerCacheParsingError(t *testing.T) { // There must be something in the cache to compare with storeVersion(t, "Step1", c, "1", true) - pv := newVolume("pvName", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete) + pv := newVolume("pvName", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classEmpty) pv.ResourceVersion = "xxx" _, err := storeObjectUpdate(c, pv, "volume") if err == nil { diff --git a/pkg/controller/volume/persistentvolume/recycle_test.go b/pkg/controller/volume/persistentvolume/recycle_test.go index 86681c52587..8566a898c0a 100644 --- a/pkg/controller/volume/persistentvolume/recycle_test.go +++ b/pkg/controller/volume/persistentvolume/recycle_test.go @@ -33,8 +33,8 @@ func TestRecycleSync(t *testing.T) { { // recycle volume bound by controller "6-1 - successful recycle", - newVolumeArray("volume6-1", "1Gi", "uid6-1", "claim6-1", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, annBoundByController), - newVolumeArray("volume6-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle), + newVolumeArray("volume6-1", "1Gi", "uid6-1", "claim6-1", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, annBoundByController), + newVolumeArray("volume6-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), noclaims, noclaims, noevents, noerrors, @@ -45,8 +45,8 @@ func TestRecycleSync(t *testing.T) { { // recycle volume bound by user "6-2 - successful recycle with prebound volume", - newVolumeArray("volume6-2", "1Gi", "uid6-2", "claim6-2", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle), - newVolumeArray("volume6-2", "1Gi", "", "claim6-2", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle), + 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, @@ -57,8 +57,8 @@ func TestRecycleSync(t *testing.T) { { // recycle failure - plugin not found "6-3 - plugin not found", - newVolumeArray("volume6-3", "1Gi", "uid6-3", "claim6-3", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle), - withMessage("No recycler plugin found for the volume!", newVolumeArray("volume6-3", "1Gi", "uid6-3", "claim6-3", v1.VolumeFailed, v1.PersistentVolumeReclaimRecycle)), + 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, @@ -66,8 +66,8 @@ func TestRecycleSync(t *testing.T) { { // recycle failure - Recycle returns error "6-4 - newRecycler returns error", - newVolumeArray("volume6-4", "1Gi", "uid6-4", "claim6-4", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle), - withMessage("Recycle failed: Mock plugin error: no recycleCalls configured", newVolumeArray("volume6-4", "1Gi", "uid6-4", "claim6-4", v1.VolumeFailed, v1.PersistentVolumeReclaimRecycle)), + 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, @@ -76,8 +76,8 @@ func TestRecycleSync(t *testing.T) { { // recycle failure - recycle returns error "6-5 - recycle returns error", - newVolumeArray("volume6-5", "1Gi", "uid6-5", "claim6-5", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle), - withMessage("Recycle failed: Mock recycle error", newVolumeArray("volume6-5", "1Gi", "uid6-5", "claim6-5", v1.VolumeFailed, v1.PersistentVolumeReclaimRecycle)), + 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, @@ -86,7 +86,7 @@ func TestRecycleSync(t *testing.T) { { // 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), + newVolumeArray("volume6-6", "1Gi", "uid6-6", "claim6-6", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), novolumes, noclaims, noclaims, @@ -103,8 +103,8 @@ func TestRecycleSync(t *testing.T) { // 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, annBoundByController), - newVolumeArray("volume6-7", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle), + newVolumeArray("volume6-7", "1Gi", "uid6-7", "claim6-7", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, annBoundByController), + newVolumeArray("volume6-7", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), noclaims, noclaims, noevents, noerrors, @@ -124,8 +124,8 @@ func TestRecycleSync(t *testing.T) { // "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), - newVolumeArray("volume6-8", "1Gi", "", "claim6-8", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle), + newVolumeArray("volume6-8", "1Gi", "uid6-8", "claim6-8", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), + newVolumeArray("volume6-8", "1Gi", "", "claim6-8", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), noclaims, noclaims, noevents, noerrors, @@ -142,10 +142,10 @@ 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), - newVolumeArray("volume6-9", "1Gi", "", "claim6-9", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle), - newClaimArray("claim6-9", "uid6-9-x", "10Gi", "", v1.ClaimPending), - newClaimArray("claim6-9", "uid6-9-x", "10Gi", "", v1.ClaimPending), + 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, // Inject recycler into the controller and call syncVolume. The // recycler simulates one recycle() call that succeeds. @@ -154,8 +154,8 @@ func TestRecycleSync(t *testing.T) { { // volume has unknown reclaim policy - failure expected "6-10 - unknown reclaim policy", - newVolumeArray("volume6-10", "1Gi", "uid6-10", "claim6-10", v1.VolumeBound, "Unknown"), - withMessage("Volume has unrecognized PersistentVolumeReclaimPolicy", newVolumeArray("volume6-10", "1Gi", "uid6-10", "claim6-10", v1.VolumeFailed, "Unknown")), + 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, @@ -184,8 +184,8 @@ func TestRecycleMultiSync(t *testing.T) { // recycle failure - recycle returns error. The controller should // try again. "7-1 - recycle returns error", - newVolumeArray("volume7-1", "1Gi", "uid7-1", "claim7-1", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle), - newVolumeArray("volume7-1", "1Gi", "", "claim7-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle), + newVolumeArray("volume7-1", "1Gi", "uid7-1", "claim7-1", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty), + newVolumeArray("volume7-1", "1Gi", "", "claim7-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty), noclaims, noclaims, []string{"Warning VolumeFailedRecycle"}, noerrors,