Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log underlying error when YAML generation fails #100

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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