From fd8c95baf811f4c3acb8a9cbd6674b05ee84fcaf Mon Sep 17 00:00:00 2001 From: lyndon-li <98304688+Lyndon-Li@users.noreply.github.com> Date: Mon, 21 Jul 2025 12:33:07 +0800 Subject: [PATCH] Issue 9053: remove selected-node annotation during PVC restore (#9076) issue 9053: remove selected-node annotation during PVC restore Signed-off-by: Lyndon-Li --- changelogs/unreleased/9076-Lyndon-Li | 1 + pkg/restore/actions/pvc_action.go | 13 ++------- pkg/restore/actions/pvc_action_test.go | 39 +++++++++----------------- 3 files changed, 16 insertions(+), 37 deletions(-) create mode 100644 changelogs/unreleased/9076-Lyndon-Li diff --git a/changelogs/unreleased/9076-Lyndon-Li b/changelogs/unreleased/9076-Lyndon-Li new file mode 100644 index 000000000..03ba8e2b5 --- /dev/null +++ b/changelogs/unreleased/9076-Lyndon-Li @@ -0,0 +1 @@ +Fix issue #9053, Always remove selected-node annotation during PVC restore when no node mapping exists. Breaking change: Previously, the annotation was preserved if the node existed. \ No newline at end of file diff --git a/pkg/restore/actions/pvc_action.go b/pkg/restore/actions/pvc_action.go index 2954e1823..fdc0c26ec 100644 --- a/pkg/restore/actions/pvc_action.go +++ b/pkg/restore/actions/pvc_action.go @@ -125,17 +125,8 @@ func (p *PVCAction) Execute(input *velero.RestoreItemActionExecuteInput) (*veler pvc.Annotations[AnnSelectedNode] = newNode log.Infof("Updating selected-node to %s from %s", newNode, node) } else { - // configMap doesn't have node-mapping - // Let's check if node exists or not - exists, err := isNodeExist(p.nodeClient, node) - if err != nil { - return nil, errors.Wrapf(err, "error checking node %s existence", node) - } - - if !exists { - log.Infof("Clearing selected-node because node named %s does not exist", node) - delete(pvc.Annotations, AnnSelectedNode) - } + log.Info("Clearing PVC selected-node annotation") + delete(pvc.Annotations, AnnSelectedNode) } } diff --git a/pkg/restore/actions/pvc_action_test.go b/pkg/restore/actions/pvc_action_test.go index 19b28952f..429196575 100644 --- a/pkg/restore/actions/pvc_action_test.go +++ b/pkg/restore/actions/pvc_action_test.go @@ -68,43 +68,29 @@ func TestPVCActionExecute(t *testing.T) { ).Result(), }, { - name: "when no config map exists for the plugin and node doesn't exist, the item is returned without node selector", + name: "when no config map exists for the plugin, the item is returned without node selector", pvc: builder.ForPersistentVolumeClaim("source-ns", "pvc-1"). ObjectMeta( builder.WithAnnotations("volume.kubernetes.io/selected-node", "source-node"), ).Result(), configMap: builder.ForConfigMap("velero", "change-pvc-node"). ObjectMeta(builder.WithLabels("velero.io/plugin-config", "", "velero.io/some-other-plugin", "RestoreItemAction")). - Data("source-noed", "dest-node"). + Data("source-node", "dest-node"). Result(), - want: builder.ForPersistentVolumeClaim("source-ns", "pvc-1").Result(), - }, - { - name: "when no node-mappings exist in the plugin config map and selected-node doesn't exist, the item is returned without node selector", - pvc: builder.ForPersistentVolumeClaim("source-ns", "pvc-1"). - ObjectMeta( - builder.WithAnnotations("volume.kubernetes.io/selected-node", "source-node"), - ).Result(), - configMap: builder.ForConfigMap("velero", "change-pvc-node"). - ObjectMeta(builder.WithLabels("velero.io/plugin-config", "", "velero.io/change-pvc-node-selector", "RestoreItemAction")). - Result(), - want: builder.ForPersistentVolumeClaim("source-ns", "pvc-1").Result(), - }, - { - name: "when no node-mappings exist in the plugin config map and selected-node exist, the item is returned as-is", - pvc: builder.ForPersistentVolumeClaim("source-ns", "pvc-1"). - ObjectMeta( - builder.WithAnnotations("volume.kubernetes.io/selected-node", "source-node"), - ).Result(), - configMap: builder.ForConfigMap("velero", "change-pvc-node"). - ObjectMeta(builder.WithLabels("velero.io/plugin-config", "", "velero.io/change-pvc-node-selector", "RestoreItemAction")). - Result(), - // MAYANK TODO node: builder.ForNode("source-node").Result(), - want: builder.ForPersistentVolumeClaim("source-ns", "pvc-1"). + want: builder.ForPersistentVolumeClaim("source-ns", "pvc-1").Result(), + }, + { + name: "when no node-mappings exist in the plugin config map, the item is returned without node selector", + pvc: builder.ForPersistentVolumeClaim("source-ns", "pvc-1"). ObjectMeta( builder.WithAnnotations("volume.kubernetes.io/selected-node", "source-node"), ).Result(), + configMap: builder.ForConfigMap("velero", "change-pvc-node"). + ObjectMeta(builder.WithLabels("velero.io/plugin-config", "", "velero.io/change-pvc-node-selector", "RestoreItemAction")). + Result(), + node: builder.ForNode("source-node").Result(), + want: builder.ForPersistentVolumeClaim("source-ns", "pvc-1").Result(), }, { name: "when persistent volume claim has no node selector, the item is returned as-is", @@ -125,6 +111,7 @@ func TestPVCActionExecute(t *testing.T) { ObjectMeta(builder.WithLabels("velero.io/plugin-config", "", "velero.io/change-pvc-node-selector", "RestoreItemAction")). Data("source-node-1", "dest-node"). Result(), + node: builder.ForNode("source-node").Result(), want: builder.ForPersistentVolumeClaim("source-ns", "pvc-1").Result(), }, }