Merge pull request #24421 from deads2k/fix-admission

Automatic merge from submit-queue

let admission plugins indicate they want nothing

An admission plugin can return `nil, nil` for construction.  This is useful for dealing with cases where the `config` passed to you effectively means, "no work".  The calling code already handles this.

@derekwaynecarr
This commit is contained in:
k8s-merge-robot 2016-04-23 12:04:19 -07:00
commit f583174d76

View File

@ -63,18 +63,19 @@ func RegisterPlugin(name string, plugin Factory) {
plugins[name] = plugin
}
// GetPlugin creates an instance of the named plugin, or nil if the name is not
// known. The error is returned only when 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 for no configuration.
func GetPlugin(name string, client clientset.Interface, config io.Reader) (Interface, error) {
// getPlugin creates an instance of the named plugin. It returns `false` if the
// the name is not known. The error is returned only when 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 for no configuration.
func getPlugin(name string, client clientset.Interface, config io.Reader) (Interface, bool, error) {
pluginsMutex.Lock()
defer pluginsMutex.Unlock()
f, found := plugins[name]
if !found {
return nil, nil
return nil, false, nil
}
return f(client, config)
ret, err := f(client, config)
return ret, true, err
}
// InitPlugin creates an instance of the named interface.
@ -99,11 +100,11 @@ func InitPlugin(name string, client clientset.Interface, configFilePath string)
defer config.Close()
}
plugin, err := GetPlugin(name, client, config)
plugin, found, err := getPlugin(name, client, config)
if err != nil {
glog.Fatalf("Couldn't init admission plugin %q: %v", name, err)
}
if plugin == nil {
if !found {
glog.Fatalf("Unknown admission plugin: %s", name)
}