forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_master_config.go
49 lines (39 loc) · 1.5 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
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"
)
// 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("must have master config file")
}
return true, nil
}
func (d MasterConfigCheck) Check() types.DiagnosticResult {
r := types.NewDiagnosticResult(MasterConfigCheckName)
r.Debug("DH0001", fmt.Sprintf("Looking for master config file at '%s'", d.MasterConfigFile))
masterConfig, err := configapilatest.ReadAndResolveMasterConfig(d.MasterConfigFile)
if err != nil {
r.Error("DH0002", err, fmt.Sprintf("Could not read master config file '%s':\n(%T) %[2]v", d.MasterConfigFile, err))
return r
}
r.Info("DH0003", fmt.Sprintf("Found a master config file: %[1]s", d.MasterConfigFile))
for _, err := range configvalidation.ValidateMasterConfig(masterConfig).Errors {
r.Error("DH0004", err, fmt.Sprintf("Validation of master config file '%s' failed:\n(%T) %[2]v", d.MasterConfigFile, err))
}
return r
}