mirror of
https://github.com/vmware-tanzu/velero.git
synced 2025-12-23 06:15:21 +00:00
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>
This commit is contained in:
@@ -69,8 +69,9 @@ type Request struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type restoredItemStatus struct {
|
type restoredItemStatus struct {
|
||||||
action string
|
action string
|
||||||
itemExists bool
|
itemExists bool
|
||||||
|
createdName string // Actual name assigned by K8s for GenerateName resources
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetItemOperationsList returns ItemOperationsList, initializing it if necessary
|
// GetItemOperationsList returns ItemOperationsList, initializing it if necessary
|
||||||
@@ -87,9 +88,15 @@ func (r *Request) GetItemOperationsList() *[]*itemoperation.RestoreOperation {
|
|||||||
func (r *Request) RestoredResourceList() map[string][]string {
|
func (r *Request) RestoredResourceList() map[string][]string {
|
||||||
resources := map[string][]string{}
|
resources := map[string][]string{}
|
||||||
for i, item := range r.RestoredItems {
|
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 != "" {
|
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)
|
entry = fmt.Sprintf("%s(%s)", entry, item.action)
|
||||||
resources[i.resource] = append(resources[i.resource], entry)
|
resources[i.resource] = append(resources[i.resource], entry)
|
||||||
|
|||||||
@@ -1514,7 +1514,11 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
|
|||||||
createdObj, restoreErr = resourceClient.Create(obj)
|
createdObj, restoreErr = resourceClient.Create(obj)
|
||||||
if restoreErr == nil {
|
if restoreErr == nil {
|
||||||
itemExists = true
|
itemExists = true
|
||||||
ctx.restoredItems[itemKey] = restoredItemStatus{action: ItemRestoreResultCreated, itemExists: itemExists}
|
ctx.restoredItems[itemKey] = restoredItemStatus{
|
||||||
|
action: ItemRestoreResultCreated,
|
||||||
|
itemExists: itemExists,
|
||||||
|
createdName: createdObj.GetName(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user