Commit 52adaa16 authored by Jan Safranek's avatar Jan Safranek

PV controller: use attributes instead of beta annotations in unit tests

parent 0097adc1
...@@ -620,7 +620,7 @@ func newTestController(kubeClient clientset.Interface, informerFactory informers ...@@ -620,7 +620,7 @@ func newTestController(kubeClient clientset.Interface, informerFactory informers
} }
// newVolume returns a new volume with given attributes // 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{ volume := v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
...@@ -635,6 +635,7 @@ func newVolume(name, capacity, boundToClaimUID, boundToClaimName string, phase v ...@@ -635,6 +635,7 @@ func newVolume(name, capacity, boundToClaimUID, boundToClaimName string, phase v
}, },
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce, v1.ReadOnlyMany}, AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce, v1.ReadOnlyMany},
PersistentVolumeReclaimPolicy: reclaimPolicy, PersistentVolumeReclaimPolicy: reclaimPolicy,
StorageClassName: class,
}, },
Status: v1.PersistentVolumeStatus{ Status: v1.PersistentVolumeStatus{
Phase: phase, Phase: phase,
...@@ -657,8 +658,6 @@ func newVolume(name, capacity, boundToClaimUID, boundToClaimName string, phase v ...@@ -657,8 +658,6 @@ func newVolume(name, capacity, boundToClaimUID, boundToClaimName string, phase v
switch a { switch a {
case annDynamicallyProvisioned: case annDynamicallyProvisioned:
volume.Annotations[a] = mockPluginName volume.Annotations[a] = mockPluginName
case v1.BetaStorageClassAnnotation:
volume.Annotations[a] = "gold"
default: default:
volume.Annotations[a] = "yes" volume.Annotations[a] = "yes"
} }
...@@ -706,27 +705,16 @@ func withMessage(message string, volumes []*v1.PersistentVolume) []*v1.Persisten ...@@ -706,27 +705,16 @@ func withMessage(message string, volumes []*v1.PersistentVolume) []*v1.Persisten
return volumes 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 // newVolumeArray returns array with a single volume that would be returned by
// newVolume() with the same parameters. // 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{ 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 // 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{ claim := v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
...@@ -741,7 +729,8 @@ func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.Persisten ...@@ -741,7 +729,8 @@ func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.Persisten
v1.ResourceName(v1.ResourceStorage): resource.MustParse(capacity), v1.ResourceName(v1.ResourceStorage): resource.MustParse(capacity),
}, },
}, },
VolumeName: boundToVolume, VolumeName: boundToVolume,
StorageClassName: class,
}, },
Status: v1.PersistentVolumeClaimStatus{ Status: v1.PersistentVolumeClaimStatus{
Phase: phase, Phase: phase,
...@@ -754,8 +743,6 @@ func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.Persisten ...@@ -754,8 +743,6 @@ func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.Persisten
claim.Annotations = make(map[string]string) claim.Annotations = make(map[string]string)
for _, a := range annotations { for _, a := range annotations {
switch a { switch a {
case v1.BetaStorageClassAnnotation:
claim.Annotations[a] = "gold"
case annStorageProvisioner: case annStorageProvisioner:
claim.Annotations[a] = mockPluginName claim.Annotations[a] = mockPluginName
default: default:
...@@ -777,23 +764,12 @@ func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.Persisten ...@@ -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 // newClaimArray returns array with a single claim that would be returned by
// newClaim() with the same parameters. // 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{ 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. // claimWithAnnotation saves given annotation into given claims.
// Meant to be used to compose claims specified inline in a test. // Meant to be used to compose claims specified inline in a test.
func claimWithAnnotation(name, value string, claims []*v1.PersistentVolumeClaim) []*v1.PersistentVolumeClaim { func claimWithAnnotation(name, value string, claims []*v1.PersistentVolumeClaim) []*v1.PersistentVolumeClaim {
...@@ -827,6 +803,15 @@ type operationType string ...@@ -827,6 +803,15 @@ type operationType string
const operationDelete = "Delete" const operationDelete = "Delete"
const operationRecycle = "Recycle" 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: // wrapTestWithPluginCalls returns a testCall that:
// - configures controller with a volume plugin that implements recycler, // - configures controller with a volume plugin that implements recycler,
// deleter and provisioner. The plugin retunrs provided errors when a volume // deleter and provisioner. The plugin retunrs provided errors when a volume
......
...@@ -111,24 +111,20 @@ func TestMatchVolume(t *testing.T) { ...@@ -111,24 +111,20 @@ func TestMatchVolume(t *testing.T) {
"successful-match-with-class": { "successful-match-with-class": {
expectedMatch: "gce-pd-silver1", expectedMatch: "gce-pd-silver1",
claim: makePVC("1G", func(pvc *v1.PersistentVolumeClaim) { claim: makePVC("1G", func(pvc *v1.PersistentVolumeClaim) {
pvc.ObjectMeta.Annotations = map[string]string{
v1.BetaStorageClassAnnotation: "silver",
}
pvc.Spec.Selector = &metav1.LabelSelector{ pvc.Spec.Selector = &metav1.LabelSelector{
MatchLabels: map[string]string{ MatchLabels: map[string]string{
"should-exist": "true", "should-exist": "true",
}, },
} }
pvc.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce} pvc.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce}
pvc.Spec.StorageClassName = &classSilver
}), }),
}, },
"successful-match-with-class-and-labels": { "successful-match-with-class-and-labels": {
expectedMatch: "gce-pd-silver2", expectedMatch: "gce-pd-silver2",
claim: makePVC("1G", func(pvc *v1.PersistentVolumeClaim) { 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.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce}
pvc.Spec.StorageClassName = &classSilver
}), }),
}, },
} }
...@@ -541,9 +537,6 @@ func createTestVolumes() []*v1.PersistentVolume { ...@@ -541,9 +537,6 @@ func createTestVolumes() []*v1.PersistentVolume {
Labels: map[string]string{ Labels: map[string]string{
"should-exist": "true", "should-exist": "true",
}, },
Annotations: map[string]string{
v1.BetaStorageClassAnnotation: "silver",
},
}, },
Spec: v1.PersistentVolumeSpec{ Spec: v1.PersistentVolumeSpec{
Capacity: v1.ResourceList{ Capacity: v1.ResourceList{
...@@ -555,15 +548,13 @@ func createTestVolumes() []*v1.PersistentVolume { ...@@ -555,15 +548,13 @@ func createTestVolumes() []*v1.PersistentVolume {
AccessModes: []v1.PersistentVolumeAccessMode{ AccessModes: []v1.PersistentVolumeAccessMode{
v1.ReadWriteOnce, v1.ReadWriteOnce,
}, },
StorageClassName: classSilver,
}, },
}, },
{ {
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
UID: "gce-pd-silver2", UID: "gce-pd-silver2",
Name: "gce0024", Name: "gce0024",
Annotations: map[string]string{
v1.BetaStorageClassAnnotation: "silver",
},
}, },
Spec: v1.PersistentVolumeSpec{ Spec: v1.PersistentVolumeSpec{
Capacity: v1.ResourceList{ Capacity: v1.ResourceList{
...@@ -575,15 +566,13 @@ func createTestVolumes() []*v1.PersistentVolume { ...@@ -575,15 +566,13 @@ func createTestVolumes() []*v1.PersistentVolume {
AccessModes: []v1.PersistentVolumeAccessMode{ AccessModes: []v1.PersistentVolumeAccessMode{
v1.ReadWriteOnce, v1.ReadWriteOnce,
}, },
StorageClassName: classSilver,
}, },
}, },
{ {
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
UID: "gce-pd-gold", UID: "gce-pd-gold",
Name: "gce0025", Name: "gce0025",
Annotations: map[string]string{
v1.BetaStorageClassAnnotation: "gold",
},
}, },
Spec: v1.PersistentVolumeSpec{ Spec: v1.PersistentVolumeSpec{
Capacity: v1.ResourceList{ Capacity: v1.ResourceList{
...@@ -595,6 +584,7 @@ func createTestVolumes() []*v1.PersistentVolume { ...@@ -595,6 +584,7 @@ func createTestVolumes() []*v1.PersistentVolume {
AccessModes: []v1.PersistentVolumeAccessMode{ AccessModes: []v1.PersistentVolumeAccessMode{
v1.ReadWriteOnce, v1.ReadWriteOnce,
}, },
StorageClassName: classGold,
}, },
}, },
} }
......
...@@ -45,14 +45,14 @@ func TestControllerSync(t *testing.T) { ...@@ -45,14 +45,14 @@ func TestControllerSync(t *testing.T) {
{ {
// addClaim gets a new claim. Check it's bound to a volume. // addClaim gets a new claim. Check it's bound to a volume.
"5-2 - complete bind", "5-2 - complete bind",
newVolumeArray("volume5-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain), newVolumeArray("volume5-2", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRetain, classEmpty),
newVolumeArray("volume5-2", "1Gi", "uid5-2", "claim5-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, annBoundByController), newVolumeArray("volume5-2", "1Gi", "uid5-2", "claim5-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController),
noclaims, /* added in testAddClaim5_2 */ 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, noevents, noerrors,
// Custom test function that generates an add event // Custom test function that generates an add event
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error { 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) reactor.addClaimEvent(claim)
return nil return nil
}, },
...@@ -60,9 +60,9 @@ func TestControllerSync(t *testing.T) { ...@@ -60,9 +60,9 @@ func TestControllerSync(t *testing.T) {
{ {
// deleteClaim with a bound claim makes bound volume released. // deleteClaim with a bound claim makes bound volume released.
"5-3 - delete claim", "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.VolumeBound, v1.PersistentVolumeReclaimRetain, classEmpty, annBoundByController),
newVolumeArray("volume5-3", "10Gi", "uid5-3", "claim5-3", v1.VolumeReleased, v1.PersistentVolumeReclaimRetain, 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, annBoundByController, annBindCompleted), newClaimArray("claim5-3", "uid5-3", "1Gi", "volume5-3", v1.ClaimBound, nil, annBoundByController, annBindCompleted),
noclaims, noclaims,
noevents, noerrors, noevents, noerrors,
// Custom test function that generates a delete event // Custom test function that generates a delete event
...@@ -76,10 +76,10 @@ func TestControllerSync(t *testing.T) { ...@@ -76,10 +76,10 @@ func TestControllerSync(t *testing.T) {
{ {
// deleteVolume with a bound volume. Check the claim is Lost. // deleteVolume with a bound volume. Check the claim is Lost.
"5-4 - delete volume", "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, novolumes,
newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", v1.ClaimBound, 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, annBoundByController, annBindCompleted), newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", v1.ClaimLost, nil, annBoundByController, annBindCompleted),
[]string{"Warning ClaimLost"}, noerrors, []string{"Warning ClaimLost"}, noerrors,
// Custom test function that generates a delete event // Custom test function that generates a delete event
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error { func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error {
...@@ -94,13 +94,13 @@ func TestControllerSync(t *testing.T) { ...@@ -94,13 +94,13 @@ func TestControllerSync(t *testing.T) {
// is expected - it should stay bound. // is expected - it should stay bound.
"5-5 - add bound volume from 1.2", "5-5 - add bound volume from 1.2",
novolumes, novolumes,
[]*v1.PersistentVolume{addVolumeAnnotation(newVolume("volume5-5", "1Gi", "uid5-5", "claim5-5", v1.VolumeBound, v1.PersistentVolumeReclaimDelete), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)}, []*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), newClaimArray("claim5-5", "uid5-5", "1Gi", "", v1.ClaimPending, nil),
newClaimArray("claim5-5", "uid5-5", "1Gi", "volume5-5", v1.ClaimBound, annBindCompleted, annBoundByController), newClaimArray("claim5-5", "uid5-5", "1Gi", "volume5-5", v1.ClaimBound, nil, annBindCompleted, annBoundByController),
noevents, noerrors, noevents, noerrors,
// Custom test function that generates a add event // Custom test function that generates a add event
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error { 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) volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)
reactor.addVolumeEvent(volume) reactor.addVolumeEvent(volume)
return nil return nil
...@@ -110,14 +110,14 @@ func TestControllerSync(t *testing.T) { ...@@ -110,14 +110,14 @@ func TestControllerSync(t *testing.T) {
// updateVolume with provisioned volume from Kubernetes 1.2. No // updateVolume with provisioned volume from Kubernetes 1.2. No
// "action" is expected - it should stay bound. // "action" is expected - it should stay bound.
"5-6 - update bound volume from 1.2", "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, classEmpty), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)},
[]*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, classEmpty), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)},
newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", v1.ClaimBound), newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", v1.ClaimBound, nil),
newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", v1.ClaimBound, annBindCompleted), newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", v1.ClaimBound, nil, annBindCompleted),
noevents, noerrors, noevents, noerrors,
// Custom test function that generates a add event // Custom test function that generates a add event
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error { 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) volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)
reactor.modifyVolumeEvent(volume) reactor.modifyVolumeEvent(volume)
return nil return nil
...@@ -129,12 +129,12 @@ func TestControllerSync(t *testing.T) { ...@@ -129,12 +129,12 @@ func TestControllerSync(t *testing.T) {
"5-7 - add unprovisioned volume from 1.2", "5-7 - add unprovisioned volume from 1.2",
novolumes, novolumes,
novolumes, novolumes,
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), newClaimArray("claim5-7", "uid5-7", "1Gi", "", v1.ClaimPending, nil),
noevents, noerrors, noevents, noerrors,
// Custom test function that generates a add event // Custom test function that generates a add event
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error { 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") volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, "yes")
reactor.addVolumeEvent(volume) reactor.addVolumeEvent(volume)
return nil return nil
...@@ -146,12 +146,12 @@ func TestControllerSync(t *testing.T) { ...@@ -146,12 +146,12 @@ func TestControllerSync(t *testing.T) {
"5-8 - update bound volume from 1.2", "5-8 - update bound volume from 1.2",
novolumes, novolumes,
novolumes, novolumes,
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), newClaimArray("claim5-8", "uid5-8", "1Gi", "", v1.ClaimPending, nil),
noevents, noerrors, noevents, noerrors,
// Custom test function that generates a add event // Custom test function that generates a add event
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error { 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") volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, "yes")
reactor.modifyVolumeEvent(volume) reactor.modifyVolumeEvent(volume)
return nil return nil
...@@ -224,7 +224,7 @@ func TestControllerSync(t *testing.T) { ...@@ -224,7 +224,7 @@ func TestControllerSync(t *testing.T) {
} }
func storeVersion(t *testing.T, prefix string, c cache.Store, version string, expectedReturn bool) { 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 pv.ResourceVersion = version
ret, err := storeObjectUpdate(c, pv, "volume") ret, err := storeObjectUpdate(c, pv, "volume")
if err != nil { if err != nil {
...@@ -283,7 +283,7 @@ func TestControllerCacheParsingError(t *testing.T) { ...@@ -283,7 +283,7 @@ func TestControllerCacheParsingError(t *testing.T) {
// There must be something in the cache to compare with // There must be something in the cache to compare with
storeVersion(t, "Step1", c, "1", true) 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" pv.ResourceVersion = "xxx"
_, err := storeObjectUpdate(c, pv, "volume") _, err := storeObjectUpdate(c, pv, "volume")
if err == nil { if err == nil {
......
...@@ -33,8 +33,8 @@ func TestRecycleSync(t *testing.T) { ...@@ -33,8 +33,8 @@ func TestRecycleSync(t *testing.T) {
{ {
// recycle volume bound by controller // recycle volume bound by controller
"6-1 - successful recycle", "6-1 - successful recycle",
newVolumeArray("volume6-1", "1Gi", "uid6-1", "claim6-1", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, annBoundByController), newVolumeArray("volume6-1", "1Gi", "uid6-1", "claim6-1", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, annBoundByController),
newVolumeArray("volume6-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle), newVolumeArray("volume6-1", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty),
noclaims, noclaims,
noclaims, noclaims,
noevents, noerrors, noevents, noerrors,
...@@ -45,8 +45,8 @@ func TestRecycleSync(t *testing.T) { ...@@ -45,8 +45,8 @@ func TestRecycleSync(t *testing.T) {
{ {
// recycle volume bound by user // recycle volume bound by user
"6-2 - successful recycle with prebound volume", "6-2 - successful recycle with prebound volume",
newVolumeArray("volume6-2", "1Gi", "uid6-2", "claim6-2", v1.VolumeBound, 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), newVolumeArray("volume6-2", "1Gi", "", "claim6-2", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty),
noclaims, noclaims,
noclaims, noclaims,
noevents, noerrors, noevents, noerrors,
...@@ -57,8 +57,8 @@ func TestRecycleSync(t *testing.T) { ...@@ -57,8 +57,8 @@ func TestRecycleSync(t *testing.T) {
{ {
// recycle failure - plugin not found // recycle failure - plugin not found
"6-3 - plugin not found", "6-3 - plugin not found",
newVolumeArray("volume6-3", "1Gi", "uid6-3", "claim6-3", v1.VolumeBound, 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)), withMessage("No recycler plugin found for the volume!", newVolumeArray("volume6-3", "1Gi", "uid6-3", "claim6-3", v1.VolumeFailed, v1.PersistentVolumeReclaimRecycle, classEmpty)),
noclaims, noclaims,
noclaims, noclaims,
[]string{"Warning VolumeFailedRecycle"}, noerrors, testSyncVolume, []string{"Warning VolumeFailedRecycle"}, noerrors, testSyncVolume,
...@@ -66,8 +66,8 @@ func TestRecycleSync(t *testing.T) { ...@@ -66,8 +66,8 @@ func TestRecycleSync(t *testing.T) {
{ {
// recycle failure - Recycle returns error // recycle failure - Recycle returns error
"6-4 - newRecycler returns error", "6-4 - newRecycler returns error",
newVolumeArray("volume6-4", "1Gi", "uid6-4", "claim6-4", v1.VolumeBound, 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)), withMessage("Recycle failed: Mock plugin error: no recycleCalls configured", newVolumeArray("volume6-4", "1Gi", "uid6-4", "claim6-4", v1.VolumeFailed, v1.PersistentVolumeReclaimRecycle, classEmpty)),
noclaims, noclaims,
noclaims, noclaims,
[]string{"Warning VolumeFailedRecycle"}, noerrors, []string{"Warning VolumeFailedRecycle"}, noerrors,
...@@ -76,8 +76,8 @@ func TestRecycleSync(t *testing.T) { ...@@ -76,8 +76,8 @@ func TestRecycleSync(t *testing.T) {
{ {
// recycle failure - recycle returns error // recycle failure - recycle returns error
"6-5 - recycle returns error", "6-5 - recycle returns error",
newVolumeArray("volume6-5", "1Gi", "uid6-5", "claim6-5", v1.VolumeBound, 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)), withMessage("Recycle failed: Mock recycle error", newVolumeArray("volume6-5", "1Gi", "uid6-5", "claim6-5", v1.VolumeFailed, v1.PersistentVolumeReclaimRecycle, classEmpty)),
noclaims, noclaims,
noclaims, noclaims,
[]string{"Warning VolumeFailedRecycle"}, noerrors, []string{"Warning VolumeFailedRecycle"}, noerrors,
...@@ -86,7 +86,7 @@ func TestRecycleSync(t *testing.T) { ...@@ -86,7 +86,7 @@ func TestRecycleSync(t *testing.T) {
{ {
// recycle success(?) - volume is deleted before doRecycle() starts // recycle success(?) - volume is deleted before doRecycle() starts
"6-6 - volume is deleted before recycling", "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, novolumes,
noclaims, noclaims,
noclaims, noclaims,
...@@ -103,8 +103,8 @@ func TestRecycleSync(t *testing.T) { ...@@ -103,8 +103,8 @@ func TestRecycleSync(t *testing.T) {
// at the time new doRecycle() starts. This simulates "volume no // at the time new doRecycle() starts. This simulates "volume no
// longer needs recycling, skipping". // longer needs recycling, skipping".
"6-7 - volume is deleted before recycling", "6-7 - volume is deleted before recycling",
newVolumeArray("volume6-7", "1Gi", "uid6-7", "claim6-7", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, annBoundByController), newVolumeArray("volume6-7", "1Gi", "uid6-7", "claim6-7", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty, annBoundByController),
newVolumeArray("volume6-7", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle), newVolumeArray("volume6-7", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty),
noclaims, noclaims,
noclaims, noclaims,
noevents, noerrors, noevents, noerrors,
...@@ -124,8 +124,8 @@ func TestRecycleSync(t *testing.T) { ...@@ -124,8 +124,8 @@ func TestRecycleSync(t *testing.T) {
// "volume no longer needs recycling, skipping" with volume bound by // "volume no longer needs recycling, skipping" with volume bound by
// user. // user.
"6-8 - prebound volume is deleted before recycling", "6-8 - prebound volume is deleted before recycling",
newVolumeArray("volume6-8", "1Gi", "uid6-8", "claim6-8", v1.VolumeBound, 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), newVolumeArray("volume6-8", "1Gi", "", "claim6-8", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty),
noclaims, noclaims,
noclaims, noclaims,
noevents, noerrors, noevents, noerrors,
...@@ -142,10 +142,10 @@ func TestRecycleSync(t *testing.T) { ...@@ -142,10 +142,10 @@ func TestRecycleSync(t *testing.T) {
// recycle success - volume bound by user is recycled, while a new // recycle success - volume bound by user is recycled, while a new
// claim is created with another UID. // claim is created with another UID.
"6-9 - prebound volume is recycled while the claim exists", "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", "uid6-9", "claim6-9", v1.VolumeBound, v1.PersistentVolumeReclaimRecycle, classEmpty),
newVolumeArray("volume6-9", "1Gi", "", "claim6-9", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle), newVolumeArray("volume6-9", "1Gi", "", "claim6-9", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty),
newClaimArray("claim6-9", "uid6-9-x", "10Gi", "", v1.ClaimPending), newClaimArray("claim6-9", "uid6-9-x", "10Gi", "", v1.ClaimPending, nil),
newClaimArray("claim6-9", "uid6-9-x", "10Gi", "", v1.ClaimPending), newClaimArray("claim6-9", "uid6-9-x", "10Gi", "", v1.ClaimPending, nil),
noevents, noerrors, noevents, noerrors,
// Inject recycler into the controller and call syncVolume. The // Inject recycler into the controller and call syncVolume. The
// recycler simulates one recycle() call that succeeds. // recycler simulates one recycle() call that succeeds.
...@@ -154,8 +154,8 @@ func TestRecycleSync(t *testing.T) { ...@@ -154,8 +154,8 @@ func TestRecycleSync(t *testing.T) {
{ {
// volume has unknown reclaim policy - failure expected // volume has unknown reclaim policy - failure expected
"6-10 - unknown reclaim policy", "6-10 - unknown reclaim policy",
newVolumeArray("volume6-10", "1Gi", "uid6-10", "claim6-10", v1.VolumeBound, "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")), withMessage("Volume has unrecognized PersistentVolumeReclaimPolicy", newVolumeArray("volume6-10", "1Gi", "uid6-10", "claim6-10", v1.VolumeFailed, "Unknown", classEmpty)),
noclaims, noclaims,
noclaims, noclaims,
[]string{"Warning VolumeUnknownReclaimPolicy"}, noerrors, testSyncVolume, []string{"Warning VolumeUnknownReclaimPolicy"}, noerrors, testSyncVolume,
...@@ -184,8 +184,8 @@ func TestRecycleMultiSync(t *testing.T) { ...@@ -184,8 +184,8 @@ func TestRecycleMultiSync(t *testing.T) {
// recycle failure - recycle returns error. The controller should // recycle failure - recycle returns error. The controller should
// try again. // try again.
"7-1 - recycle returns error", "7-1 - recycle returns error",
newVolumeArray("volume7-1", "1Gi", "uid7-1", "claim7-1", v1.VolumeBound, 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), newVolumeArray("volume7-1", "1Gi", "", "claim7-1", v1.VolumeAvailable, v1.PersistentVolumeReclaimRecycle, classEmpty),
noclaims, noclaims,
noclaims, noclaims,
[]string{"Warning VolumeFailedRecycle"}, noerrors, []string{"Warning VolumeFailedRecycle"}, noerrors,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment