From d5a2e7e6b9512e8ba52ec269ed5ce9a0fa23548c Mon Sep 17 00:00:00 2001 From: Xun Jiang/Bruce Jiang <59276555+blackpiglet@users.noreply.github.com> Date: Mon, 12 May 2025 16:08:45 +0800 Subject: [PATCH] Add VolumeSnapshotContent into the RIA and the mustHave resource list. (#8924) Signed-off-by: Xun Jiang --- changelogs/unreleased/8924-blackpiglet | 1 + pkg/restore/actions/csi/volumesnapshot_action.go | 16 +++++++++++++++- pkg/restore/restore.go | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/8924-blackpiglet diff --git a/changelogs/unreleased/8924-blackpiglet b/changelogs/unreleased/8924-blackpiglet new file mode 100644 index 000000000..bb60675e3 --- /dev/null +++ b/changelogs/unreleased/8924-blackpiglet @@ -0,0 +1 @@ +Add VolumeSnapshotContent into the RIA and the mustHave resource list. diff --git a/pkg/restore/actions/csi/volumesnapshot_action.go b/pkg/restore/actions/csi/volumesnapshot_action.go index d9a162d77..560ce33d7 100644 --- a/pkg/restore/actions/csi/volumesnapshot_action.go +++ b/pkg/restore/actions/csi/volumesnapshot_action.go @@ -17,6 +17,8 @@ limitations under the License. package csi import ( + "fmt" + snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -26,6 +28,7 @@ import ( velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/client" + "github.com/vmware-tanzu/velero/pkg/kuberesource" plugincommon "github.com/vmware-tanzu/velero/pkg/plugin/framework/common" "github.com/vmware-tanzu/velero/pkg/plugin/velero" "github.com/vmware-tanzu/velero/pkg/util" @@ -106,12 +109,23 @@ func (p *volumeSnapshotRestoreItemAction) Execute( return nil, errors.WithStack(err) } + if vsFromBackup.Status == nil || + vsFromBackup.Status.BoundVolumeSnapshotContentName == nil { + p.log.Errorf("VS %s doesn't have bound VSC", vsFromBackup.Name) + return nil, fmt.Errorf("VS %s doesn't have bound VSC", vsFromBackup.Name) + } + + vsc := velero.ResourceIdentifier{ + GroupResource: kuberesource.VolumeSnapshotContents, + Name: *vsFromBackup.Status.BoundVolumeSnapshotContentName, + } + p.log.Infof(`Returning from VolumeSnapshotRestoreItemAction with no additionalItems`) return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: &unstructured.Unstructured{Object: vsMap}, - AdditionalItems: []velero.ResourceIdentifier{}, + AdditionalItems: []velero.ResourceIdentifier{vsc}, }, nil } diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index bcadf4d4e..563c9741d 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -83,6 +83,7 @@ const ObjectStatusRestoreAnnotationKey = "velero.io/restore-status" var resourceMustHave = []string{ "datauploads.velero.io", + "volumesnapshotcontents.snapshot.storage.k8s.io", } type VolumeSnapshotterGetter interface {