diff --git a/internal/restore/pvc_action.go b/internal/restore/pvc_action.go index 80b737f4..04f5c772 100644 --- a/internal/restore/pvc_action.go +++ b/internal/restore/pvc_action.go @@ -32,6 +32,7 @@ import ( "github.com/vmware-tanzu/velero-plugin-for-csi/internal/util" "github.com/vmware-tanzu/velero/pkg/plugin/velero" + "github.com/vmware-tanzu/velero/pkg/util/boolptr" ) const ( @@ -103,6 +104,10 @@ func (p *PVCRestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInp return nil, errors.WithStack(err) } p.Log.Infof("Starting PVCRestoreItemAction for PVC %s/%s", pvc.Namespace, pvc.Name) + if boolptr.IsSetToFalse(input.Restore.Spec.RestorePVs) { + p.Log.Infof("Restore did not request for PVs to be restored %s/%s", input.Restore.Namespace, input.Restore.Name) + return &velero.RestoreItemActionExecuteOutput{SkipRestore: true}, nil + } removePVCAnnotations(&pvc, []string{AnnBindCompleted, AnnBoundByController, AnnStorageProvisioner, AnnBetaStorageProvisioner, AnnSelectedNode}) diff --git a/internal/restore/volumesnapshot_action.go b/internal/restore/volumesnapshot_action.go index 88935726..ada1d05c 100644 --- a/internal/restore/volumesnapshot_action.go +++ b/internal/restore/volumesnapshot_action.go @@ -32,6 +32,7 @@ import ( velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/label" "github.com/vmware-tanzu/velero/pkg/plugin/velero" + "github.com/vmware-tanzu/velero/pkg/util/boolptr" ) // VolumeSnapshotRestoreItemAction is a Velero restore item action plugin for VolumeSnapshots @@ -62,6 +63,10 @@ func resetVolumeSnapshotAnnotation(vs *snapshotv1api.VolumeSnapshot) { // 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") + if boolptr.IsSetToFalse(input.Restore.Spec.RestorePVs) { + p.Log.Infof("Restore did not request for PVs to be restored %s/%s", input.Restore.Namespace, input.Restore.Name) + return &velero.RestoreItemActionExecuteOutput{SkipRestore: true}, nil + } var vs snapshotv1api.VolumeSnapshot if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), &vs); err != nil { diff --git a/internal/restore/volumesnapshotclass_action.go b/internal/restore/volumesnapshotclass_action.go index 6e9c3bc7..1ceacd6e 100644 --- a/internal/restore/volumesnapshotclass_action.go +++ b/internal/restore/volumesnapshotclass_action.go @@ -26,6 +26,7 @@ import ( "github.com/vmware-tanzu/velero-plugin-for-csi/internal/util" "github.com/vmware-tanzu/velero/pkg/plugin/velero" + "github.com/vmware-tanzu/velero/pkg/util/boolptr" ) // VolumeSnapshotClassRestoreItemAction is a Velero restore item action plugin for VolumeSnapshotClass @@ -44,7 +45,10 @@ func (p *VolumeSnapshotClassRestoreItemAction) AppliesTo() (velero.ResourceSelec // Execute restores volumesnapshotclass objects returning any snapshotlister secret as additional items to restore func (p *VolumeSnapshotClassRestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { p.Log.Info("Starting VolumeSnapshotClassRestoreItemAction") - + if boolptr.IsSetToFalse(input.Restore.Spec.RestorePVs) { + p.Log.Infof("Restore did not request for PVs to be restored %s/%s", input.Restore.Namespace, input.Restore.Name) + return &velero.RestoreItemActionExecuteOutput{SkipRestore: true}, nil + } var snapClass snapshotv1api.VolumeSnapshotClass if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), &snapClass); err != nil { diff --git a/internal/restore/volumesnapshotcontent_action.go b/internal/restore/volumesnapshotcontent_action.go index 3be6b722..b141aa8d 100644 --- a/internal/restore/volumesnapshotcontent_action.go +++ b/internal/restore/volumesnapshotcontent_action.go @@ -26,6 +26,7 @@ import ( "github.com/vmware-tanzu/velero-plugin-for-csi/internal/util" "github.com/vmware-tanzu/velero/pkg/plugin/velero" + "github.com/vmware-tanzu/velero/pkg/util/boolptr" ) // VolumeSnapshotContentRestoreItemAction is a restore item action plugin for Velero @@ -46,7 +47,10 @@ func (p *VolumeSnapshotContentRestoreItemAction) AppliesTo() (velero.ResourceSel func (p *VolumeSnapshotContentRestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { p.Log.Info("Starting VolumeSnapshotContentRestoreItemAction") var snapCont snapshotv1api.VolumeSnapshotContent - + if boolptr.IsSetToFalse(input.Restore.Spec.RestorePVs) { + p.Log.Infof("Restore did not request for PVs to be restored %s/%s", input.Restore.Namespace, input.Restore.Name) + return &velero.RestoreItemActionExecuteOutput{SkipRestore: true}, nil + } if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), &snapCont); err != nil { return &velero.RestoreItemActionExecuteOutput{}, errors.Wrapf(err, "failed to convert input.Item from unstructured") }