admission: cleanup admission

pull/6/head
Xiang Li 2015-02-19 22:25:52 -08:00
parent 984fb2e675
commit 041c0a6f2b
2 changed files with 14 additions and 10 deletions

View File

@ -23,7 +23,8 @@ import (
// chainAdmissionHandler is an instance of admission.Interface that performs admission control using a chain of admission handlers
type chainAdmissionHandler []Interface
// New returns an admission.Interface that will enforce admission control decisions
// NewFromPlugins returns an admission.Interface that will enforce admission control decisions of all
// the given plugins.
func NewFromPlugins(client client.Interface, pluginNames []string, configFilePath string) Interface {
plugins := []Interface{}
for _, pluginName := range pluginNames {
@ -36,7 +37,7 @@ func NewFromPlugins(client client.Interface, pluginNames []string, configFilePat
}
// Admit performs an admission control check using a chain of handlers, and returns immediately on first error
func (admissionHandler chainAdmissionHandler) Admit(a Attributes) (err error) {
func (admissionHandler chainAdmissionHandler) Admit(a Attributes) error {
for _, handler := range admissionHandler {
err := handler.Admit(a)
if err != nil {

View File

@ -25,15 +25,17 @@ import (
"github.com/golang/glog"
)
// Factory is a function that returns a Interface for admission decisions.
// Factory is a function that returns an Interface for admission decisions.
// The config parameter provides an io.Reader handler to the factory in
// order to load specific configurations. If no configuration is provided
// the parameter is nil.
type Factory func(client client.Interface, config io.Reader) (Interface, error)
// All registered admission options.
var pluginsMutex sync.Mutex
var plugins = make(map[string]Factory)
var (
pluginsMutex sync.Mutex
plugins = make(map[string]Factory)
)
// GetPlugins enumerates the
func GetPlugins() []string {
@ -59,7 +61,7 @@ func RegisterPlugin(name string, plugin Factory) {
plugins[name] = plugin
}
// GetInterface creates an instance of the named plugin, or nil if
// GetPlugin creates an instance of the named plugin, or nil if
// the name is not known. The error return is only used if the named provider
// was known but failed to initialize. The config parameter specifies the
// io.Reader handler of the configuration file for the cloud provider, or nil
@ -74,9 +76,12 @@ func GetPlugin(name string, client client.Interface, config io.Reader) (Interfac
return f(client, config)
}
// InitPlugin creates an instance of the named interface
// InitPlugin creates an instance of the named interface.
func InitPlugin(name string, client client.Interface, configFilePath string) Interface {
var config *os.File
var (
config *os.File
err error
)
if name == "" {
glog.Info("No admission plugin specified.")
@ -84,8 +89,6 @@ func InitPlugin(name string, client client.Interface, configFilePath string) Int
}
if configFilePath != "" {
var err error
config, err = os.Open(configFilePath)
if err != nil {
glog.Fatalf("Couldn't open admission plugin configuration %s: %#v",