From 07f30d06b9888e4d7563c620e74312a3fecd1380 Mon Sep 17 00:00:00 2001 From: Shubham Pampattiwar Date: Mon, 27 Oct 2025 12:04:46 -0700 Subject: [PATCH] Track actual resource names for GenerateName in restore status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When restoring resources with GenerateName, Kubernetes assigns the actual name after creation, but Velero only tracked the original name from the backup in itemKey. This caused volume information collection to fail when trying to fetch PVCs using the original name instead of the actual created name. Example: - Original PVC name from backup: "test-vm-disk-1" - Actual created PVC name: "test-vm-backup-2025-10-27-test-vm-disk-1-mdjkd" - Volume info tried to fetch: "test-vm-disk-1" → Failed with "not found" This affects any plugin or workflow using GenerateName during restore: - kubevirt-velero-plugin (VMFR use case with PVC collision avoidance) - Custom restore item actions using generateName - Secrets/ConfigMaps restored with generateName Changes: 1. Add createdName field to restoredItemStatus struct (pkg/restore/request.go) 2. Capture actual name from createdObj.GetName() (pkg/restore/restore.go:1520) 3. Use createdName in RestoredResourceList() when available (pkg/restore/request.go:93-95) This fix is backwards compatible: - createdName defaults to empty string - When empty, falls back to itemKey.name (original behavior) - Only populated for GenerateName resources where needed Fixes volume information collection errors like: "Failed to get PVC" error="persistentvolumeclaims \"\" not found" Signed-off-by: Shubham Pampattiwar --- pkg/restore/request.go | 15 +++++++++++---- pkg/restore/restore.go | 6 +++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pkg/restore/request.go b/pkg/restore/request.go index 452be4264..239d65df9 100644 --- a/pkg/restore/request.go +++ b/pkg/restore/request.go @@ -69,8 +69,9 @@ type Request struct { } type restoredItemStatus struct { - action string - itemExists bool + action string + itemExists bool + createdName string // Actual name assigned by K8s for GenerateName resources } // GetItemOperationsList returns ItemOperationsList, initializing it if necessary @@ -87,9 +88,15 @@ func (r *Request) GetItemOperationsList() *[]*itemoperation.RestoreOperation { func (r *Request) RestoredResourceList() map[string][]string { resources := map[string][]string{} for i, item := range r.RestoredItems { - entry := i.name + // Use createdName if available (GenerateName case), otherwise itemKey.name + name := i.name + if item.createdName != "" { + name = item.createdName + } + + entry := name if i.namespace != "" { - entry = fmt.Sprintf("%s/%s", i.namespace, i.name) + entry = fmt.Sprintf("%s/%s", i.namespace, name) } entry = fmt.Sprintf("%s(%s)", entry, item.action) resources[i.resource] = append(resources[i.resource], entry) diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index c8a9ab40a..52c947835 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -1514,7 +1514,11 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso createdObj, restoreErr = resourceClient.Create(obj) if restoreErr == nil { itemExists = true - ctx.restoredItems[itemKey] = restoredItemStatus{action: ItemRestoreResultCreated, itemExists: itemExists} + ctx.restoredItems[itemKey] = restoredItemStatus{ + action: ItemRestoreResultCreated, + itemExists: itemExists, + createdName: createdObj.GetName(), + } } }