Allow plugins to have multiple handlers
Currently the plugins pkg allows a single handler. This assumption breaks down if there are mutiple listeners to a plugin of a certain Manifest such as NetworkDriver or IpamDriver when swarm-mode is enabled. Signed-off-by: Madhu Venugopal <madhu@docker.com> Upstream-commit: 5e9c78aeaf1d88000921190b88a1d91d6261208c Component: engine
This commit is contained in:
@ -43,7 +43,7 @@ type plugins struct {
|
||||
|
||||
var (
|
||||
storage = plugins{plugins: make(map[string]*Plugin)}
|
||||
extpointHandlers = make(map[string]func(string, *Client))
|
||||
extpointHandlers = make(map[string][]func(string, *Client))
|
||||
)
|
||||
|
||||
// Manifest lists what a plugin implements.
|
||||
@ -129,11 +129,13 @@ func (p *Plugin) activateWithLock() error {
|
||||
p.Manifest = m
|
||||
|
||||
for _, iface := range m.Implements {
|
||||
handler, handled := extpointHandlers[iface]
|
||||
handlers, handled := extpointHandlers[iface]
|
||||
if !handled {
|
||||
continue
|
||||
}
|
||||
handler(p.name, p.client)
|
||||
for _, handler := range handlers {
|
||||
handler(p.name, p.client)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -226,7 +228,16 @@ func Get(name, imp string) (*Plugin, error) {
|
||||
|
||||
// Handle adds the specified function to the extpointHandlers.
|
||||
func Handle(iface string, fn func(string, *Client)) {
|
||||
extpointHandlers[iface] = fn
|
||||
handlers, ok := extpointHandlers[iface]
|
||||
if !ok {
|
||||
handlers = []func(string, *Client){}
|
||||
}
|
||||
|
||||
handlers = append(handlers, fn)
|
||||
extpointHandlers[iface] = handlers
|
||||
for _, p := range storage.plugins {
|
||||
p.activated = false
|
||||
}
|
||||
}
|
||||
|
||||
// GetAll returns all the plugins for the specified implementation
|
||||
|
||||
Reference in New Issue
Block a user