This repository has been archived by the owner on Jul 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
host.go
67 lines (58 loc) · 2.26 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
57
58
59
60
61
62
63
64
65
66
67
package diagnostics
import (
"fmt"
"k8s.io/apimachinery/pkg/util/sets"
hostdiags "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/host"
systemddiags "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/systemd"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
)
var (
// defaultSkipHostDiagnostics is a list of diagnostics to skip by default
defaultSkipHostDiagnostics = sets.NewString(
hostdiags.EtcdWriteName,
)
)
// availableHostDiagnostics returns host diagnostics that can be executed
// during a single run of diagnostics. Add more diagnostics to the list as they are defined.
func availableHostDiagnostics() types.DiagnosticList {
return types.DiagnosticList{
&systemddiags.AnalyzeLogs{},
&systemddiags.UnitStatus{},
&hostdiags.EtcdWriteVolume{},
}
}
// buildHostDiagnostics builds host Diagnostic objects based on the host environment.
// Returns the Diagnostics built, and an error if any was encountered during the building of diagnostics.
func (o DiagnosticsOptions) buildHostDiagnostics() ([]types.Diagnostic, error) {
requestedDiagnostics := availableHostDiagnostics().Names().Intersection(sets.NewString(o.RequestedDiagnostics.List()...)).List()
if len(requestedDiagnostics) == 0 { // no diagnostics to run here
return nil, 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, 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.EtcdWriteName:
etcd := o.ParameterizedDiagnostics[hostdiags.EtcdWriteName].(*hostdiags.EtcdWriteVolume)
etcd.MasterConfigLocation = o.MasterConfigLocation
d = etcd
default:
return diagnostics, fmt.Errorf("unknown diagnostic: %v", diagnosticName)
}
diagnostics = append(diagnostics, d)
}
return diagnostics, nil
}