Skip to content

Commit bde2771

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 bde2771

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

cmd/kubent/main.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,21 @@ 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, exitError bool) ([]map[string]interface{}, error) {
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+
if exitError {
46+
return nil, err
47+
}
4548
} else {
4649
inputs = append(inputs, rs...)
4750
log.Info().Str("name", c.Name()).Msgf("Retrieved %d resources from collector", len(rs))
4851
}
4952
}
50-
return inputs
53+
return inputs, nil
5154
}
5255

5356
func storeCollector(collector collector.Collector, err error, collectors []collector.Collector) []collector.Collector {
@@ -87,7 +90,6 @@ func getServerVersion(cv *judge.Version, collectors []collector.Collector) (*jud
8790
if err != nil {
8891
return nil, fmt.Errorf("failed to detect k8s version: %w", err)
8992
}
90-
9193
return version, nil
9294
}
9395
}
@@ -119,11 +121,17 @@ func main() {
119121
initCollectors := initCollectors(config)
120122

121123
config.TargetVersion, err = getServerVersion(config.TargetVersion, initCollectors)
124+
if config.ExitError && err != nil {
125+
os.Exit(exitCode)
126+
}
122127
if config.TargetVersion != nil {
123128
log.Info().Msgf("Target K8s version is %s", config.TargetVersion.String())
124129
}
125130

126-
collectors := getCollectors(initCollectors)
131+
collectors, err := getCollectors(initCollectors, config.ExitError)
132+
if config.ExitError && err != nil {
133+
os.Exit(exitCode)
134+
}
127135

128136
// this could probably use some error checking in future, but
129137
// 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)

0 commit comments

Comments
 (0)