Merge pull request #9124 from blackpiglet/remove_wait_vsc_for_vs_bia
Some checks failed
Run the E2E test on kind / build (push) Failing after 12m25s
Run the E2E test on kind / setup-test-matrix (push) Successful in 5s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / Build (push) Failing after 30s
Close stale issues and PRs / stale (push) Successful in 15s
Trivy Nightly Scan / Trivy nightly scan (velero, main) (push) Failing after 1m11s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-aws, main) (push) Failing after 54s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-gcp, main) (push) Failing after 56s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-microsoft-azure, main) (push) Failing after 53s

Remove the WaitUntilVSCHandleIsReady from vs BIA.
This commit is contained in:
Daniel Jiang
2025-07-31 19:59:46 +08:00
committed by GitHub
4 changed files with 86 additions and 6 deletions

View File

@@ -0,0 +1 @@
Remove the WaitUntilVSCHandleIsReady from vs BIA.

View File

@@ -108,12 +108,9 @@ func (p *volumeSnapshotBackupItemAction) Execute(
p.log.Infof("Getting VolumesnapshotContent for Volumesnapshot %s/%s",
vs.Namespace, vs.Name)
vsc, err := csi.WaitUntilVSCHandleIsReady(
vs,
p.crClient,
p.log,
backup.Spec.CSISnapshotTimeout.Duration,
)
ctx := context.TODO()
vsc, err := csi.GetVSCForVS(ctx, vs, p.crClient)
if err != nil {
csi.CleanupVolumeSnapshot(vs, p.crClient, p.log)
return nil, nil, "", nil, errors.WithStack(err)

View File

@@ -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
}

View File

@@ -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")))
}
})
}
}