Skip to content

Commit

Permalink
Log underlying error when YAML generation fails
Browse files Browse the repository at this point in the history
support-bundle-kit 99

Signed-off-by: Eric Weber <eric.weber@suse.com>
  • Loading branch information
ejweber committed Jul 10, 2024
1 parent 366d823 commit 65bf721
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
15 changes: 12 additions & 3 deletions pkg/manager/client/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion pkg/manager/collectors/cluster.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package collectors

import (
"fmt"
"path/filepath"

"github.com/sirupsen/logrus"
Expand All @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/manager/collectors/default.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package collectors

import (
"fmt"
"io"
"path/filepath"

Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/manager/collectors/harvester.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package collectors

import (
"fmt"
"path/filepath"

"github.com/Jeffail/gabs/v2"
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 65bf721

Please sign in to comment.