From 648f3ac2282d583bea473f3319767dd3a45df844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wenkai=20Yin=28=E5=B0=B9=E6=96=87=E5=BC=80=29?= Date: Tue, 23 Nov 2021 16:42:29 +0800 Subject: [PATCH] Keep the annotation "pv.kubernetes.io/provisioned-by" when restoring PVs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More details please refer to https://github.com/vmware-tanzu/velero/issues/3470#issuecomment-976279606 Fixes #3470 Signed-off-by: Wenkai Yin(尹文开) --- changelogs/unreleased/4391-ywk253100 | 1 + pkg/restore/restore.go | 4 ---- pkg/restore/restore_test.go | 3 +-- 3 files changed, 2 insertions(+), 6 deletions(-) create mode 100644 changelogs/unreleased/4391-ywk253100 diff --git a/changelogs/unreleased/4391-ywk253100 b/changelogs/unreleased/4391-ywk253100 new file mode 100644 index 000000000..99a1ae5fa --- /dev/null +++ b/changelogs/unreleased/4391-ywk253100 @@ -0,0 +1 @@ +Keep the annotation "pv.kubernetes.io/provisioned-by" when restoring PVs \ No newline at end of file diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 19e500269..09f5e662a 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -1562,10 +1562,6 @@ func resetVolumeBindingInfo(obj *unstructured.Unstructured) *unstructured.Unstru // the PV(C) controller to take the two objects and bind them again. delete(annotations, KubeAnnBoundByController) - // Remove the provisioned-by annotation which signals that the persistent - // volume was dynamically provisioned; it is now statically provisioned. - delete(annotations, KubeAnnDynamicallyProvisioned) - // GetAnnotations returns a copy, so we have to set them again. obj.SetAnnotations(annotations) diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index faada13f9..52c8e6986 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -2997,7 +2997,7 @@ func Test_resetVolumeBindingInfo(t *testing.T) { "resourceVersion": "1"}).Unstructured, expected: NewTestUnstructured().WithMetadataField("kind", "persistentVolume"). WithName("pv-1"). - WithAnnotations(). + WithAnnotations(KubeAnnDynamicallyProvisioned). WithSpecField("claimRef", map[string]interface{}{ "namespace": "ns-1", "name": "pvc-1"}).Unstructured, }, @@ -3007,7 +3007,6 @@ func Test_resetVolumeBindingInfo(t *testing.T) { WithName("pvc-1").WithAnnotations( KubeAnnBindCompleted, KubeAnnBoundByController, - KubeAnnDynamicallyProvisioned, ).WithSpecField("volumeName", "pv-1").Unstructured, expected: NewTestUnstructured().WithMetadataField("kind", "persistentVolumeClaim"). WithName("pvc-1").WithAnnotations().