Skip to content

Commit

Permalink
feat: Fix auth error, errors out properly closes #450 and increased l…
Browse files Browse the repository at this point in the history
…og level for silent resource failures

Signed-off-by: dark0dave <dark0dave@mykolab.com>
  • Loading branch information
dark0dave committed Sep 5, 2023
1 parent f6ebd85 commit a5f43d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions cmd/kubent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, exitError 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 exitError {
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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubent/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit a5f43d6

Please sign in to comment.