diff --git a/pkg/admission/chain.go b/pkg/admission/chain.go index 696c1f23497..42f49b9c7c3 100644 --- a/pkg/admission/chain.go +++ b/pkg/admission/chain.go @@ -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 { diff --git a/pkg/admission/plugins.go b/pkg/admission/plugins.go index 6fecabd9f6c..d9f22ed85a3 100644 --- a/pkg/admission/plugins.go +++ b/pkg/admission/plugins.go @@ -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",