diff --git a/cmd/kubent/main.go b/cmd/kubent/main.go index d9f93d79..d601f832 100644 --- a/cmd/kubent/main.go +++ b/cmd/kubent/main.go @@ -36,16 +36,19 @@ func generateUserAgent() string { return fmt.Sprintf("kubent (%s/%s)", version, gitSha) } -func getCollectors(collectors []collector.Collector) []map[string]interface{} { +func getCollectors(collectors []collector.Collector, exitIfError bool) []map[string]interface{} { var inputs []map[string]interface{} for _, c := range collectors { rs, err := c.Get() if err != nil { log.Error().Err(err).Str("name", c.Name()).Msg("Failed to retrieve data from collector") - } else { - inputs = append(inputs, rs...) - log.Info().Str("name", c.Name()).Msgf("Retrieved %d resources from collector", len(rs)) + if exitIfError { + os.Exit(EXIT_CODE_FAIL_GENERIC) + } + continue } + inputs = append(inputs, rs...) + log.Info().Str("name", c.Name()).Msgf("Retrieved %d resources from collector", len(rs)) } return inputs } @@ -123,7 +126,7 @@ func main() { log.Info().Msgf("Target K8s version is %s", config.TargetVersion.String()) } - collectors := getCollectors(initCollectors) + collectors := getCollectors(initCollectors, config.ExitError) // this could probably use some error checking in future, but // schema.ParseKindArg does not return any error diff --git a/cmd/kubent/main_test.go b/cmd/kubent/main_test.go index 80fc2195..c9549e7d 100644 --- a/cmd/kubent/main_test.go +++ b/cmd/kubent/main_test.go @@ -49,7 +49,7 @@ func TestGetCollectors(t *testing.T) { initCollectors := []collector.Collector{} initCollectors = append(initCollectors, fileCollector) - collectors := getCollectors(initCollectors) + collectors := getCollectors(initCollectors, false) if collectors != nil && len(collectors) != 1 { t.Errorf("Did not get file collector correctly with error: %s", err) diff --git a/pkg/collector/cluster.go b/pkg/collector/cluster.go index 6ce73904..9e371e4a 100644 --- a/pkg/collector/cluster.go +++ b/pkg/collector/cluster.go @@ -121,7 +121,7 @@ func (c *ClusterCollector) Get() ([]map[string]interface{}, error) { log.Debug().Msgf("Retrieving: %s.%s.%s", g.Resource, g.Version, g.Group) rs, err := ri.List(context.Background(), metav1.ListOptions{}) if err != nil { - log.Debug().Msgf("Failed to retrieve: %s: %s", g, err) + log.Warn().Msgf("Failed to retrieve: %s: %s", g, err) continue }