Skip to content

Commit

Permalink
Keep the annotation "pv.kubernetes.io/provisioned-by" when restoring PVs
Browse files Browse the repository at this point in the history
More details please refer to #3470 (comment)

Fixes #3470

Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
  • Loading branch information
ywk253100 committed Nov 23, 2021
1 parent 48d1859 commit 5406258
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/4390-ywk253100
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Keep the annotation "pv.kubernetes.io/provisioned-by" when storing PVs
5 changes: 0 additions & 5 deletions pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import (
// Originals can be found in kubernetes/kubernetes/pkg/controller/volume/persistentvolume/util/util.go.
const KubeAnnBindCompleted = "pv.kubernetes.io/bind-completed"
const KubeAnnBoundByController = "pv.kubernetes.io/bound-by-controller"
const KubeAnnDynamicallyProvisioned = "pv.kubernetes.io/provisioned-by"

type VolumeSnapshotterGetter interface {
GetVolumeSnapshotter(name string) (velero.VolumeSnapshotter, error)
Expand Down Expand Up @@ -1576,10 +1575,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)

Expand Down
5 changes: 2 additions & 3 deletions pkg/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2989,15 +2989,15 @@ func Test_resetVolumeBindingInfo(t *testing.T) {
WithName("pv-1").WithAnnotations(
KubeAnnBindCompleted,
KubeAnnBoundByController,
KubeAnnDynamicallyProvisioned,
"pv.kubernetes.io/provisioned-by",
).WithSpecField("claimRef", map[string]interface{}{
"namespace": "ns-1",
"name": "pvc-1",
"uid": "abc",
"resourceVersion": "1"}).Unstructured,
expected: NewTestUnstructured().WithMetadataField("kind", "persistentVolume").
WithName("pv-1").
WithAnnotations().
WithAnnotations("pv.kubernetes.io/provisioned-by").
WithSpecField("claimRef", map[string]interface{}{
"namespace": "ns-1", "name": "pvc-1"}).Unstructured,
},
Expand All @@ -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().
Expand Down

0 comments on commit 5406258

Please sign in to comment.