forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_node_config.go
60 lines (51 loc) · 1.79 KB
/
check_node_config.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
package host
import (
"errors"
"fmt"
configapilatest "github.com/openshift/origin/pkg/cmd/server/api/latest"
configvalidation "github.com/openshift/origin/pkg/cmd/server/api/validation"
"github.com/openshift/origin/pkg/diagnostics/types"
)
// NodeConfigCheck is a Diagnostic to check that the node config file is valid
type NodeConfigCheck struct {
NodeConfigFile string
}
const NodeConfigCheckName = "NodeConfigCheck"
func (d NodeConfigCheck) Name() string {
return NodeConfigCheckName
}
func (d NodeConfigCheck) Description() string {
return "Check the node config file"
}
func (d NodeConfigCheck) CanRun() (bool, error) {
if len(d.NodeConfigFile) == 0 {
return false, errors.New("must have node config file")
}
return true, nil
}
func (d NodeConfigCheck) Check() types.DiagnosticResult {
r := types.NewDiagnosticResult(NodeConfigCheckName)
r.Debug("DH1001", fmt.Sprintf("Looking for node config file at '%s'", d.NodeConfigFile))
nodeConfig, err := configapilatest.ReadAndResolveNodeConfig(d.NodeConfigFile)
if err != nil {
r.Error("DH1002", err, fmt.Sprintf("Could not read node config file '%s':\n(%T) %[2]v", d.NodeConfigFile, err))
return r
}
r.Info("DH1003", fmt.Sprintf("Found a node config file: %[1]s", d.NodeConfigFile))
results := configvalidation.ValidateNodeConfig(nodeConfig, nil)
if len(results.Errors) > 0 {
errText := fmt.Sprintf("Validation of node config file '%s' failed:\n", d.NodeConfigFile)
for _, err := range results.Errors {
errText += fmt.Sprintf("%v\n", err)
}
r.Error("DH1004", nil, errText)
}
if len(results.Warnings) > 0 {
warnText := fmt.Sprintf("Validation of node config file '%s' warned:\n", d.NodeConfigFile)
for _, warn := range results.Warnings {
warnText += fmt.Sprintf("%v\n", warn)
}
r.Warn("DH1005", nil, warnText)
}
return r
}