From ad164fa893ab725e1866aee85f697dbcc1605fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wenkai=20Yin=28=E5=B0=B9=E6=96=87=E5=BC=80=29?= Date: Tue, 23 Jan 2024 17:04:04 +0800 Subject: [PATCH] Check whether the API resource exists before creating the informer cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check whether the API resource exists before creating the informer cache Signed-off-by: Wenkai Yin(尹文开) --- pkg/restore/restore.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 796bb48cb0..f19e4c7f6e 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -593,6 +593,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()) @@ -1059,11 +1064,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 }