You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve the legibility of the code that builds and runs diagnostics.
The main confusion was the need to track and report the number of
diagnostic errors and warnings versus problems that halt execution
prematurely and the need to return a correct status code at completion.
In the end it seemed simplest to just have the logger report how many
diagnostic errors and warnings were seen, leaving function signatures to
return only build/run errors.
As a side effect, I looked at the ConfigLoading code that does an early
check to see if there is a client config, and concluded it was confusing
and unnecessary for it to be a diagnostic, so I refactored it away.
Main diagnostics as well as pod diagnostics are now implemented more uniformly.
// buildClientDiagnostics builds client Diagnostic objects based on the rawConfig passed in.
21
-
// Returns the Diagnostics built, "ok" bool for whether to proceed or abort, and an error if any was encountered during the building of diagnostics.) {
// buildClusterDiagnostics builds cluster Diagnostic objects if a cluster-admin client can be extracted from the rawConfig passed in.
46
-
// Returns the Diagnostics built, "ok" bool for whether to proceed or abort, and an error if any was encountered during the building of diagnostics.) {
o.Logger.Notice("CED1002", "Could not configure a client with cluster-admin permissions for the current server, so cluster diagnostics will be skipped")
o.Logger().Notice("CED1002", "Could not configure a client with cluster-admin permissions for the current server, so cluster diagnostics will be skipped")
func() { // don't trust discovery/build of diagnostics; wrap panic nicely in case of developer error
327
-
deferfunc() {
328
-
ifr:=recover(); r!=nil {
329
-
failed=true
330
-
stack:=debug.Stack()
331
-
errors=append(errors, fmt.Errorf("While building the diagnostics, a panic was encountered.\nThis is a bug in diagnostics. Error and stack trace follow: \n%v\n%s", r, stack))
332
-
}
333
-
}()
309
+
// RunDiagnostics builds diagnostics based on the options and executes them. Returns:
310
+
// error (raised during construction of diagnostics; may be an aggregate error object),
// build client/cluster diags if there is a client config for them to use
336
-
expected, detected, detectWarnings, detectErrors:=o.detectClientConfig() // may log and return problems
337
-
for_, warn:=rangedetectWarnings {
338
-
warnings=append(warnings, warn)
339
-
}
340
-
for_, err:=rangedetectErrors {
341
-
errors=append(errors, err)
342
-
}
343
-
if!expected {
344
-
// no diagnostic required a client config, nothing to do
345
-
} elseif!detected {
346
-
// there just plain isn't any client config file available
347
-
o.Logger.Notice("CED3014", "No client configuration specified; skipping client and cluster diagnostics.")
348
-
} elseifrawConfig, err:=o.buildRawConfig(); err!=nil { // client config is totally broken - won't parse etc (problems may have been detected and logged)
349
-
o.Logger.Error("CED3015", fmt.Sprintf("Client configuration failed to load; skipping client and cluster diagnostics due to error: %s", err.Error()))
// don't trust discovery/build of diagnostics; wrap panic nicely in case of developer error
323
+
deferfunc() {
324
+
ifr:=recover(); r!=nil {
325
+
failure=fmt.Errorf("While building the diagnostics, a panic was encountered.\nThis is a bug in diagnostics. Error and stack trace follow: \n%v\n%s", r, debug.Stack())
369
326
}
327
+
}()
370
328
371
-
// build host diagnostics if config is available
372
-
hostDiags, err:=o.buildHostDiagnostics()
329
+
// build client/cluster diags if there is a client config for them to use
330
+
expected, detected:=o.detectClientConfig() // may log and return problems
331
+
if!expected {
332
+
// no diagnostic required a client config, nothing to do
333
+
} elseif!detected {
334
+
// there just plain isn't any client config file available
335
+
o.Logger().Notice("CED3014", "No client configuration specified; skipping client and cluster diagnostics.")
336
+
} elseifrawConfig, err:=o.buildRawConfig(); err!=nil { // client config is totally broken - won't parse etc (problems may have been detected and logged)
337
+
o.Logger().Error("CED3015", fmt.Sprintf("Client configuration failed to load; skipping client and cluster diagnostics due to error: %s", err.Error()))
o.Logger.Error("CED3016", "Requested diagnostic(s) skipped; nothing to run. See --help and consider setting flags or providing config to enable running.")
func() { // don't trust discovery/build of diagnostics; wrap panic nicely in case of developer error
100
90
deferfunc() {
101
91
ifr:=recover(); r!=nil {
102
-
failed=true
103
-
stack:=debug.Stack()
104
-
errors=append(errors, fmt.Errorf("While building the diagnostics, a panic was encountered.\nThis is a bug in diagnostics. Error and stack trace follow: \n%v\n%s", r, stack))
92
+
fatal=fmt.Errorf("While building the diagnostics, a panic was encountered.\nThis is a bug in diagnostics. Error and stack trace follow: \n%v\n%s", r, debug.Stack())
func() { // don't trust discovery/build of diagnostics; wrap panic nicely in case of developer error
99
89
deferfunc() {
100
90
ifr:=recover(); r!=nil {
101
-
failed=true
102
-
stack:=debug.Stack()
103
-
errors=append(errors, fmt.Errorf("While building the diagnostics, a panic was encountered.\nThis is a bug in diagnostics. Error and stack trace follow: \n%v\n%s", r, stack))
91
+
fatal=fmt.Errorf("While building the diagnostics, a panic was encountered.\nThis is a bug in diagnostics. Error and stack trace follow: \n%v\n%s", r, debug.Stack())
0 commit comments