Refactor delete test to use withSnapshotFinalizers function
Signed-off-by: Grant Griffiths <grant@portworx.com>
This commit is contained in:
@@ -164,11 +164,13 @@ type reactorError struct {
|
|||||||
error error
|
error error
|
||||||
}
|
}
|
||||||
|
|
||||||
func withSnapshotFinalizer(snapshot *crdv1.VolumeSnapshot) *crdv1.VolumeSnapshot {
|
func withSnapshotFinalizers(snapshots []*crdv1.VolumeSnapshot, finalizers ...string) []*crdv1.VolumeSnapshot {
|
||||||
snapshot.ObjectMeta.Finalizers = append(snapshot.ObjectMeta.Finalizers, utils.VolumeSnapshotContentFinalizer)
|
for i := range snapshots {
|
||||||
snapshot.ObjectMeta.Finalizers = append(snapshot.ObjectMeta.Finalizers, utils.VolumeSnapshotAsSourceFinalizer)
|
for _, f := range finalizers {
|
||||||
snapshot.ObjectMeta.Finalizers = append(snapshot.ObjectMeta.Finalizers, utils.VolumeSnapshotBoundFinalizer)
|
snapshots[i].ObjectMeta.Finalizers = append(snapshots[i].ObjectMeta.Finalizers, f)
|
||||||
return snapshot
|
}
|
||||||
|
}
|
||||||
|
return snapshots
|
||||||
}
|
}
|
||||||
|
|
||||||
func withContentFinalizer(content *crdv1.VolumeSnapshotContent) *crdv1.VolumeSnapshotContent {
|
func withContentFinalizer(content *crdv1.VolumeSnapshotContent) *crdv1.VolumeSnapshotContent {
|
||||||
@@ -863,7 +865,7 @@ func newContentWithUnmatchDriverArray(contentName, boundToSnapshotUID, boundToSn
|
|||||||
func newSnapshot(
|
func newSnapshot(
|
||||||
snapshotName, snapshotUID, pvcName, targetContentName, snapshotClassName, boundContentName string,
|
snapshotName, snapshotUID, pvcName, targetContentName, snapshotClassName, boundContentName string,
|
||||||
readyToUse *bool, creationTime *metav1.Time, restoreSize *resource.Quantity,
|
readyToUse *bool, creationTime *metav1.Time, restoreSize *resource.Quantity,
|
||||||
err *crdv1.VolumeSnapshotError, nilStatus bool, withFinalizer bool, deletionTimestamp *metav1.Time) *crdv1.VolumeSnapshot {
|
err *crdv1.VolumeSnapshotError, nilStatus bool, withAllFinalizers bool, deletionTimestamp *metav1.Time) *crdv1.VolumeSnapshot {
|
||||||
snapshot := crdv1.VolumeSnapshot{
|
snapshot := crdv1.VolumeSnapshot{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: snapshotName,
|
Name: snapshotName,
|
||||||
@@ -904,8 +906,8 @@ func newSnapshot(
|
|||||||
VolumeSnapshotContentName: &targetContentName,
|
VolumeSnapshotContentName: &targetContentName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if withFinalizer {
|
if withAllFinalizers {
|
||||||
return withSnapshotFinalizer(&snapshot)
|
return withSnapshotFinalizers([]*crdv1.VolumeSnapshot{&snapshot}, utils.VolumeSnapshotContentFinalizer, utils.VolumeSnapshotAsSourceFinalizer, utils.VolumeSnapshotBoundFinalizer)[0]
|
||||||
}
|
}
|
||||||
return &snapshot
|
return &snapshot
|
||||||
}
|
}
|
||||||
@@ -913,9 +915,9 @@ func newSnapshot(
|
|||||||
func newSnapshotArray(
|
func newSnapshotArray(
|
||||||
snapshotName, snapshotUID, pvcName, targetContentName, snapshotClassName, boundContentName string,
|
snapshotName, snapshotUID, pvcName, targetContentName, snapshotClassName, boundContentName string,
|
||||||
readyToUse *bool, creationTime *metav1.Time, restoreSize *resource.Quantity,
|
readyToUse *bool, creationTime *metav1.Time, restoreSize *resource.Quantity,
|
||||||
err *crdv1.VolumeSnapshotError, nilStatus bool, withFinalizer bool, deletionTimestamp *metav1.Time) []*crdv1.VolumeSnapshot {
|
err *crdv1.VolumeSnapshotError, nilStatus bool, withAllFinalizers bool, deletionTimestamp *metav1.Time) []*crdv1.VolumeSnapshot {
|
||||||
return []*crdv1.VolumeSnapshot{
|
return []*crdv1.VolumeSnapshot{
|
||||||
newSnapshot(snapshotName, snapshotUID, pvcName, targetContentName, snapshotClassName, boundContentName, readyToUse, creationTime, restoreSize, err, nilStatus, withFinalizer, deletionTimestamp),
|
newSnapshot(snapshotName, snapshotUID, pvcName, targetContentName, snapshotClassName, boundContentName, readyToUse, creationTime, restoreSize, err, nilStatus, withAllFinalizers, deletionTimestamp),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,7 +24,6 @@ import (
|
|||||||
"github.com/kubernetes-csi/external-snapshotter/v2/pkg/utils"
|
"github.com/kubernetes-csi/external-snapshotter/v2/pkg/utils"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var class1Parameters = map[string]string{
|
var class1Parameters = map[string]string{
|
||||||
@@ -304,36 +303,9 @@ func TestDeleteSync(t *testing.T) {
|
|||||||
initialContents: newContentArray("content3-1", "", "snap3-1", "sid3-1", validSecretClass, "", "", deletePolicy, nil, nil, true),
|
initialContents: newContentArray("content3-1", "", "snap3-1", "sid3-1", validSecretClass, "", "", deletePolicy, nil, nil, true),
|
||||||
expectedContents: nocontents,
|
expectedContents: nocontents,
|
||||||
initialSnapshots: newSnapshotArray("snap3-1", "snapuid3-1", "claim3-1", "", validSecretClass, "content3-1", &False, nil, nil, nil, false, true, &timeNowMetav1),
|
initialSnapshots: newSnapshotArray("snap3-1", "snapuid3-1", "claim3-1", "", validSecretClass, "content3-1", &False, nil, nil, nil, false, true, &timeNowMetav1),
|
||||||
expectedSnapshots: []*crdv1.VolumeSnapshot{
|
expectedSnapshots: withSnapshotFinalizers(newSnapshotArray("snap3-1", "snapuid3-1", "claim3-1", "", validSecretClass, "content3-1", &False, nil, nil, nil, false, false, &timeNowMetav1),
|
||||||
&crdv1.VolumeSnapshot{
|
utils.VolumeSnapshotContentFinalizer, utils.VolumeSnapshotBoundFinalizer,
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
),
|
||||||
Name: "snap3-1",
|
|
||||||
Namespace: testNamespace,
|
|
||||||
UID: types.UID("snapuid3-1"),
|
|
||||||
ResourceVersion: "1",
|
|
||||||
Finalizers: []string{
|
|
||||||
"snapshot.storage.kubernetes.io/volumesnapshotcontent-bound-protection",
|
|
||||||
"snapshot.storage.kubernetes.io/volumesnapshot-bound-protection",
|
|
||||||
},
|
|
||||||
SelfLink: "/apis/snapshot.storage.k8s.io/v1beta1/namespaces/" + testNamespace + "/volumesnapshots/" + "snap3-1",
|
|
||||||
DeletionTimestamp: &timeNowMetav1,
|
|
||||||
},
|
|
||||||
Spec: crdv1.VolumeSnapshotSpec{
|
|
||||||
VolumeSnapshotClassName: &validSecretClass,
|
|
||||||
Source: crdv1.VolumeSnapshotSource{
|
|
||||||
PersistentVolumeClaimName: &claim31,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
Status: &crdv1.VolumeSnapshotStatus{
|
|
||||||
CreationTime: nil,
|
|
||||||
ReadyToUse: &False,
|
|
||||||
Error: nil,
|
|
||||||
RestoreSize: nil,
|
|
||||||
BoundVolumeSnapshotContentName: &content31,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
initialClaims: newClaimArray("claim3-1", "pvc-uid3-1", "1Gi", "volume3-1", v1.ClaimBound, &classEmpty),
|
initialClaims: newClaimArray("claim3-1", "pvc-uid3-1", "1Gi", "volume3-1", v1.ClaimBound, &classEmpty),
|
||||||
expectedEvents: noevents,
|
expectedEvents: noevents,
|
||||||
initialSecrets: []*v1.Secret{secret()},
|
initialSecrets: []*v1.Secret{secret()},
|
||||||
|
Reference in New Issue
Block a user