From 7295609bd6b9dc11642a9e543001ecd792ca7105 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: Mon, 22 Jan 2024 11:12:00 +0800 Subject: [PATCH] Log the error got from the discovery helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Log the error got from the discovery helper Signed-off-by: Wenkai Yin(尹文开) --- pkg/restore/restore.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 9949e48eab..1c85d88da4 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -1017,16 +1017,14 @@ func (ctx *restoreContext) getResourceClient(groupResource schema.GroupResource, return client, nil } -func (ctx *restoreContext) getResourceLister(groupResource schema.GroupResource, obj *unstructured.Unstructured, namespace string) cache.GenericNamespaceLister { +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(), }) - clusterHasKind := err == nil - if !clusterHasKind { - ctx.log.Errorf("Cannot get resource lister %s because GVK doesn't exist in the cluster", groupResource) - return nil + if err != nil { + return nil, err } informer := ctx.dynamicInformerFactory.factory.ForResource(groupResource.WithVersion(obj.GroupVersionKind().Version)) // if the restore contains CRDs or the RIA returns new resources, need to make sure the corresponding informers are synced @@ -1037,10 +1035,9 @@ func (ctx *restoreContext) getResourceLister(groupResource schema.GroupResource, } if namespace == "" { - return informer.Lister() - } else { - return informer.Lister().ByNamespace(namespace) + return informer.Lister(), nil } + return informer.Lister().ByNamespace(namespace), nil } func getResourceID(groupResource schema.GroupResource, namespace, name string) string { @@ -1052,10 +1049,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 { - // getResourceLister logs the error, this func returns error to the caller to trigger partiallyFailed. - return nil, errors.Errorf("Error getting lister for %s because no informer for GVK found", getResourceID(groupResource, namespace, name)) + lister, err := ctx.getResourceLister(groupResource, obj, namespace) + if err != nil { + return nil, errors.Wrapf(err, "Error getting lister for %s", getResourceID(groupResource, namespace, name)) } clusterObj, err := lister.Get(name) if err != nil {