-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
46 lines (41 loc) · 1.31 KB
/
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
package pluginconfig
import (
"io/ioutil"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
"github.com/openshift/origin/pkg/cmd/server/api/latest"
)
func GetPluginConfig(cfg configapi.AdmissionPluginConfig) (string, error) {
obj := cfg.Configuration
if obj == nil {
return cfg.Location, nil
}
configFile, err := ioutil.TempFile("", "admission-plugin-config")
if err != nil {
return "", err
}
if err = configFile.Close(); err != nil {
return "", err
}
content, err := latest.WriteYAML(obj)
if err != nil {
return "", err
}
if err = ioutil.WriteFile(configFile.Name(), content, 0644); err != nil {
return "", err
}
return configFile.Name(), nil
}
// GetPluginConfigFile translates from the master plugin config to a file name containing
// a particular plugin's config (the file may be a temp file if config is embedded)
func GetPluginConfigFile(pluginConfig map[string]configapi.AdmissionPluginConfig, pluginName string, defaultConfigFilePath string) (string, error) {
// Check whether a config is specified for this plugin. If not, default to the
// global plugin config file (if any).
if cfg, hasConfig := pluginConfig[pluginName]; hasConfig {
configFilePath, err := GetPluginConfig(cfg)
if err != nil {
return "", err
}
return configFilePath, nil
}
return defaultConfigFilePath, nil
}