diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 43833b2b35d..e0b2a2cded3 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -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) @@ -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 { @@ -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)