Skip to content

Commit b92a443

Browse files
committed
feat: Fix auth error, errors out properly closes #450 and increased log level for silent resource failures
Signed-off-by: dark0dave <[email protected]>
1 parent f6ebd85 commit b92a443

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

cmd/kubent/main.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,19 @@ func generateUserAgent() string {
3636
return fmt.Sprintf("kubent (%s/%s)", version, gitSha)
3737
}
3838

39-
func getCollectors(collectors []collector.Collector) []map[string]interface{} {
39+
func getCollectors(collectors []collector.Collector, exitIfError bool) []map[string]interface{} {
4040
var inputs []map[string]interface{}
4141
for _, c := range collectors {
4242
rs, err := c.Get()
4343
if err != nil {
4444
log.Error().Err(err).Str("name", c.Name()).Msg("Failed to retrieve data from collector")
45-
} else {
46-
inputs = append(inputs, rs...)
47-
log.Info().Str("name", c.Name()).Msgf("Retrieved %d resources from collector", len(rs))
45+
if exitIfError {
46+
os.Exit(EXIT_CODE_FAIL_GENERIC)
47+
}
48+
continue
4849
}
50+
inputs = append(inputs, rs...)
51+
log.Info().Str("name", c.Name()).Msgf("Retrieved %d resources from collector", len(rs))
4952
}
5053
return inputs
5154
}
@@ -123,7 +126,7 @@ func main() {
123126
log.Info().Msgf("Target K8s version is %s", config.TargetVersion.String())
124127
}
125128

126-
collectors := getCollectors(initCollectors)
129+
collectors := getCollectors(initCollectors, config.ExitError)
127130

128131
// this could probably use some error checking in future, but
129132
// schema.ParseKindArg does not return any error

cmd/kubent/main_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestGetCollectors(t *testing.T) {
4949
initCollectors := []collector.Collector{}
5050
initCollectors = append(initCollectors, fileCollector)
5151

52-
collectors := getCollectors(initCollectors)
52+
collectors := getCollectors(initCollectors, false)
5353

5454
if collectors != nil && len(collectors) != 1 {
5555
t.Errorf("Did not get file collector correctly with error: %s", err)

pkg/collector/cluster.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (c *ClusterCollector) Get() ([]map[string]interface{}, error) {
121121
log.Debug().Msgf("Retrieving: %s.%s.%s", g.Resource, g.Version, g.Group)
122122
rs, err := ri.List(context.Background(), metav1.ListOptions{})
123123
if err != nil {
124-
log.Debug().Msgf("Failed to retrieve: %s: %s", g, err)
124+
log.Warn().Msgf("Failed to retrieve: %s: %s", g, err)
125125
continue
126126
}
127127

0 commit comments

Comments
 (0)