From 53a2aa9c0d9268f4f56c8e4caf1b3ac8b9f2fa6e Mon Sep 17 00:00:00 2001 From: Emily McMullan Date: Mon, 17 Apr 2023 10:24:47 -0400 Subject: [PATCH] remove dataSource field in case of prior csi restore (#258) --- pkg/backup/backup_pv_action.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/backup/backup_pv_action.go b/pkg/backup/backup_pv_action.go index 6eb8b93095..23359f8bed 100644 --- a/pkg/backup/backup_pv_action.go +++ b/pkg/backup/backup_pv_action.go @@ -20,6 +20,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" corev1api "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" v1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" @@ -61,5 +62,19 @@ func (a *PVCAction) Execute(item runtime.Unstructured, backup *v1.Backup) (runti GroupResource: kuberesource.PersistentVolumes, Name: pvc.Spec.VolumeName, } - return item, []velero.ResourceIdentifier{pv}, nil + + // remove dataSource if exists from prior restored CSI volumes + if pvc.Spec.DataSource != nil { + pvc.Spec.DataSource = nil + } + if pvc.Spec.DataSourceRef != nil { + pvc.Spec.DataSourceRef = nil + } + + pvcMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&pvc) + if err != nil { + return nil, nil, errors.Wrap(err, "unable to convert pvc to unstructured item") + } + + return &unstructured.Unstructured{Object: pvcMap}, []velero.ResourceIdentifier{pv}, nil }