Skip to content

Commit

Permalink
Merge pull request #148 from blackpiglet/release-0.4
Browse files Browse the repository at this point in the history
[cherry-pick][release-0.4]Honour restorePV flag in restore flow
  • Loading branch information
Lyndon-Li authored Feb 21, 2023
2 parents b3258d3 + c94c71f commit 9b32134
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions internal/restore/pvc_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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})
Expand Down
5 changes: 5 additions & 0 deletions internal/restore/volumesnapshot_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion internal/restore/volumesnapshotclass_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion internal/restore/volumesnapshotcontent_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
Expand Down

0 comments on commit 9b32134

Please sign in to comment.