From b5a4f629b9b44f3f722ae892d04addf858dc2290 Mon Sep 17 00:00:00 2001 From: Daniel Jiang Date: Thu, 31 Mar 2022 21:00:11 +0800 Subject: [PATCH] Bump up the API from v1beta1 to v1 This commit updates the CSI plugin to use the v1 API. Signed-off-by: Daniel Jiang --- .github/auto-assignees.yml | 4 - changelogs/unreleased/99-reasonerjt | 1 + go.mod | 2 +- go.sum | 3 +- internal/backup/pvc_action.go | 16 +- internal/backup/volumesnapshot_action.go | 8 +- internal/backup/volumesnapshotclass_action.go | 4 +- .../backup/volumesnapshotcontent_action.go | 4 +- internal/delete/volumesnapshot_action.go | 8 +- .../delete/volumesnapshotcontent_action.go | 8 +- internal/restore/pvc_action.go | 6 +- internal/restore/volumesnapshot_action.go | 20 +-- .../restore/volumesnapshot_action_test.go | 16 +- .../restore/volumesnapshotclass_action.go | 4 +- .../restore/volumesnapshotcontent_action.go | 4 +- internal/util/util.go | 22 +-- internal/util/util_test.go | 140 +++++++++--------- 17 files changed, 134 insertions(+), 136 deletions(-) create mode 100644 changelogs/unreleased/99-reasonerjt diff --git a/.github/auto-assignees.yml b/.github/auto-assignees.yml index 7e2b36cf..19e77a94 100644 --- a/.github/auto-assignees.yml +++ b/.github/auto-assignees.yml @@ -9,14 +9,10 @@ reviewers: groups: maintainers: - - dsu-igeek - - jenting - sseago - reasonerjt - ywk253100 - blackpiglet - - qiuming-best - options: ignore_draft: true ignored_keywords: diff --git a/changelogs/unreleased/99-reasonerjt b/changelogs/unreleased/99-reasonerjt new file mode 100644 index 00000000..dee2b5f2 --- /dev/null +++ b/changelogs/unreleased/99-reasonerjt @@ -0,0 +1 @@ +Bump up the API from v1beta1 to v1 \ No newline at end of file diff --git a/go.mod b/go.mod index f403dccf..87c3438e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/vmware-tanzu/velero-plugin-for-csi go 1.17 require ( - github.com/kubernetes-csi/external-snapshotter/client/v4 v4.0.0 + github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.8.1 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index bf09ad61..4c9506b2 100644 --- a/go.sum +++ b/go.sum @@ -436,8 +436,9 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kubernetes-csi/external-snapshotter/client/v4 v4.0.0 h1:ipLtV9ubLEYx42YvwDa12eVPQvjuGZoPdbCozGzVNRc= github.com/kubernetes-csi/external-snapshotter/client/v4 v4.0.0/go.mod h1:YBCo4DoEeDndqvAn6eeu0vWM7QdXmHEeI9cFWplmBys= +github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 h1:nHHjmvjitIiyPlUHk/ofpgvBcNcawJLtf4PYHORLjAA= +github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0/go.mod h1:YBCo4DoEeDndqvAn6eeu0vWM7QdXmHEeI9cFWplmBys= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE= github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= diff --git a/internal/backup/pvc_action.go b/internal/backup/pvc_action.go index 51c19602..7097d35d 100644 --- a/internal/backup/pvc_action.go +++ b/internal/backup/pvc_action.go @@ -23,7 +23,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" corev1api "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -105,7 +105,7 @@ func (p *PVCBackupItemAction) Execute(item runtime.Unstructured, backup *velerov return nil, nil, errors.Wrap(err, "error getting storage class") } p.Log.Debugf("Fetching volumesnapshot class for %s", storageClass.Provisioner) - snapshotClass, err := util.GetVolumeSnapshotClassForStorageClass(storageClass.Provisioner, snapshotClient.SnapshotV1beta1()) + snapshotClass, err := util.GetVolumeSnapshotClassForStorageClass(storageClass.Provisioner, snapshotClient.SnapshotV1()) if err != nil { return nil, nil, errors.Wrapf(err, "failed to get volumesnapshotclass for storageclass %s", storageClass.Name) } @@ -114,12 +114,12 @@ func (p *PVCBackupItemAction) Execute(item runtime.Unstructured, backup *velerov // If deletetionPolicy is not Retain, then in the event of a disaster, the namespace is lost with the volumesnapshot object in it, // the underlying volumesnapshotcontent and the volume snapshot in the storage provider is also deleted. // In such a scenario, the backup objects will be useless as the snapshot handle itself will not be valid. - if snapshotClass.DeletionPolicy != snapshotv1beta1api.VolumeSnapshotContentRetain { + if snapshotClass.DeletionPolicy != snapshotv1api.VolumeSnapshotContentRetain { p.Log.Warnf("DeletionPolicy on VolumeSnapshotClass %s is not %s; Deletion of VolumeSnapshot objects will lead to deletion of snapshot in the storage provider.", - snapshotClass.Name, snapshotv1beta1api.VolumeSnapshotContentRetain) + snapshotClass.Name, snapshotv1api.VolumeSnapshotContentRetain) } // Craft the snapshot object to be created - snapshot := snapshotv1beta1api.VolumeSnapshot{ + snapshot := snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ GenerateName: "velero-" + pvc.Name + "-", Namespace: pvc.Namespace, @@ -127,15 +127,15 @@ func (p *PVCBackupItemAction) Execute(item runtime.Unstructured, backup *velerov velerov1api.BackupNameLabel: label.GetValidName(backup.Name), }, }, - Spec: snapshotv1beta1api.VolumeSnapshotSpec{ - Source: snapshotv1beta1api.VolumeSnapshotSource{ + Spec: snapshotv1api.VolumeSnapshotSpec{ + Source: snapshotv1api.VolumeSnapshotSource{ PersistentVolumeClaimName: &pvc.Name, }, VolumeSnapshotClassName: &snapshotClass.Name, }, } - upd, err := snapshotClient.SnapshotV1beta1().VolumeSnapshots(pvc.Namespace).Create(context.TODO(), &snapshot, metav1.CreateOptions{}) + upd, err := snapshotClient.SnapshotV1().VolumeSnapshots(pvc.Namespace).Create(context.TODO(), &snapshot, metav1.CreateOptions{}) if err != nil { return nil, nil, errors.Wrapf(err, "error creating volume snapshot") } diff --git a/internal/backup/volumesnapshot_action.go b/internal/backup/volumesnapshot_action.go index 6786af9c..883c2807 100644 --- a/internal/backup/volumesnapshot_action.go +++ b/internal/backup/volumesnapshot_action.go @@ -23,7 +23,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -57,7 +57,7 @@ func (p *VolumeSnapshotBackupItemAction) AppliesTo() (velero.ResourceSelector, e func (p *VolumeSnapshotBackupItemAction) Execute(item runtime.Unstructured, backup *velerov1api.Backup) (runtime.Unstructured, []velero.ResourceIdentifier, error) { p.Log.Infof("Executing VolumeSnapshotBackupItemAction") - var vs snapshotv1beta1api.VolumeSnapshot + var vs snapshotv1api.VolumeSnapshot if err := runtime.DefaultUnstructuredConverter.FromUnstructured(item.UnstructuredContent(), &vs); err != nil { return nil, nil, errors.WithStack(err) } @@ -90,7 +90,7 @@ func (p *VolumeSnapshotBackupItemAction) Execute(item runtime.Unstructured, back p.Log.Infof("Getting VolumesnapshotContent for Volumesnapshot %s/%s", vs.Namespace, vs.Name) - vsc, err := util.GetVolumeSnapshotContentForVolumeSnapshot(&vs, snapshotClient.SnapshotV1beta1(), p.Log, backupOngoing) + vsc, err := util.GetVolumeSnapshotContentForVolumeSnapshot(&vs, snapshotClient.SnapshotV1(), p.Log, backupOngoing) if err != nil { return nil, nil, errors.WithStack(err) } @@ -137,7 +137,7 @@ func (p *VolumeSnapshotBackupItemAction) Execute(item runtime.Unstructured, back // Further, we want to add this label only on volumesnapshotcontents that were created during an ongoing velero backup. pb := []byte(fmt.Sprintf(`{"metadata":{"labels":{"%s":"%s"}}}`, velerov1api.BackupNameLabel, label.GetValidName(backup.Name))) - if _, vscPatchError := snapshotClient.SnapshotV1beta1().VolumeSnapshotContents().Patch(context.TODO(), vsc.Name, types.MergePatchType, pb, metav1.PatchOptions{}); vscPatchError != nil { + if _, vscPatchError := snapshotClient.SnapshotV1().VolumeSnapshotContents().Patch(context.TODO(), vsc.Name, types.MergePatchType, pb, metav1.PatchOptions{}); vscPatchError != nil { p.Log.Warnf("Failed to patch volumesnapshotcontent %s: %v", vsc.Name, vscPatchError) } } diff --git a/internal/backup/volumesnapshotclass_action.go b/internal/backup/volumesnapshotclass_action.go index b4c644a1..e2280817 100644 --- a/internal/backup/volumesnapshotclass_action.go +++ b/internal/backup/volumesnapshotclass_action.go @@ -20,7 +20,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -48,7 +48,7 @@ func (p *VolumeSnapshotClassBackupItemAction) AppliesTo() (velero.ResourceSelect func (p *VolumeSnapshotClassBackupItemAction) Execute(item runtime.Unstructured, backup *velerov1api.Backup) (runtime.Unstructured, []velero.ResourceIdentifier, error) { p.Log.Infof("Executing VolumeSnapshotClassBackupItemAction") - var snapClass snapshotv1beta1api.VolumeSnapshotClass + var snapClass snapshotv1api.VolumeSnapshotClass if err := runtime.DefaultUnstructuredConverter.FromUnstructured(item.UnstructuredContent(), &snapClass); err != nil { return nil, nil, errors.WithStack(err) } diff --git a/internal/backup/volumesnapshotcontent_action.go b/internal/backup/volumesnapshotcontent_action.go index 67e85fc0..84f5a438 100644 --- a/internal/backup/volumesnapshotcontent_action.go +++ b/internal/backup/volumesnapshotcontent_action.go @@ -17,10 +17,10 @@ limitations under the License. package backup import ( + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" "github.com/pkg/errors" "github.com/sirupsen/logrus" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -49,7 +49,7 @@ func (p *VolumeSnapshotContentBackupItemAction) AppliesTo() (velero.ResourceSele func (p *VolumeSnapshotContentBackupItemAction) Execute(item runtime.Unstructured, backup *velerov1api.Backup) (runtime.Unstructured, []velero.ResourceIdentifier, error) { p.Log.Infof("Executing VolumeSnapshotContentBackupItemAction") - var snapCont snapshotv1beta1api.VolumeSnapshotContent + var snapCont snapshotv1api.VolumeSnapshotContent if err := runtime.DefaultUnstructuredConverter.FromUnstructured(item.UnstructuredContent(), &snapCont); err != nil { return nil, nil, errors.WithStack(err) } diff --git a/internal/delete/volumesnapshot_action.go b/internal/delete/volumesnapshot_action.go index 65c8dcbb..bc9efe1f 100644 --- a/internal/delete/volumesnapshot_action.go +++ b/internal/delete/volumesnapshot_action.go @@ -11,7 +11,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" ) @@ -32,7 +32,7 @@ func (p *VolumeSnapshotDeleteItemAction) AppliesTo() (velero.ResourceSelector, e func (p *VolumeSnapshotDeleteItemAction) Execute(input *velero.DeleteItemActionExecuteInput) error { p.Log.Info("Starting VolumeSnapshotDeleteItemAction for volumeSnapshot") - var vs snapshotv1beta1api.VolumeSnapshot + var vs snapshotv1api.VolumeSnapshot if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), &vs); err != nil { return errors.Wrapf(err, "failed to convert input.Item from unstructured") @@ -54,7 +54,7 @@ func (p *VolumeSnapshotDeleteItemAction) Execute(input *velero.DeleteItemActionE if vs.Status != nil && vs.Status.BoundVolumeSnapshotContentName != nil { // we patch the DeletionPolicy of the volumesnapshotcontent to set it to Delete. // This ensures that the volume snapshot in the storage provider is also deleted. - err := util.SetVolumeSnapshotContentDeletionPolicy(*vs.Status.BoundVolumeSnapshotContentName, snapClient.SnapshotV1beta1()) + err := util.SetVolumeSnapshotContentDeletionPolicy(*vs.Status.BoundVolumeSnapshotContentName, snapClient.SnapshotV1()) if err != nil && !apierrors.IsNotFound(err) { return errors.Wrapf(err, fmt.Sprintf("failed to patch DeletionPolicy of volume snapshot %s/%s", vs.Namespace, vs.Name)) } @@ -63,7 +63,7 @@ func (p *VolumeSnapshotDeleteItemAction) Execute(input *velero.DeleteItemActionE return nil } } - err = snapClient.SnapshotV1beta1().VolumeSnapshots(vs.Namespace).Delete(context.TODO(), vs.Name, metav1.DeleteOptions{}) + err = snapClient.SnapshotV1().VolumeSnapshots(vs.Namespace).Delete(context.TODO(), vs.Name, metav1.DeleteOptions{}) if err != nil && !apierrors.IsNotFound(err) { return err } diff --git a/internal/delete/volumesnapshotcontent_action.go b/internal/delete/volumesnapshotcontent_action.go index a1983284..a4038a4c 100644 --- a/internal/delete/volumesnapshotcontent_action.go +++ b/internal/delete/volumesnapshotcontent_action.go @@ -12,7 +12,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" ) // VolumeSnapshotContentDeleteItemAction is a restore item action plugin for Velero @@ -31,7 +31,7 @@ func (p *VolumeSnapshotContentDeleteItemAction) AppliesTo() (velero.ResourceSele func (p *VolumeSnapshotContentDeleteItemAction) Execute(input *velero.DeleteItemActionExecuteInput) error { p.Log.Info("Starting VolumeSnapshotContentDeleteItemAction") - var snapCont snapshotv1beta1api.VolumeSnapshotContent + var snapCont snapshotv1api.VolumeSnapshotContent if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), &snapCont); err != nil { return errors.Wrapf(err, "failed to convert input.Item from unstructured") } @@ -51,7 +51,7 @@ func (p *VolumeSnapshotContentDeleteItemAction) Execute(input *velero.DeleteItem return errors.WithStack(err) } - err = util.SetVolumeSnapshotContentDeletionPolicy(snapCont.Name, snapClient.SnapshotV1beta1()) + err = util.SetVolumeSnapshotContentDeletionPolicy(snapCont.Name, snapClient.SnapshotV1()) if err != nil { if apierrors.IsNotFound(err) { p.Log.Infof("VolumeSnapshotContent %s not found", snapCont.Name) @@ -60,7 +60,7 @@ func (p *VolumeSnapshotContentDeleteItemAction) Execute(input *velero.DeleteItem return errors.Wrapf(err, fmt.Sprintf("failed to set DeletionPolicy on volumesnapshotcontent %s. Skipping deletion", snapCont.Name)) } - err = snapClient.SnapshotV1beta1().VolumeSnapshotContents().Delete(context.TODO(), snapCont.Name, metav1.DeleteOptions{}) + err = snapClient.SnapshotV1().VolumeSnapshotContents().Delete(context.TODO(), snapCont.Name, metav1.DeleteOptions{}) if err != nil && !apierrors.IsNotFound(err) { p.Log.Infof("VolumeSnapshotContent %s not found", snapCont.Name) return err diff --git a/internal/restore/pvc_action.go b/internal/restore/pvc_action.go index c3c41a2f..5990e3a2 100644 --- a/internal/restore/pvc_action.go +++ b/internal/restore/pvc_action.go @@ -20,10 +20,10 @@ import ( "context" "fmt" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" "github.com/pkg/errors" "github.com/sirupsen/logrus" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" corev1api "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -71,7 +71,7 @@ func resetPVCSpec(pvc *corev1api.PersistentVolumeClaim, vsName string) { // So clear out the volume name, which is a ref to the PV pvc.Spec.VolumeName = "" pvc.Spec.DataSource = &corev1api.TypedLocalObjectReference{ - APIGroup: &snapshotv1beta1api.SchemeGroupVersion.Group, + APIGroup: &snapshotv1api.SchemeGroupVersion.Group, Kind: "VolumeSnapshot", Name: vsName, } @@ -123,7 +123,7 @@ func (p *PVCRestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInp return nil, errors.WithStack(err) } - vs, err := snapClient.SnapshotV1beta1().VolumeSnapshots(pvc.Namespace).Get(context.TODO(), volumeSnapshotName, metav1.GetOptions{}) + vs, err := snapClient.SnapshotV1().VolumeSnapshots(pvc.Namespace).Get(context.TODO(), volumeSnapshotName, metav1.GetOptions{}) if err != nil { return nil, errors.Wrapf(err, fmt.Sprintf("Failed to get Volumesnapshot %s/%s to restore PVC %s/%s", pvc.Namespace, volumeSnapshotName, pvc.Namespace, pvc.Name)) } diff --git a/internal/restore/volumesnapshot_action.go b/internal/restore/volumesnapshot_action.go index c94bc210..3c3e4abc 100644 --- a/internal/restore/volumesnapshot_action.go +++ b/internal/restore/volumesnapshot_action.go @@ -22,7 +22,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" core_v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -47,7 +47,7 @@ func (p *VolumeSnapshotRestoreItemAction) AppliesTo() (velero.ResourceSelector, }, nil } -func resetVolumeSnapshotSpecForRestore(vs *snapshotv1beta1api.VolumeSnapshot, vscName *string) { +func resetVolumeSnapshotSpecForRestore(vs *snapshotv1api.VolumeSnapshot, vscName *string) { // Spec of the backed-up object used the PVC as the source of the volumeSnapshot. // Restore operation will however, restore the volumesnapshot from the volumesnapshotcontent vs.Spec.Source.PersistentVolumeClaimName = nil @@ -58,7 +58,7 @@ func resetVolumeSnapshotSpecForRestore(vs *snapshotv1beta1api.VolumeSnapshot, vs // to recreate a volumesnapshotcontent object and statically bind the Volumesnapshot object being restored. func (p *VolumeSnapshotRestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { p.Log.Info("Starting VolumeSnapshotRestoreItemAction") - var vs snapshotv1beta1api.VolumeSnapshot + var vs snapshotv1api.VolumeSnapshot if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), &vs); err != nil { return &velero.RestoreItemActionExecuteOutput{}, errors.Wrapf(err, "failed to convert input.Item from unstructured") @@ -75,7 +75,7 @@ func (p *VolumeSnapshotRestoreItemAction) Execute(input *velero.RestoreItemActio return nil, errors.WithStack(err) } - if !util.IsVolumeSnapshotExists(&vs, snapClient.SnapshotV1beta1()) { + if !util.IsVolumeSnapshotExists(&vs, snapClient.SnapshotV1()) { snapHandle, exists := vs.Annotations[util.VolumeSnapshotHandleAnnotation] if !exists { return nil, errors.Errorf("Volumesnapshot %s/%s does not have a %s annotation", vs.Namespace, vs.Name, util.VolumeSnapshotHandleAnnotation) @@ -90,26 +90,26 @@ func (p *VolumeSnapshotRestoreItemAction) Execute(input *velero.RestoreItemActio if !exists { p.Log.Infof("Volumesnapshot %s/%s does not have a %s annotation using DeletionPolicy Retain for volumesnapshotcontent", vs.Namespace, vs.Name, util.CSIVSCDeletionPolicy) - deletionPolicy = string(snapshotv1beta1api.VolumeSnapshotContentRetain) + deletionPolicy = string(snapshotv1api.VolumeSnapshotContentRetain) } // TODO: generated name will be like velero-velero-something. Fix that. - vsc := snapshotv1beta1api.VolumeSnapshotContent{ + vsc := snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ GenerateName: "velero-" + vs.Name + "-", Labels: map[string]string{ velerov1api.RestoreNameLabel: label.GetValidName(input.Restore.Name), }, }, - Spec: snapshotv1beta1api.VolumeSnapshotContentSpec{ - DeletionPolicy: snapshotv1beta1api.DeletionPolicy(deletionPolicy), + Spec: snapshotv1api.VolumeSnapshotContentSpec{ + DeletionPolicy: snapshotv1api.DeletionPolicy(deletionPolicy), Driver: csiDriverName, VolumeSnapshotRef: core_v1.ObjectReference{ Kind: "VolumeSnapshot", Namespace: vs.Namespace, Name: vs.Name, }, - Source: snapshotv1beta1api.VolumeSnapshotContentSource{ + Source: snapshotv1api.VolumeSnapshotContentSource{ SnapshotHandle: &snapHandle, }, }, @@ -121,7 +121,7 @@ func (p *VolumeSnapshotRestoreItemAction) Execute(input *velero.RestoreItemActio // between the volumesnapshotcontent and volumesnapshot objects have to be setup. // Further, it is disallowed to convert a dynamically created volumesnapshotcontent for static binding. // See: https://github.com/kubernetes-csi/external-snapshotter/issues/274 - vscupd, err := snapClient.SnapshotV1beta1().VolumeSnapshotContents().Create(context.TODO(), &vsc, metav1.CreateOptions{}) + vscupd, err := snapClient.SnapshotV1().VolumeSnapshotContents().Create(context.TODO(), &vsc, metav1.CreateOptions{}) if err != nil { return nil, errors.Wrapf(err, "failed to create volumesnapshotcontents %s", vsc.GenerateName) } diff --git a/internal/restore/volumesnapshot_action_test.go b/internal/restore/volumesnapshot_action_test.go index a59b9645..64792c89 100644 --- a/internal/restore/volumesnapshot_action_test.go +++ b/internal/restore/volumesnapshot_action_test.go @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -34,18 +34,18 @@ var ( func TestResetVolumeSnapshotSpecForRestore(t *testing.T) { testCases := []struct { name string - vs snapshotv1beta1api.VolumeSnapshot + vs snapshotv1api.VolumeSnapshot vscName string }{ { name: "should reset spec as expected", - vs: snapshotv1beta1api.VolumeSnapshot{ + vs: snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "test-vs", Namespace: "test-ns", }, - Spec: snapshotv1beta1api.VolumeSnapshotSpec{ - Source: snapshotv1beta1api.VolumeSnapshotSource{ + Spec: snapshotv1api.VolumeSnapshotSpec{ + Source: snapshotv1api.VolumeSnapshotSource{ PersistentVolumeClaimName: &testPVC, }, VolumeSnapshotClassName: &testSnapClass, @@ -55,13 +55,13 @@ func TestResetVolumeSnapshotSpecForRestore(t *testing.T) { }, { name: "should reset spec and overwriting value for Source.VolumeSnapshotContentName", - vs: snapshotv1beta1api.VolumeSnapshot{ + vs: snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "test-vs", Namespace: "test-ns", }, - Spec: snapshotv1beta1api.VolumeSnapshotSpec{ - Source: snapshotv1beta1api.VolumeSnapshotSource{ + Spec: snapshotv1api.VolumeSnapshotSpec{ + Source: snapshotv1api.VolumeSnapshotSource{ VolumeSnapshotContentName: &randText, }, VolumeSnapshotClassName: &testSnapClass, diff --git a/internal/restore/volumesnapshotclass_action.go b/internal/restore/volumesnapshotclass_action.go index c6926096..6e9c3bc7 100644 --- a/internal/restore/volumesnapshotclass_action.go +++ b/internal/restore/volumesnapshotclass_action.go @@ -20,7 +20,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -45,7 +45,7 @@ func (p *VolumeSnapshotClassRestoreItemAction) AppliesTo() (velero.ResourceSelec func (p *VolumeSnapshotClassRestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { p.Log.Info("Starting VolumeSnapshotClassRestoreItemAction") - var snapClass snapshotv1beta1api.VolumeSnapshotClass + var snapClass snapshotv1api.VolumeSnapshotClass if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), &snapClass); err != nil { return &velero.RestoreItemActionExecuteOutput{}, errors.Wrapf(err, "failed to convert input.Item from unstructured") diff --git a/internal/restore/volumesnapshotcontent_action.go b/internal/restore/volumesnapshotcontent_action.go index ec067cde..3be6b722 100644 --- a/internal/restore/volumesnapshotcontent_action.go +++ b/internal/restore/volumesnapshotcontent_action.go @@ -20,7 +20,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -45,7 +45,7 @@ func (p *VolumeSnapshotContentRestoreItemAction) AppliesTo() (velero.ResourceSel // additional items to restore. func (p *VolumeSnapshotContentRestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { p.Log.Info("Starting VolumeSnapshotContentRestoreItemAction") - var snapCont snapshotv1beta1api.VolumeSnapshotContent + var snapCont snapshotv1api.VolumeSnapshotContent if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), &snapCont); err != nil { return &velero.RestoreItemActionExecuteOutput{}, errors.Wrapf(err, "failed to convert input.Item from unstructured") diff --git a/internal/util/util.go b/internal/util/util.go index 6d908e5e..c22f2451 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -22,12 +22,12 @@ import ( "strings" "time" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" "github.com/pkg/errors" "github.com/sirupsen/logrus" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" snapshotterClientSet "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned" - snapshotter "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned/typed/volumesnapshot/v1beta1" + snapshotter "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned/typed/volumesnapshot/v1" corev1api "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -121,7 +121,7 @@ func IsPVCBackedUpByRestic(pvcNamespace, pvcName string, podClient corev1client. } // GetVolumeSnapshotClassForStorageClass returns a VolumeSnapshotClass for the supplied volume provisioner/ driver name. -func GetVolumeSnapshotClassForStorageClass(provisioner string, snapshotClient snapshotter.SnapshotV1beta1Interface) (*snapshotv1beta1api.VolumeSnapshotClass, error) { +func GetVolumeSnapshotClassForStorageClass(provisioner string, snapshotClient snapshotter.SnapshotV1Interface) (*snapshotv1api.VolumeSnapshotClass, error) { snapshotClasses, err := snapshotClient.VolumeSnapshotClasses().List(context.TODO(), metav1.ListOptions{}) if err != nil { return nil, errors.Wrap(err, "error listing volumesnapshot classes") @@ -129,7 +129,7 @@ func GetVolumeSnapshotClassForStorageClass(provisioner string, snapshotClient sn // We pick the volumesnapshotclass that matches the CSI driver name and has a 'velero.io/csi-volumesnapshot-class' // label. This allows multiple VolumesnapshotClasses for the same driver with different values for the // other fields in the spec. - // https://pkg.go.dev/github.com/kubernetes-csi/external-snapshotter/v2@v2.0.1/pkg/apis/volumesnapshot/v1beta1?tab=doc#VolumeSnapshotClass + // https://github.com/kubernetes-csi/external-snapshotter/blob/release-4.2/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml for _, sc := range snapshotClasses.Items { _, hasLabelSelector := sc.Labels[VolumeSnapshotClassSelectorLabel] if sc.Driver == provisioner && hasLabelSelector { @@ -140,7 +140,7 @@ func GetVolumeSnapshotClassForStorageClass(provisioner string, snapshotClient sn } // GetVolumeSnapshotContentForVolumeSnapshot returns the volumesnapshotcontent object associated with the volumesnapshot -func GetVolumeSnapshotContentForVolumeSnapshot(volSnap *snapshotv1beta1api.VolumeSnapshot, snapshotClient snapshotter.SnapshotV1beta1Interface, log logrus.FieldLogger, shouldWait bool) (*snapshotv1beta1api.VolumeSnapshotContent, error) { +func GetVolumeSnapshotContentForVolumeSnapshot(volSnap *snapshotv1api.VolumeSnapshot, snapshotClient snapshotter.SnapshotV1Interface, log logrus.FieldLogger, shouldWait bool) (*snapshotv1api.VolumeSnapshotContent, error) { if !shouldWait { if volSnap.Status == nil || volSnap.Status.BoundVolumeSnapshotContentName == nil { // volumesnapshot hasn't been reconciled and we're not waiting for it. @@ -157,7 +157,7 @@ func GetVolumeSnapshotContentForVolumeSnapshot(volSnap *snapshotv1beta1api.Volum // TODO: make this timeout configurable. timeout := 10 * time.Minute interval := 5 * time.Second - var snapshotContent *snapshotv1beta1api.VolumeSnapshotContent + var snapshotContent *snapshotv1api.VolumeSnapshotContent err := wait.PollImmediate(interval, timeout, func() (bool, error) { vs, err := snapshotClient.VolumeSnapshots(volSnap.Namespace).Get(context.TODO(), volSnap.Name, metav1.GetOptions{}) @@ -219,7 +219,7 @@ func GetClients() (*kubernetes.Clientset, *snapshotterClientSet.Clientset, error } // IsVolumeSnapshotClassHasListerSecret returns whether a volumesnapshotclass has a snapshotlister secret -func IsVolumeSnapshotClassHasListerSecret(vc *snapshotv1beta1api.VolumeSnapshotClass) bool { +func IsVolumeSnapshotClassHasListerSecret(vc *snapshotv1api.VolumeSnapshotClass) bool { // https://github.com/kubernetes-csi/external-snapshotter/blob/master/pkg/utils/util.go#L59-L60 // There is no release w/ these constants exported. Using the strings for now. _, nameExists := vc.Annotations[PrefixedSnapshotterListSecretNameKey] @@ -228,7 +228,7 @@ func IsVolumeSnapshotClassHasListerSecret(vc *snapshotv1beta1api.VolumeSnapshotC } // IsVolumeSnapshotContentHasDeleteSecret returns whether a volumesnapshotcontent has a deletesnapshot secret -func IsVolumeSnapshotContentHasDeleteSecret(vsc *snapshotv1beta1api.VolumeSnapshotContent) bool { +func IsVolumeSnapshotContentHasDeleteSecret(vsc *snapshotv1api.VolumeSnapshotContent) bool { // https://github.com/kubernetes-csi/external-snapshotter/blob/master/pkg/utils/util.go#L56-L57 // use exported constants in the next release _, nameExists := vsc.Annotations[PrefixedSnapshotterSecretNameKey] @@ -238,7 +238,7 @@ func IsVolumeSnapshotContentHasDeleteSecret(vsc *snapshotv1beta1api.VolumeSnapsh // IsVolumeSnapshotHasVSCDeleteSecret returns whether a volumesnapshot should set the deletesnapshot secret // for the static volumesnapshotcontent that is created on restore -func IsVolumeSnapshotHasVSCDeleteSecret(vs *snapshotv1beta1api.VolumeSnapshot) bool { +func IsVolumeSnapshotHasVSCDeleteSecret(vs *snapshotv1api.VolumeSnapshot) bool { _, nameExists := vs.Annotations[CSIDeleteSnapshotSecretName] _, nsExists := vs.Annotations[CSIDeleteSnapshotSecretNamespace] return nameExists && nsExists @@ -265,7 +265,7 @@ func AddLabels(o *metav1.ObjectMeta, vals map[string]string) { } // IsVolumeSnapshotExists returns whether a specific volumesnapshot object exists. -func IsVolumeSnapshotExists(volSnap *snapshotv1beta1api.VolumeSnapshot, snapshotClient snapshotter.SnapshotV1beta1Interface) bool { +func IsVolumeSnapshotExists(volSnap *snapshotv1api.VolumeSnapshot, snapshotClient snapshotter.SnapshotV1Interface) bool { exists := false if volSnap != nil { vs, err := snapshotClient.VolumeSnapshots(volSnap.Namespace).Get(context.TODO(), volSnap.Name, metav1.GetOptions{}) @@ -277,7 +277,7 @@ func IsVolumeSnapshotExists(volSnap *snapshotv1beta1api.VolumeSnapshot, snapshot return exists } -func SetVolumeSnapshotContentDeletionPolicy(vscName string, csiClient snapshotter.SnapshotV1beta1Interface) error { +func SetVolumeSnapshotContentDeletionPolicy(vscName string, csiClient snapshotter.SnapshotV1Interface) error { pb := []byte(`{"spec":{"deletionPolicy":"Delete"}}`) _, err := csiClient.VolumeSnapshotContents().Patch(context.TODO(), vscName, types.MergePatchType, pb, metav1.PatchOptions{}) diff --git a/internal/util/util_test.go b/internal/util/util_test.go index fc17b861..91a9d775 100644 --- a/internal/util/util_test.go +++ b/internal/util/util_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" - snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" snapshotFake "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned/fake" "github.com/sirupsen/logrus" corev1api "k8s.io/api/core/v1" @@ -622,7 +622,7 @@ func TestIsPVCBackedUpByRestic(t *testing.T) { } func TestGetVolumeSnapshotCalssForStorageClass(t *testing.T) { - hostpathClass := &snapshotv1beta1api.VolumeSnapshotClass{ + hostpathClass := &snapshotv1api.VolumeSnapshotClass{ ObjectMeta: metav1.ObjectMeta{ Name: "hostpath", Labels: map[string]string{ @@ -632,7 +632,7 @@ func TestGetVolumeSnapshotCalssForStorageClass(t *testing.T) { Driver: "hostpath.csi.k8s.io", } - fooClass := &snapshotv1beta1api.VolumeSnapshotClass{ + fooClass := &snapshotv1api.VolumeSnapshotClass{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", Labels: map[string]string{ @@ -642,7 +642,7 @@ func TestGetVolumeSnapshotCalssForStorageClass(t *testing.T) { Driver: "foo.csi.k8s.io", } - barClass := &snapshotv1beta1api.VolumeSnapshotClass{ + barClass := &snapshotv1api.VolumeSnapshotClass{ ObjectMeta: metav1.ObjectMeta{ Name: "bar", Labels: map[string]string{ @@ -652,7 +652,7 @@ func TestGetVolumeSnapshotCalssForStorageClass(t *testing.T) { Driver: "bar.csi.k8s.io", } - bazClass := &snapshotv1beta1api.VolumeSnapshotClass{ + bazClass := &snapshotv1api.VolumeSnapshotClass{ ObjectMeta: metav1.ObjectMeta{ Name: "baz", }, @@ -665,7 +665,7 @@ func TestGetVolumeSnapshotCalssForStorageClass(t *testing.T) { testCases := []struct { name string driverName string - expectedVSC *snapshotv1beta1api.VolumeSnapshotClass + expectedVSC *snapshotv1api.VolumeSnapshotClass expectError bool }{ { @@ -702,7 +702,7 @@ func TestGetVolumeSnapshotCalssForStorageClass(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - actualVSC, actualError := GetVolumeSnapshotClassForStorageClass(tc.driverName, fakeClient.SnapshotV1beta1()) + actualVSC, actualError := GetVolumeSnapshotClassForStorageClass(tc.driverName, fakeClient.SnapshotV1()) if tc.expectError { assert.NotNil(t, actualError) @@ -719,102 +719,102 @@ func TestGetVolumeSnapshotCalssForStorageClass(t *testing.T) { func TestGetVolumeSnapshotContentForVolumeSnapshot(t *testing.T) { vscName := "snapcontent-7d1bdbd1-d10d-439c-8d8e-e1c2565ddc53" snapshotHandle := "snapshot-handle" - vscObj := &snapshotv1beta1api.VolumeSnapshotContent{ + vscObj := &snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ Name: vscName, }, - Spec: snapshotv1beta1api.VolumeSnapshotContentSpec{ + Spec: snapshotv1api.VolumeSnapshotContentSpec{ VolumeSnapshotRef: corev1api.ObjectReference{ Name: "vol-snap-1", - APIVersion: snapshotv1beta1api.SchemeGroupVersion.String(), + APIVersion: snapshotv1api.SchemeGroupVersion.String(), }, }, - Status: &snapshotv1beta1api.VolumeSnapshotContentStatus{ + Status: &snapshotv1api.VolumeSnapshotContentStatus{ SnapshotHandle: &snapshotHandle, }, } - validVS := &snapshotv1beta1api.VolumeSnapshot{ + validVS := &snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "vs", Namespace: "default", }, - Status: &snapshotv1beta1api.VolumeSnapshotStatus{ + Status: &snapshotv1api.VolumeSnapshotStatus{ BoundVolumeSnapshotContentName: &vscName, }, } notFound := "does-not-exist" - vsWithVSCNotFound := &snapshotv1beta1api.VolumeSnapshot{ + vsWithVSCNotFound := &snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: notFound, Namespace: "default", }, - Status: &snapshotv1beta1api.VolumeSnapshotStatus{ + Status: &snapshotv1api.VolumeSnapshotStatus{ BoundVolumeSnapshotContentName: ¬Found, }, } - vsWithNilStatus := &snapshotv1beta1api.VolumeSnapshot{ + vsWithNilStatus := &snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "nil-status-vs", Namespace: "default", }, Status: nil, } - vsWithNilStatusField := &snapshotv1beta1api.VolumeSnapshot{ + vsWithNilStatusField := &snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "nil-status-field-vs", Namespace: "default", }, - Status: &snapshotv1beta1api.VolumeSnapshotStatus{ + Status: &snapshotv1api.VolumeSnapshotStatus{ BoundVolumeSnapshotContentName: nil, }, } nilStatusVsc := "nil-status-vsc" - vscWithNilStatus := &snapshotv1beta1api.VolumeSnapshotContent{ + vscWithNilStatus := &snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ Name: nilStatusVsc, }, - Spec: snapshotv1beta1api.VolumeSnapshotContentSpec{ + Spec: snapshotv1api.VolumeSnapshotContentSpec{ VolumeSnapshotRef: corev1api.ObjectReference{ Name: "vol-snap-1", - APIVersion: snapshotv1beta1api.SchemeGroupVersion.String(), + APIVersion: snapshotv1api.SchemeGroupVersion.String(), }, }, Status: nil, } - vsForNilStatusVsc := &snapshotv1beta1api.VolumeSnapshot{ + vsForNilStatusVsc := &snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "vs-for-nil-status-vsc", Namespace: "default", }, - Status: &snapshotv1beta1api.VolumeSnapshotStatus{ + Status: &snapshotv1api.VolumeSnapshotStatus{ BoundVolumeSnapshotContentName: &nilStatusVsc, }, } nilStatusFieldVsc := "nil-status-field-vsc" - vscWithNilStatusField := &snapshotv1beta1api.VolumeSnapshotContent{ + vscWithNilStatusField := &snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ Name: nilStatusFieldVsc, }, - Spec: snapshotv1beta1api.VolumeSnapshotContentSpec{ + Spec: snapshotv1api.VolumeSnapshotContentSpec{ VolumeSnapshotRef: corev1api.ObjectReference{ Name: "vol-snap-1", - APIVersion: snapshotv1beta1api.SchemeGroupVersion.String(), + APIVersion: snapshotv1api.SchemeGroupVersion.String(), }, }, - Status: &snapshotv1beta1api.VolumeSnapshotContentStatus{ + Status: &snapshotv1api.VolumeSnapshotContentStatus{ SnapshotHandle: nil, }, } - vsForNilStatusFieldVsc := &snapshotv1beta1api.VolumeSnapshot{ + vsForNilStatusFieldVsc := &snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "vs-for-nil-status-field", Namespace: "default", }, - Status: &snapshotv1beta1api.VolumeSnapshotStatus{ + Status: &snapshotv1api.VolumeSnapshotStatus{ BoundVolumeSnapshotContentName: &nilStatusFieldVsc, }, } @@ -823,8 +823,8 @@ func TestGetVolumeSnapshotContentForVolumeSnapshot(t *testing.T) { fakeClient := snapshotFake.NewSimpleClientset(objs...) testCases := []struct { name string - volSnap *snapshotv1beta1api.VolumeSnapshot - exepctedVSC *snapshotv1beta1api.VolumeSnapshotContent + volSnap *snapshotv1api.VolumeSnapshot + exepctedVSC *snapshotv1api.VolumeSnapshotContent wait bool expectError bool }{ @@ -847,12 +847,12 @@ func TestGetVolumeSnapshotContentForVolumeSnapshot(t *testing.T) { wait: true, exepctedVSC: nil, expectError: true, - volSnap: &snapshotv1beta1api.VolumeSnapshot{ + volSnap: &snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "not-found", Namespace: "default", }, - Status: &snapshotv1beta1api.VolumeSnapshotStatus{ + Status: &snapshotv1api.VolumeSnapshotStatus{ BoundVolumeSnapshotContentName: &nilStatusVsc, }, }, @@ -896,7 +896,7 @@ func TestGetVolumeSnapshotContentForVolumeSnapshot(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - actualVSC, actualError := GetVolumeSnapshotContentForVolumeSnapshot(tc.volSnap, fakeClient.SnapshotV1beta1(), logrus.New().WithField("fake", "test"), tc.wait) + actualVSC, actualError := GetVolumeSnapshotContentForVolumeSnapshot(tc.volSnap, fakeClient.SnapshotV1(), logrus.New().WithField("fake", "test"), tc.wait) if tc.expectError && actualError == nil { assert.NotNil(t, actualError) assert.Nil(t, actualVSC) @@ -910,12 +910,12 @@ func TestGetVolumeSnapshotContentForVolumeSnapshot(t *testing.T) { func TestIsVolumeSnapshotClassHasListerSecret(t *testing.T) { testCases := []struct { name string - snapClass snapshotv1beta1api.VolumeSnapshotClass + snapClass snapshotv1api.VolumeSnapshotClass expected bool }{ { name: "should find both annotations", - snapClass: snapshotv1beta1api.VolumeSnapshotClass{ + snapClass: snapshotv1api.VolumeSnapshotClass{ ObjectMeta: metav1.ObjectMeta{ Name: "class-1", Annotations: map[string]string{ @@ -928,7 +928,7 @@ func TestIsVolumeSnapshotClassHasListerSecret(t *testing.T) { }, { name: "should not find both annotations name is missing", - snapClass: snapshotv1beta1api.VolumeSnapshotClass{ + snapClass: snapshotv1api.VolumeSnapshotClass{ ObjectMeta: metav1.ObjectMeta{ Name: "class-1", Annotations: map[string]string{ @@ -941,7 +941,7 @@ func TestIsVolumeSnapshotClassHasListerSecret(t *testing.T) { }, { name: "should not find both annotations namespace is missing", - snapClass: snapshotv1beta1api.VolumeSnapshotClass{ + snapClass: snapshotv1api.VolumeSnapshotClass{ ObjectMeta: metav1.ObjectMeta{ Name: "class-1", Annotations: map[string]string{ @@ -954,7 +954,7 @@ func TestIsVolumeSnapshotClassHasListerSecret(t *testing.T) { }, { name: "should not find expected annotation non-empty annotation", - snapClass: snapshotv1beta1api.VolumeSnapshotClass{ + snapClass: snapshotv1api.VolumeSnapshotClass{ ObjectMeta: metav1.ObjectMeta{ Name: "class-2", Annotations: map[string]string{ @@ -967,7 +967,7 @@ func TestIsVolumeSnapshotClassHasListerSecret(t *testing.T) { }, { name: "should not find expected annotation nil annotation", - snapClass: snapshotv1beta1api.VolumeSnapshotClass{ + snapClass: snapshotv1api.VolumeSnapshotClass{ ObjectMeta: metav1.ObjectMeta{ Name: "class-3", Annotations: nil, @@ -977,7 +977,7 @@ func TestIsVolumeSnapshotClassHasListerSecret(t *testing.T) { }, { name: "should not find expected annotation empty annotation", - snapClass: snapshotv1beta1api.VolumeSnapshotClass{ + snapClass: snapshotv1api.VolumeSnapshotClass{ ObjectMeta: metav1.ObjectMeta{ Name: "class-3", Annotations: map[string]string{}, @@ -998,12 +998,12 @@ func TestIsVolumeSnapshotClassHasListerSecret(t *testing.T) { func TestIsVolumeSnapshotContentHasDeleteSecret(t *testing.T) { testCases := []struct { name string - vsc snapshotv1beta1api.VolumeSnapshotContent + vsc snapshotv1api.VolumeSnapshotContent expected bool }{ { name: "should find both annotations", - vsc: snapshotv1beta1api.VolumeSnapshotContent{ + vsc: snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ Name: "vsc-1", Annotations: map[string]string{ @@ -1016,7 +1016,7 @@ func TestIsVolumeSnapshotContentHasDeleteSecret(t *testing.T) { }, { name: "should not find both annotations name is missing", - vsc: snapshotv1beta1api.VolumeSnapshotContent{ + vsc: snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ Name: "vsc-2", Annotations: map[string]string{ @@ -1029,7 +1029,7 @@ func TestIsVolumeSnapshotContentHasDeleteSecret(t *testing.T) { }, { name: "should not find both annotations namespace is missing", - vsc: snapshotv1beta1api.VolumeSnapshotContent{ + vsc: snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ Name: "vsc-3", Annotations: map[string]string{ @@ -1042,7 +1042,7 @@ func TestIsVolumeSnapshotContentHasDeleteSecret(t *testing.T) { }, { name: "should not find expected annotation non-empty annotation", - vsc: snapshotv1beta1api.VolumeSnapshotContent{ + vsc: snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ Name: "vsc-4", Annotations: map[string]string{ @@ -1055,7 +1055,7 @@ func TestIsVolumeSnapshotContentHasDeleteSecret(t *testing.T) { }, { name: "should not find expected annotation empty annotation", - vsc: snapshotv1beta1api.VolumeSnapshotContent{ + vsc: snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ Name: "vsc-5", Annotations: map[string]string{}, @@ -1065,7 +1065,7 @@ func TestIsVolumeSnapshotContentHasDeleteSecret(t *testing.T) { }, { name: "should not find expected annotation nil annotation", - vsc: snapshotv1beta1api.VolumeSnapshotContent{ + vsc: snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ Name: "vsc-6", Annotations: nil, @@ -1086,12 +1086,12 @@ func TestIsVolumeSnapshotContentHasDeleteSecret(t *testing.T) { func TestIsVolumeSnapshotHasVSCDeleteSecret(t *testing.T) { testCases := []struct { name string - vs snapshotv1beta1api.VolumeSnapshot + vs snapshotv1api.VolumeSnapshot expected bool }{ { name: "should find both annotations", - vs: snapshotv1beta1api.VolumeSnapshot{ + vs: snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "vs-1", Annotations: map[string]string{ @@ -1104,7 +1104,7 @@ func TestIsVolumeSnapshotHasVSCDeleteSecret(t *testing.T) { }, { name: "should not find both annotations name is missing", - vs: snapshotv1beta1api.VolumeSnapshot{ + vs: snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "vs-1", Annotations: map[string]string{ @@ -1117,7 +1117,7 @@ func TestIsVolumeSnapshotHasVSCDeleteSecret(t *testing.T) { }, { name: "should not find both annotations namespace is missing", - vs: snapshotv1beta1api.VolumeSnapshot{ + vs: snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "vs-1", Annotations: map[string]string{ @@ -1130,7 +1130,7 @@ func TestIsVolumeSnapshotHasVSCDeleteSecret(t *testing.T) { }, { name: "should not find annotation non-empty annotation", - vs: snapshotv1beta1api.VolumeSnapshot{ + vs: snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "vs-1", Annotations: map[string]string{ @@ -1143,7 +1143,7 @@ func TestIsVolumeSnapshotHasVSCDeleteSecret(t *testing.T) { }, { name: "should not find annotation empty annotation", - vs: snapshotv1beta1api.VolumeSnapshot{ + vs: snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "vs-1", Annotations: map[string]string{}, @@ -1153,7 +1153,7 @@ func TestIsVolumeSnapshotHasVSCDeleteSecret(t *testing.T) { }, { name: "should not find annotation nil annotation", - vs: snapshotv1beta1api.VolumeSnapshot{ + vs: snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "vs-1", Annotations: nil, @@ -1298,13 +1298,13 @@ func TestAddLabels(t *testing.T) { } func TestIsVolumeSnapshotExists(t *testing.T) { - vsExists := &snapshotv1beta1api.VolumeSnapshot{ + vsExists := &snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "vs-exists", Namespace: "default", }, } - vsNotExists := &snapshotv1beta1api.VolumeSnapshot{ + vsNotExists := &snapshotv1api.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: "vs-does-not-exists", Namespace: "default", @@ -1316,7 +1316,7 @@ func TestIsVolumeSnapshotExists(t *testing.T) { testCases := []struct { name string expected bool - vs *snapshotv1beta1api.VolumeSnapshot + vs *snapshotv1api.VolumeSnapshot }{ { name: "should find existing VolumeSnapshot object", @@ -1337,7 +1337,7 @@ func TestIsVolumeSnapshotExists(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - actual := IsVolumeSnapshotExists(tc.vs, fakeClient.SnapshotV1beta1()) + actual := IsVolumeSnapshotExists(tc.vs, fakeClient.SnapshotV1()) assert.Equal(t, tc.expected, actual) }) } @@ -1354,12 +1354,12 @@ func TestSetVolumeSnapshotContentDeletionPolicy(t *testing.T) { name: "should update DeletionPolicy of a VSC from retain to delete", inputVSCName: "retainVSC", objs: []runtime.Object{ - &snapshotv1beta1api.VolumeSnapshotContent{ + &snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ Name: "retainVSC", }, - Spec: snapshotv1beta1api.VolumeSnapshotContentSpec{ - DeletionPolicy: snapshotv1beta1api.VolumeSnapshotContentRetain, + Spec: snapshotv1api.VolumeSnapshotContentSpec{ + DeletionPolicy: snapshotv1api.VolumeSnapshotContentRetain, }, }, }, @@ -1369,12 +1369,12 @@ func TestSetVolumeSnapshotContentDeletionPolicy(t *testing.T) { name: "should be a no-op updating if DeletionPolicy of a VSC is already Delete", inputVSCName: "deleteVSC", objs: []runtime.Object{ - &snapshotv1beta1api.VolumeSnapshotContent{ + &snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ Name: "deleteVSC", }, - Spec: snapshotv1beta1api.VolumeSnapshotContentSpec{ - DeletionPolicy: snapshotv1beta1api.VolumeSnapshotContentDelete, + Spec: snapshotv1api.VolumeSnapshotContentSpec{ + DeletionPolicy: snapshotv1api.VolumeSnapshotContentDelete, }, }, }, @@ -1384,11 +1384,11 @@ func TestSetVolumeSnapshotContentDeletionPolicy(t *testing.T) { name: "should update DeletionPolicy of a VSC with no DeletionPolicy", inputVSCName: "nothingVSC", objs: []runtime.Object{ - &snapshotv1beta1api.VolumeSnapshotContent{ + &snapshotv1api.VolumeSnapshotContent{ ObjectMeta: metav1.ObjectMeta{ Name: "nothingVSC", }, - Spec: snapshotv1beta1api.VolumeSnapshotContentSpec{}, + Spec: snapshotv1api.VolumeSnapshotContentSpec{}, }, }, expectError: false, @@ -1404,14 +1404,14 @@ func TestSetVolumeSnapshotContentDeletionPolicy(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { fakeClient := snapshotFake.NewSimpleClientset(tc.objs...) - err := SetVolumeSnapshotContentDeletionPolicy(tc.inputVSCName, fakeClient.SnapshotV1beta1()) + err := SetVolumeSnapshotContentDeletionPolicy(tc.inputVSCName, fakeClient.SnapshotV1()) if tc.expectError { assert.NotNil(t, err) } else { assert.Nil(t, err) - actual, err := fakeClient.SnapshotV1beta1().VolumeSnapshotContents().Get(context.TODO(), tc.inputVSCName, metav1.GetOptions{}) + actual, err := fakeClient.SnapshotV1().VolumeSnapshotContents().Get(context.TODO(), tc.inputVSCName, metav1.GetOptions{}) assert.Nil(t, err) - assert.Equal(t, snapshotv1beta1api.VolumeSnapshotContentDelete, actual.Spec.DeletionPolicy) + assert.Equal(t, snapshotv1api.VolumeSnapshotContentDelete, actual.Spec.DeletionPolicy) } }) }