Skip to content

Commit

Permalink
Check for GVK before attempting restore.
Browse files Browse the repository at this point in the history
Signed-off-by: Tiger Kaovilai <[email protected]>

do not attempt restore resource with no available GVK in cluster

Signed-off-by: Tiger Kaovilai <[email protected]>
  • Loading branch information
kaovilai committed Jan 16, 2024
1 parent 2caba3e commit a7de73e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/7322-kaovilai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check resource Group Version and Kind is available in cluster before attempting restore to prevent being stuck.
16 changes: 16 additions & 0 deletions pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,22 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
}
}

// Check if cluster has GVK required to restore resource, otherwise return err.
// Placed here because the object apiVersion might get modified by a RestorePlugin
// So we check for the GVK after the RestorePlugin has run.
_, _, err = ctx.discoveryHelper.KindFor(schema.GroupVersionKind{
Group: groupResource.Group,
Version: obj.GetAPIVersion(),
Kind: groupResource.Resource,
})
clusterHasKind := err == nil
if !clusterHasKind {
ctx.log.Errorf("Cannot restore %s because GVK doesn't exist in the cluster", groupResource)
// Adding to errs should cause restore to partially fail
errs.Add(namespace, fmt.Errorf("cannot restore %s because gvk doesn't exist in the cluster", groupResource))
return warnings, errs, itemExists
}

// Necessary because we may have remapped the namespace if the namespace is
// blank, don't create the key.
originalNamespace := obj.GetNamespace()
Expand Down

0 comments on commit a7de73e

Please sign in to comment.