mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-05 13:05:17 +00:00
Remove the WaitUntilVSCHandleIsReady from vs BIA.
Becasue the pvc BIA already run WaitUntilVSCHandleIsReady, no need to do the same work in vs BIA. Signed-off-by: Xun Jiang <xun.jiang@broadcom.com>
This commit is contained in:
@@ -731,3 +731,28 @@ func DiagnoseVSC(vsc *snapshotv1api.VolumeSnapshotContent) string {
|
||||
|
||||
return diag
|
||||
}
|
||||
|
||||
// GetVSCForVS returns the VolumeSnapshotContent object associated with the VolumeSnapshot.
|
||||
func GetVSCForVS(
|
||||
ctx context.Context,
|
||||
vs *snapshotv1api.VolumeSnapshot,
|
||||
client crclient.Client,
|
||||
) (*snapshotv1api.VolumeSnapshotContent, error) {
|
||||
if vs.Status == nil || vs.Status.BoundVolumeSnapshotContentName == nil {
|
||||
return nil, errors.Errorf("invalid snapshot info in volume snapshot %s", vs.Name)
|
||||
}
|
||||
|
||||
vsc := new(snapshotv1api.VolumeSnapshotContent)
|
||||
|
||||
if err := client.Get(
|
||||
ctx,
|
||||
crclient.ObjectKey{
|
||||
Name: *vs.Status.BoundVolumeSnapshotContentName,
|
||||
},
|
||||
vsc,
|
||||
); err != nil {
|
||||
return nil, errors.Wrap(err, "error getting volume snapshot content from API")
|
||||
}
|
||||
|
||||
return vsc, nil
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
|
||||
snapshotFake "github.com/kubernetes-csi/external-snapshotter/client/v8/clientset/versioned/fake"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -36,6 +38,7 @@ import (
|
||||
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
"github.com/vmware-tanzu/velero/pkg/builder"
|
||||
"github.com/vmware-tanzu/velero/pkg/test"
|
||||
velerotest "github.com/vmware-tanzu/velero/pkg/test"
|
||||
"github.com/vmware-tanzu/velero/pkg/util/boolptr"
|
||||
"github.com/vmware-tanzu/velero/pkg/util/logging"
|
||||
@@ -1881,3 +1884,57 @@ func TestDiagnoseVSC(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetVSCForVS(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
vs *snapshotv1api.VolumeSnapshot
|
||||
vsc *snapshotv1api.VolumeSnapshotContent
|
||||
expectedErr string
|
||||
expectedVSC *snapshotv1api.VolumeSnapshotContent
|
||||
}{
|
||||
{
|
||||
name: "vs has no status",
|
||||
vs: builder.ForVolumeSnapshot("ns1", "vs1").Result(),
|
||||
expectedErr: "invalid snapshot info in volume snapshot vs1",
|
||||
},
|
||||
{
|
||||
name: "vs has no bound vsc",
|
||||
vs: builder.ForVolumeSnapshot("ns1", "vs1").Status().Result(),
|
||||
expectedErr: "invalid snapshot info in volume snapshot vs1",
|
||||
},
|
||||
{
|
||||
name: "vs bound vsc cannot be found",
|
||||
vs: builder.ForVolumeSnapshot("ns1", "vs1").Status().BoundVolumeSnapshotContentName("vsc1").Result(),
|
||||
expectedErr: "error getting volume snapshot content from API: volumesnapshotcontents.snapshot.storage.k8s.io \"vsc1\" not found",
|
||||
},
|
||||
{
|
||||
name: "normal case",
|
||||
vs: builder.ForVolumeSnapshot("ns1", "vs1").Status().BoundVolumeSnapshotContentName("vsc1").Result(),
|
||||
vsc: builder.ForVolumeSnapshotContent("vsc1").Result(),
|
||||
expectedVSC: builder.ForVolumeSnapshotContent("vsc1").Result(),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
objs := []runtime.Object{tc.vs}
|
||||
if tc.vsc != nil {
|
||||
objs = append(objs, tc.vsc)
|
||||
}
|
||||
|
||||
client := test.NewFakeControllerRuntimeClient(t, objs...)
|
||||
vsc, err := GetVSCForVS(t.Context(), tc.vs, client)
|
||||
|
||||
if tc.expectedErr != "" {
|
||||
require.EqualError(t, err, tc.expectedErr)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
if tc.expectedVSC != nil {
|
||||
require.True(t, cmp.Equal(tc.expectedVSC, vsc, cmpopts.IgnoreFields(snapshotv1api.VolumeSnapshotContent{}, "ResourceVersion")))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user