Skip to content

Commit 07f30d0

Browse files
Track actual resource names for GenerateName in restore status
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 \"<original-name>\" not found" Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>
1 parent f4af615 commit 07f30d0

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

pkg/restore/request.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ type Request struct {
6969
}
7070

7171
type restoredItemStatus struct {
72-
action string
73-
itemExists bool
72+
action string
73+
itemExists bool
74+
createdName string // Actual name assigned by K8s for GenerateName resources
7475
}
7576

7677
// GetItemOperationsList returns ItemOperationsList, initializing it if necessary
@@ -87,9 +88,15 @@ func (r *Request) GetItemOperationsList() *[]*itemoperation.RestoreOperation {
8788
func (r *Request) RestoredResourceList() map[string][]string {
8889
resources := map[string][]string{}
8990
for i, item := range r.RestoredItems {
90-
entry := i.name
91+
// Use createdName if available (GenerateName case), otherwise itemKey.name
92+
name := i.name
93+
if item.createdName != "" {
94+
name = item.createdName
95+
}
96+
97+
entry := name
9198
if i.namespace != "" {
92-
entry = fmt.Sprintf("%s/%s", i.namespace, i.name)
99+
entry = fmt.Sprintf("%s/%s", i.namespace, name)
93100
}
94101
entry = fmt.Sprintf("%s(%s)", entry, item.action)
95102
resources[i.resource] = append(resources[i.resource], entry)

pkg/restore/restore.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,11 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
15141514
createdObj, restoreErr = resourceClient.Create(obj)
15151515
if restoreErr == nil {
15161516
itemExists = true
1517-
ctx.restoredItems[itemKey] = restoredItemStatus{action: ItemRestoreResultCreated, itemExists: itemExists}
1517+
ctx.restoredItems[itemKey] = restoredItemStatus{
1518+
action: ItemRestoreResultCreated,
1519+
itemExists: itemExists,
1520+
createdName: createdObj.GetName(),
1521+
}
15181522
}
15191523
}
15201524

0 commit comments

Comments
 (0)