Commit f583174d authored by k8s-merge-robot's avatar k8s-merge-robot

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
parents 86b8a09c c33d8bbe
...@@ -63,18 +63,19 @@ func RegisterPlugin(name string, plugin Factory) { ...@@ -63,18 +63,19 @@ func RegisterPlugin(name string, plugin Factory) {
plugins[name] = plugin plugins[name] = plugin
} }
// GetPlugin creates an instance of the named plugin, or nil if the name is not // getPlugin creates an instance of the named plugin. It returns `false` if the
// known. The error is returned only when the named provider was known but failed // the name is not known. The error is returned only when the named provider was
// to initialize. The config parameter specifies the io.Reader handler of the // known but failed to initialize. The config parameter specifies the io.Reader
// configuration file for the cloud provider, or nil for no configuration. // 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) { func getPlugin(name string, client clientset.Interface, config io.Reader) (Interface, bool, error) {
pluginsMutex.Lock() pluginsMutex.Lock()
defer pluginsMutex.Unlock() defer pluginsMutex.Unlock()
f, found := plugins[name] f, found := plugins[name]
if !found { 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. // InitPlugin creates an instance of the named interface.
...@@ -99,11 +100,11 @@ func InitPlugin(name string, client clientset.Interface, configFilePath string) ...@@ -99,11 +100,11 @@ func InitPlugin(name string, client clientset.Interface, configFilePath string)
defer config.Close() defer config.Close()
} }
plugin, err := GetPlugin(name, client, config) plugin, found, err := getPlugin(name, client, config)
if err != nil { if err != nil {
glog.Fatalf("Couldn't init admission plugin %q: %v", name, err) glog.Fatalf("Couldn't init admission plugin %q: %v", name, err)
} }
if plugin == nil { if !found {
glog.Fatalf("Unknown admission plugin: %s", name) glog.Fatalf("Unknown admission plugin: %s", name)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment