From 93db8a733cd5f2568ce0f18f0fb6229a0ce2d463 Mon Sep 17 00:00:00 2001 From: Eric Weber Date: Fri, 29 Mar 2024 12:00:58 -0500 Subject: [PATCH] Log underlying error when YAML generation fails support-bundle-kit 99 Signed-off-by: Eric Weber --- pkg/manager/client/discovery.go | 15 ++++++++++++--- pkg/manager/collectors/cluster.go | 4 +++- pkg/manager/collectors/default.go | 4 +++- pkg/manager/collectors/harvester.go | 7 +++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/pkg/manager/client/discovery.go b/pkg/manager/client/discovery.go index aa8c628fb..5f3c974cf 100644 --- a/pkg/manager/client/discovery.go +++ b/pkg/manager/client/discovery.go @@ -100,7 +100,10 @@ func (dc *DiscoveryClient) SpecificResourcesForNamespace(toObj ParseResult, modu if err == nil { obj, err := toObj(b, gv.String(), resource.Kind, resource.Name) if err != nil { - return nil, err + // This is unexpected. Log, but continue to try other resources. + logrus.Errorf("Failed to parse objects received from %s: %v", url, result.Error()) + fmt.Fprintf(errLog, "Failed to parse objects received from %s: %v\n", url, result.Error()) + continue } // skip empty object, which will cause useless zero item yaml file if obj != nil { @@ -167,7 +170,10 @@ func (dc *DiscoveryClient) ResourcesForNamespace(toObj ParseResult, namespace st if err == nil { obj, err := toObj(b, gv.String(), resource.Kind) if err != nil { - return nil, err + // This is unexpected. Log, but continue to try other resources. + logrus.Errorf("Failed to parse objects received from %s: %v", url, result.Error()) + fmt.Fprintf(errLog, "Failed to parse objects received from %s: %v\n", url, result.Error()) + continue } // skip empty object, which will cause useless zero item yaml file if obj != nil { @@ -229,7 +235,10 @@ func (dc *DiscoveryClient) ResourcesForCluster(toObj ParseResult, exclude Exclud if err == nil { obj, err := toObj(b, gv.String(), resource.Kind) if err != nil { - return nil, err + // This is unexpected. Log, but continue to try other resources. + logrus.Errorf("Failed to parse objects received from %s: %v", url, result.Error()) + fmt.Fprintf(errLog, "Failed to parse objects received from %s: %v\n", url, result.Error()) + continue } // skip empty object if obj != nil { diff --git a/pkg/manager/collectors/cluster.go b/pkg/manager/collectors/cluster.go index d92c67d31..4f51651c8 100644 --- a/pkg/manager/collectors/cluster.go +++ b/pkg/manager/collectors/cluster.go @@ -1,6 +1,7 @@ package collectors import ( + "fmt" "path/filepath" "github.com/sirupsen/logrus" @@ -26,7 +27,8 @@ func (module clusterModule) generateYAMLs() { objs, err := module.c.discovery.ResourcesForCluster(module.toObj, module.c.exclude, module.c.errorLog) if err != nil { - logrus.Errorf("Unable to fetch cluster resources: %v", err) + logrus.WithError(err).Error("Unable to fetch cluster resources") + fmt.Fprintf(module.c.errorLog, "Unable to fetch cluster resources: %v\n", err) return } diff --git a/pkg/manager/collectors/default.go b/pkg/manager/collectors/default.go index 7314ae9fa..d011d8b9a 100644 --- a/pkg/manager/collectors/default.go +++ b/pkg/manager/collectors/default.go @@ -1,6 +1,7 @@ package collectors import ( + "fmt" "io" "path/filepath" @@ -56,7 +57,8 @@ func (module defaultModule) generateDiscoveredNamespacedYAMLs(namespace string, objs, err := module.c.discovery.ResourcesForNamespace(module.toObj, namespace, module.c.exclude, errLog) if err != nil { - logrus.Errorf("Unable to fetch namespaced resources: %v", err) + logrus.WithError(err).Error("Unable to fetch namespaced resources") + fmt.Fprintf(module.c.errorLog, "Unable to fetch namespaced resources: %v\n", err) return } diff --git a/pkg/manager/collectors/harvester.go b/pkg/manager/collectors/harvester.go index f526e92dd..3fb525114 100644 --- a/pkg/manager/collectors/harvester.go +++ b/pkg/manager/collectors/harvester.go @@ -1,6 +1,7 @@ package collectors import ( + "fmt" "path/filepath" "github.com/Jeffail/gabs/v2" @@ -33,7 +34,8 @@ func (module harvesterModule) generateYAMLs() { objs, err := module.c.discovery.SpecificResourcesForNamespace(module.toObj, module.name, namespace, resourceLists, module.c.errorLog) if err != nil { - logrus.Errorf("Unable to fetch namespaced resources: %v", err) + logrus.WithError(err).Error("Unable to fetch namespaced resources") + fmt.Fprintf(module.c.errorLog, "Unable to fetch namespaced resources: %v\n", err) return } @@ -48,7 +50,8 @@ func (module harvesterModule) generateYAMLs() { objs, err := module.c.discovery.ResourcesForCluster(module.toClusterObj, module.skipClusterObjects, module.c.errorLog) if err != nil { - logrus.Errorf("Unable to fetch cluster scoped resources: %v", err) + logrus.WithError(err).Error("Unable to fetch cluster resources") + fmt.Fprintf(module.c.errorLog, "Unable to fetch cluster resources: %v\n", err) return }