forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.go
56 lines (48 loc) · 2.14 KB
/
host.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package diagnostics
import (
"fmt"
"k8s.io/kubernetes/pkg/util/sets"
hostdiags "github.com/openshift/origin/pkg/diagnostics/host"
systemddiags "github.com/openshift/origin/pkg/diagnostics/systemd"
"github.com/openshift/origin/pkg/diagnostics/types"
)
var (
// availableHostDiagnostics contains the names of host diagnostics that can be executed
// during a single run of diagnostics. Add more diagnostics to the list as they are defined.
availableHostDiagnostics = sets.NewString(systemddiags.AnalyzeLogsName, systemddiags.UnitStatusName, hostdiags.MasterConfigCheckName, hostdiags.NodeConfigCheckName)
)
// buildHostDiagnostics builds host Diagnostic objects based on the host environment.
// Returns the Diagnostics built, "ok" bool for whether to proceed or abort, and an error if any was encountered during the building of diagnostics.) {
func (o DiagnosticsOptions) buildHostDiagnostics() ([]types.Diagnostic, bool, error) {
requestedDiagnostics := availableHostDiagnostics.Intersection(sets.NewString(o.RequestedDiagnostics...)).List()
if len(requestedDiagnostics) == 0 { // no diagnostics to run here
return nil, true, nil // don't waste time on discovery
}
isHost := o.IsHost
if len(o.MasterConfigLocation) > 0 || len(o.NodeConfigLocation) > 0 {
isHost = true
}
// If we're not looking at a host, don't try the diagnostics
if !isHost {
return nil, true, nil
}
diagnostics := []types.Diagnostic{}
systemdUnits := systemddiags.GetSystemdUnits(o.Logger)
for _, diagnosticName := range requestedDiagnostics {
var d types.Diagnostic
switch diagnosticName {
case systemddiags.AnalyzeLogsName:
d = systemddiags.AnalyzeLogs{SystemdUnits: systemdUnits}
case systemddiags.UnitStatusName:
d = systemddiags.UnitStatus{SystemdUnits: systemdUnits}
case hostdiags.MasterConfigCheckName:
d = hostdiags.MasterConfigCheck{MasterConfigFile: o.MasterConfigLocation}
case hostdiags.NodeConfigCheckName:
d = hostdiags.NodeConfigCheck{NodeConfigFile: o.NodeConfigLocation}
default:
return diagnostics, false, fmt.Errorf("unknown diagnostic: %v", diagnosticName)
}
diagnostics = append(diagnostics, d)
}
return diagnostics, true, nil
}