Skip to content

Commit

Permalink
Check whether the API resource exists before creating the informer cache
Browse files Browse the repository at this point in the history
Check whether the API resource exists before creating the informer cache

Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
  • Loading branch information
ywk253100 committed Jan 24, 2024
1 parent 3c379ed commit 97e2c66
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,11 @@ func (ctx *restoreContext) execute() (results.Result, results.Result) {
break
}
gvr := schema.ParseGroupResource(informerResource.resource).WithVersion(version)
_, _, err := ctx.discoveryHelper.ResourceFor(gvr)
if err != nil {
ctx.log.Infof("failed to create informer for %s", gvr)
continue
}
ctx.dynamicInformerFactory.factory.ForResource(gvr)
}
ctx.dynamicInformerFactory.factory.Start(ctx.dynamicInformerFactory.context.Done())
Expand Down Expand Up @@ -1018,11 +1023,7 @@ func (ctx *restoreContext) getResourceClient(groupResource schema.GroupResource,
}

func (ctx *restoreContext) getResourceLister(groupResource schema.GroupResource, obj *unstructured.Unstructured, namespace string) (cache.GenericNamespaceLister, error) {
_, _, err := ctx.discoveryHelper.KindFor(schema.GroupVersionKind{
Group: obj.GroupVersionKind().Group,
Version: obj.GetAPIVersion(),
Kind: obj.GetKind(),
})
_, _, err := ctx.discoveryHelper.KindFor(obj.GroupVersionKind())
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 97e2c66

Please sign in to comment.