@@ -36,18 +36,21 @@ func generateUserAgent() string {
36
36
return fmt .Sprintf ("kubent (%s/%s)" , version , gitSha )
37
37
}
38
38
39
- func getCollectors (collectors []collector.Collector ) []map [string ]interface {} {
39
+ func getCollectors (collectors []collector.Collector , exitError bool ) ( []map [string ]interface {}, error ) {
40
40
var inputs []map [string ]interface {}
41
41
for _ , c := range collectors {
42
42
rs , err := c .Get ()
43
43
if err != nil {
44
44
log .Error ().Err (err ).Str ("name" , c .Name ()).Msg ("Failed to retrieve data from collector" )
45
+ if exitError {
46
+ return nil , err
47
+ }
45
48
} else {
46
49
inputs = append (inputs , rs ... )
47
50
log .Info ().Str ("name" , c .Name ()).Msgf ("Retrieved %d resources from collector" , len (rs ))
48
51
}
49
52
}
50
- return inputs
53
+ return inputs , nil
51
54
}
52
55
53
56
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
87
90
if err != nil {
88
91
return nil , fmt .Errorf ("failed to detect k8s version: %w" , err )
89
92
}
90
-
91
93
return version , nil
92
94
}
93
95
}
@@ -119,11 +121,17 @@ func main() {
119
121
initCollectors := initCollectors (config )
120
122
121
123
config .TargetVersion , err = getServerVersion (config .TargetVersion , initCollectors )
124
+ if config .ExitError && err != nil {
125
+ os .Exit (exitCode )
126
+ }
122
127
if config .TargetVersion != nil {
123
128
log .Info ().Msgf ("Target K8s version is %s" , config .TargetVersion .String ())
124
129
}
125
130
126
- collectors := getCollectors (initCollectors )
131
+ collectors , err := getCollectors (initCollectors , config .ExitError )
132
+ if config .ExitError && err != nil {
133
+ os .Exit (exitCode )
134
+ }
127
135
128
136
// this could probably use some error checking in future, but
129
137
// schema.ParseKindArg does not return any error
0 commit comments