forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
39 lines (34 loc) · 1.48 KB
/
util.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
package host
import (
"fmt"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
configapilatest "github.com/openshift/origin/pkg/cmd/server/api/latest"
"github.com/openshift/origin/pkg/diagnostics/types"
)
// this would be bad practice if there were ever a need to load more than one master config for diagnostics.
// however we will proceed with the assumption that will never be necessary.
var (
masterConfigLoaded = false
masterConfig *configapi.MasterConfig
masterConfigLoadError error
)
func GetMasterConfig(r types.DiagnosticResult, masterConfigFile string) (*configapi.MasterConfig, error) {
if masterConfigLoaded { // no need to do this more than once
if masterConfigLoadError != nil {
printMasterConfigLoadError(r, masterConfigFile)
}
return masterConfig, masterConfigLoadError
}
r.Debug("DH0001", fmt.Sprintf("Looking for master config file at '%s'", masterConfigFile))
masterConfigLoaded = true
masterConfig, masterConfigLoadError = configapilatest.ReadAndResolveMasterConfig(masterConfigFile)
if masterConfigLoadError != nil {
printMasterConfigLoadError(r, masterConfigFile)
} else {
r.Debug("DH0003", fmt.Sprintf("Found a master config file: %[1]s", masterConfigFile))
}
return masterConfig, masterConfigLoadError
}
func printMasterConfigLoadError(r types.DiagnosticResult, masterConfigFile string) {
r.Error("DH0002", masterConfigLoadError, fmt.Sprintf("Could not read master config file '%s':\n(%T) %[2]v", masterConfigFile, masterConfigLoadError))
}