Skip to content

Commit

Permalink
do not attempt restore resource with no available GVK in cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
  • Loading branch information
kaovilai committed Jan 16, 2024
1 parent 2caba3e commit 6c4bb32
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,16 @@ func (ctx *restoreContext) getResourceClient(groupResource schema.GroupResource,

// if new informer is created, non-nil factory is returned
func (ctx *restoreContext) getGenericInformerInternal(groupResource schema.GroupResource, version, namespace string) (informers.GenericInformer, *informerFactoryWithContext) {
_, _, err := ctx.discoveryHelper.KindFor(schema.GroupVersionKind{
Group: groupResource.Group,
Version: version,
Kind: groupResource.Resource,
})
clusterHasKind := err == nil
if !clusterHasKind {
ctx.log.Errorf("Cannot get informer factory %s because GVK doesn't exist in the cluster", groupResource)
return nil, nil
}
var returnFactory *informerFactoryWithContext

key := getResourceClientKey(groupResource, version, namespace)
Expand Down Expand Up @@ -1097,6 +1107,9 @@ func (ctx *restoreContext) getGenericInformer(groupResource schema.GroupResource
}
func (ctx *restoreContext) getResourceLister(groupResource schema.GroupResource, obj *unstructured.Unstructured, namespace string) cache.GenericNamespaceLister {
informer := ctx.getGenericInformer(groupResource, obj.GroupVersionKind().Version, namespace)
if informer == nil {
return nil
}
if namespace == "" {
return informer.Lister()
} else {
Expand All @@ -1114,6 +1127,9 @@ func getResourceID(groupResource schema.GroupResource, namespace, name string) s

func (ctx *restoreContext) getResource(groupResource schema.GroupResource, obj *unstructured.Unstructured, namespace, name string) (*unstructured.Unstructured, error) {
lister := ctx.getResourceLister(groupResource, obj, namespace)
if lister == nil {
return nil, errors.Errorf("Error getting lister for %s because no informer for GVK found", getResourceID(groupResource, namespace, name))
}
clusterObj, err := lister.Get(name)
if err != nil {
return nil, errors.Wrapf(err, "error getting resource from lister for %s, %s/%s", groupResource, namespace, name)
Expand Down

0 comments on commit 6c4bb32

Please sign in to comment.