forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_master_config.go
55 lines (47 loc) · 1.46 KB
/
check_master_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
package host
import (
"errors"
"fmt"
configvalidation "github.com/openshift/origin/pkg/cmd/server/api/validation"
"github.com/openshift/origin/pkg/diagnostics/types"
)
// MasterConfigCheck is a Diagnostic to check that the master config file is valid
type MasterConfigCheck struct {
MasterConfigFile string
}
const MasterConfigCheckName = "MasterConfigCheck"
func (d MasterConfigCheck) Name() string {
return MasterConfigCheckName
}
func (d MasterConfigCheck) Description() string {
return "Check the master config file"
}
func (d MasterConfigCheck) CanRun() (bool, error) {
if len(d.MasterConfigFile) == 0 {
return false, errors.New("No master config file was detected")
}
return true, nil
}
func (d MasterConfigCheck) Check() types.DiagnosticResult {
r := types.NewDiagnosticResult(MasterConfigCheckName)
masterConfig, err := GetMasterConfig(r, d.MasterConfigFile)
if err != nil {
return r
}
results := configvalidation.ValidateMasterConfig(masterConfig, nil)
if len(results.Errors) > 0 {
errText := fmt.Sprintf("Validation of master config file '%s' failed:\n", d.MasterConfigFile)
for _, err := range results.Errors {
errText += fmt.Sprintf("%v\n", err)
}
r.Error("DH0004", nil, errText)
}
if len(results.Warnings) > 0 {
warnText := fmt.Sprintf("Validation of master config file '%s' warned:\n", d.MasterConfigFile)
for _, warn := range results.Warnings {
warnText += fmt.Sprintf("%v\n", warn)
}
r.Warn("DH0005", nil, warnText)
}
return r
}