Signed-off-by: Anusha Ragunathan <anusha@docker.com>
| ... | ... |
@@ -262,10 +262,6 @@ func (cli *DaemonCli) start() (err error) {
|
| 262 | 262 |
<-stopc // wait for daemonCli.start() to return |
| 263 | 263 |
}) |
| 264 | 264 |
|
| 265 |
- if err := pluginInit(cli.Config, containerdRemote, registryService); err != nil {
|
|
| 266 |
- return err |
|
| 267 |
- } |
|
| 268 |
- |
|
| 269 | 265 |
d, err := daemon.NewDaemon(cli.Config, registryService, containerdRemote) |
| 270 | 266 |
if err != nil {
|
| 271 | 267 |
return fmt.Errorf("Error starting daemon: %v", err)
|
| 272 | 268 |
deleted file mode 100644 |
| ... | ... |
@@ -1,13 +0,0 @@ |
| 1 |
-// +build !experimental !linux |
|
| 2 |
- |
|
| 3 |
-package main |
|
| 4 |
- |
|
| 5 |
-import ( |
|
| 6 |
- "github.com/docker/docker/daemon" |
|
| 7 |
- "github.com/docker/docker/libcontainerd" |
|
| 8 |
- "github.com/docker/docker/registry" |
|
| 9 |
-) |
|
| 10 |
- |
|
| 11 |
-func pluginInit(config *daemon.Config, remote libcontainerd.Remote, rs registry.Service) error {
|
|
| 12 |
- return nil |
|
| 13 |
-} |
| 14 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,14 +0,0 @@ |
| 1 |
-// +build linux,experimental |
|
| 2 |
- |
|
| 3 |
-package main |
|
| 4 |
- |
|
| 5 |
-import ( |
|
| 6 |
- "github.com/docker/docker/daemon" |
|
| 7 |
- "github.com/docker/docker/libcontainerd" |
|
| 8 |
- "github.com/docker/docker/plugin" |
|
| 9 |
- "github.com/docker/docker/registry" |
|
| 10 |
-) |
|
| 11 |
- |
|
| 12 |
-func pluginInit(config *daemon.Config, remote libcontainerd.Remote, rs registry.Service) error {
|
|
| 13 |
- return plugin.Init(config.Root, remote, rs, config.LiveRestore) |
|
| 14 |
-} |
| ... | ... |
@@ -3,6 +3,7 @@ |
| 3 | 3 |
package daemon |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
+ "github.com/docker/docker/libcontainerd" |
|
| 6 | 7 |
"github.com/docker/docker/plugin" |
| 7 | 8 |
"github.com/docker/engine-api/types/container" |
| 8 | 9 |
) |
| ... | ... |
@@ -11,6 +12,15 @@ func (daemon *Daemon) verifyExperimentalContainerSettings(hostConfig *container. |
| 11 | 11 |
return nil, nil |
| 12 | 12 |
} |
| 13 | 13 |
|
| 14 |
+func pluginInit(d *Daemon, cfg *Config, remote libcontainerd.Remote) error {
|
|
| 15 |
+ return plugin.Init(cfg.Root, remote, d.RegistryService, cfg.LiveRestore, d.LogPluginEvent) |
|
| 16 |
+} |
|
| 17 |
+ |
|
| 14 | 18 |
func pluginShutdown() {
|
| 15 |
- plugin.GetManager().Shutdown() |
|
| 19 |
+ manager := plugin.GetManager() |
|
| 20 |
+ // Check for a valid manager object. In error conditions, daemon init can fail |
|
| 21 |
+ // and shutdown called, before plugin manager is initialized. |
|
| 22 |
+ if manager != nil {
|
|
| 23 |
+ manager.Shutdown() |
|
| 24 |
+ } |
|
| 16 | 25 |
} |
| ... | ... |
@@ -2,11 +2,18 @@ |
| 2 | 2 |
|
| 3 | 3 |
package daemon |
| 4 | 4 |
|
| 5 |
-import "github.com/docker/engine-api/types/container" |
|
| 5 |
+import ( |
|
| 6 |
+ "github.com/docker/docker/libcontainerd" |
|
| 7 |
+ "github.com/docker/engine-api/types/container" |
|
| 8 |
+) |
|
| 6 | 9 |
|
| 7 | 10 |
func (daemon *Daemon) verifyExperimentalContainerSettings(hostConfig *container.HostConfig, config *container.Config) ([]string, error) {
|
| 8 | 11 |
return nil, nil |
| 9 | 12 |
} |
| 10 | 13 |
|
| 14 |
+func pluginInit(d *Daemon, config *Config, remote libcontainerd.Remote) error {
|
|
| 15 |
+ return nil |
|
| 16 |
+} |
|
| 17 |
+ |
|
| 11 | 18 |
func pluginShutdown() {
|
| 12 | 19 |
} |
| ... | ... |
@@ -55,6 +55,21 @@ func (daemon *Daemon) LogImageEventWithAttributes(imageID, refName, action strin |
| 55 | 55 |
daemon.EventsService.Log(action, events.ImageEventType, actor) |
| 56 | 56 |
} |
| 57 | 57 |
|
| 58 |
+// LogPluginEvent generates an event related to a plugin with only the default attributes. |
|
| 59 |
+func (daemon *Daemon) LogPluginEvent(pluginID, refName, action string) {
|
|
| 60 |
+ daemon.LogPluginEventWithAttributes(pluginID, refName, action, map[string]string{})
|
|
| 61 |
+} |
|
| 62 |
+ |
|
| 63 |
+// LogPluginEventWithAttributes generates an event related to a plugin with specific given attributes. |
|
| 64 |
+func (daemon *Daemon) LogPluginEventWithAttributes(pluginID, refName, action string, attributes map[string]string) {
|
|
| 65 |
+ attributes["name"] = refName |
|
| 66 |
+ actor := events.Actor{
|
|
| 67 |
+ ID: pluginID, |
|
| 68 |
+ Attributes: attributes, |
|
| 69 |
+ } |
|
| 70 |
+ daemon.EventsService.Log(action, events.PluginEventType, actor) |
|
| 71 |
+} |
|
| 72 |
+ |
|
| 58 | 73 |
// LogVolumeEvent generates an event related to a volume. |
| 59 | 74 |
func (daemon *Daemon) LogVolumeEvent(volumeID, action string, attributes map[string]string) {
|
| 60 | 75 |
actor := events.Actor{
|
| ... | ... |
@@ -22,6 +22,7 @@ func (ef *Filter) Include(ev events.Message) bool {
|
| 22 | 22 |
ef.filter.ExactMatch("type", ev.Type) &&
|
| 23 | 23 |
ef.matchDaemon(ev) && |
| 24 | 24 |
ef.matchContainer(ev) && |
| 25 |
+ ef.matchPlugin(ev) && |
|
| 25 | 26 |
ef.matchVolume(ev) && |
| 26 | 27 |
ef.matchNetwork(ev) && |
| 27 | 28 |
ef.matchImage(ev) && |
| ... | ... |
@@ -43,6 +44,10 @@ func (ef *Filter) matchContainer(ev events.Message) bool {
|
| 43 | 43 |
return ef.fuzzyMatchName(ev, events.ContainerEventType) |
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 |
+func (ef *Filter) matchPlugin(ev events.Message) bool {
|
|
| 47 |
+ return ef.fuzzyMatchName(ev, events.PluginEventType) |
|
| 48 |
+} |
|
| 49 |
+ |
|
| 46 | 50 |
func (ef *Filter) matchVolume(ev events.Message) bool {
|
| 47 | 51 |
return ef.fuzzyMatchName(ev, events.VolumeEventType) |
| 48 | 52 |
} |
| ... | ... |
@@ -30,6 +30,10 @@ Docker images report the following events: |
| 30 | 30 |
|
| 31 | 31 |
delete, import, load, pull, push, save, tag, untag |
| 32 | 32 |
|
| 33 |
+Docker plugins(experimental) report the following events: |
|
| 34 |
+ |
|
| 35 |
+ install, enable, disable, remove |
|
| 36 |
+ |
|
| 33 | 37 |
Docker volumes report the following events: |
| 34 | 38 |
|
| 35 | 39 |
create, mount, unmount, destroy |
| ... | ... |
@@ -74,6 +78,7 @@ The currently supported filters are: |
| 74 | 74 |
* container (`container=<name or id>`) |
| 75 | 75 |
* event (`event=<event action>`) |
| 76 | 76 |
* image (`image=<tag or id>`) |
| 77 |
+* plugin (experimental) (`plugin=<name or id>`) |
|
| 77 | 78 |
* label (`label=<key>` or `label=<key>=<value>`) |
| 78 | 79 |
* type (`type=<container or image or volume or network or daemon>`) |
| 79 | 80 |
* volume (`volume=<name or id>`) |
| ... | ... |
@@ -171,3 +176,7 @@ relative to the current time on the client machine: |
| 171 | 171 |
$ docker events --filter 'type=network' |
| 172 | 172 |
2015-12-23T21:38:24.705709133Z network create 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (name=test-event-network-local, type=bridge) |
| 173 | 173 |
2015-12-23T21:38:25.119625123Z network connect 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (name=test-event-network-local, container=b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e, type=bridge) |
| 174 |
+ |
|
| 175 |
+ $ docker events --filter 'type=plugin' (experimental) |
|
| 176 |
+ 2016-07-25T17:30:14.825557616Z plugin pull ec7b87f2ce84330fe076e666f17dfc049d2d7ae0b8190763de94e1f2d105993f (name=tiborvass/no-remove:latest) |
|
| 177 |
+ 2016-07-25T17:30:14.888127370Z plugin enable ec7b87f2ce84330fe076e666f17dfc049d2d7ae0b8190763de94e1f2d105993f (name=tiborvass/no-remove:latest) |
| ... | ... |
@@ -297,6 +297,32 @@ func (s *DockerSuite) TestEventsImageLoad(c *check.C) {
|
| 297 | 297 |
c.Assert(matches["action"], checker.Equals, "save", check.Commentf("matches: %v\nout:\n%s\n", matches, out))
|
| 298 | 298 |
} |
| 299 | 299 |
|
| 300 |
+func (s *DockerSuite) TestEventsPluginOps(c *check.C) {
|
|
| 301 |
+ testRequires(c, DaemonIsLinux, ExperimentalDaemon) |
|
| 302 |
+ |
|
| 303 |
+ pluginName := "tiborvass/no-remove:latest" |
|
| 304 |
+ since := daemonUnixTime(c) |
|
| 305 |
+ |
|
| 306 |
+ dockerCmd(c, "plugin", "install", pluginName, "--grant-all-permissions") |
|
| 307 |
+ dockerCmd(c, "plugin", "disable", pluginName) |
|
| 308 |
+ dockerCmd(c, "plugin", "remove", pluginName) |
|
| 309 |
+ |
|
| 310 |
+ out, _ := dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c)) |
|
| 311 |
+ events := strings.Split(out, "\n") |
|
| 312 |
+ events = events[:len(events)-1] |
|
| 313 |
+ |
|
| 314 |
+ nEvents := len(events) |
|
| 315 |
+ c.Assert(nEvents, checker.GreaterOrEqualThan, 4) |
|
| 316 |
+ |
|
| 317 |
+ pluginEvents := eventActionsByIDAndType(c, events, pluginName, "plugin") |
|
| 318 |
+ c.Assert(pluginEvents, checker.HasLen, 4, check.Commentf("events: %v", events))
|
|
| 319 |
+ |
|
| 320 |
+ c.Assert(pluginEvents[0], checker.Equals, "pull", check.Commentf(out)) |
|
| 321 |
+ c.Assert(pluginEvents[1], checker.Equals, "enable", check.Commentf(out)) |
|
| 322 |
+ c.Assert(pluginEvents[2], checker.Equals, "disable", check.Commentf(out)) |
|
| 323 |
+ c.Assert(pluginEvents[3], checker.Equals, "remove", check.Commentf(out)) |
|
| 324 |
+} |
|
| 325 |
+ |
|
| 300 | 326 |
func (s *DockerSuite) TestEventsFilters(c *check.C) {
|
| 301 | 327 |
since := daemonUnixTime(c) |
| 302 | 328 |
dockerCmd(c, "run", "--rm", "busybox", "true") |
| ... | ... |
@@ -22,7 +22,11 @@ func (pm *Manager) Disable(name string) error {
|
| 22 | 22 |
if err != nil {
|
| 23 | 23 |
return err |
| 24 | 24 |
} |
| 25 |
- return pm.disable(p) |
|
| 25 |
+ if err := pm.disable(p); err != nil {
|
|
| 26 |
+ return err |
|
| 27 |
+ } |
|
| 28 |
+ pm.pluginEventLogger(p.PluginObj.ID, name, "disable") |
|
| 29 |
+ return nil |
|
| 26 | 30 |
} |
| 27 | 31 |
|
| 28 | 32 |
// Enable activates a plugin, which implies that they are ready to be used by containers. |
| ... | ... |
@@ -31,7 +35,11 @@ func (pm *Manager) Enable(name string) error {
|
| 31 | 31 |
if err != nil {
|
| 32 | 32 |
return err |
| 33 | 33 |
} |
| 34 |
- return pm.enable(p) |
|
| 34 |
+ if err := pm.enable(p); err != nil {
|
|
| 35 |
+ return err |
|
| 36 |
+ } |
|
| 37 |
+ pm.pluginEventLogger(p.PluginObj.ID, name, "enable") |
|
| 38 |
+ return nil |
|
| 35 | 39 |
} |
| 36 | 40 |
|
| 37 | 41 |
// Inspect examines a plugin manifest |
| ... | ... |
@@ -40,10 +48,10 @@ func (pm *Manager) Inspect(name string) (tp types.Plugin, err error) {
|
| 40 | 40 |
if err != nil {
|
| 41 | 41 |
return tp, err |
| 42 | 42 |
} |
| 43 |
- return p.P, nil |
|
| 43 |
+ return p.PluginObj, nil |
|
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 |
-// Pull pulls a plugin and enables it. |
|
| 46 |
+// Pull pulls a plugin and computes the privileges required to install it. |
|
| 47 | 47 |
func (pm *Manager) Pull(name string, metaHeader http.Header, authConfig *types.AuthConfig) (types.PluginPrivileges, error) {
|
| 48 | 48 |
ref, err := reference.ParseNamed(name) |
| 49 | 49 |
if err != nil {
|
| ... | ... |
@@ -86,14 +94,15 @@ func (pm *Manager) Pull(name string, metaHeader http.Header, authConfig *types.A |
| 86 | 86 |
pm.save() |
| 87 | 87 |
pm.Unlock() |
| 88 | 88 |
|
| 89 |
- return computePrivileges(&p.P.Manifest), nil |
|
| 89 |
+ pm.pluginEventLogger(pluginID, name, "pull") |
|
| 90 |
+ return computePrivileges(&p.PluginObj.Manifest), nil |
|
| 90 | 91 |
} |
| 91 | 92 |
|
| 92 | 93 |
// List displays the list of plugins and associated metadata. |
| 93 | 94 |
func (pm *Manager) List() ([]types.Plugin, error) {
|
| 94 | 95 |
out := make([]types.Plugin, 0, len(pm.plugins)) |
| 95 | 96 |
for _, p := range pm.plugins {
|
| 96 |
- out = append(out, p.P) |
|
| 97 |
+ out = append(out, p.PluginObj) |
|
| 97 | 98 |
} |
| 98 | 99 |
return out, nil |
| 99 | 100 |
} |
| ... | ... |
@@ -104,7 +113,7 @@ func (pm *Manager) Push(name string, metaHeader http.Header, authConfig *types.A |
| 104 | 104 |
if err != nil {
|
| 105 | 105 |
return err |
| 106 | 106 |
} |
| 107 |
- dest := filepath.Join(pm.libRoot, p.P.ID) |
|
| 107 |
+ dest := filepath.Join(pm.libRoot, p.PluginObj.ID) |
|
| 108 | 108 |
config, err := os.Open(filepath.Join(dest, "manifest.json")) |
| 109 | 109 |
if err != nil {
|
| 110 | 110 |
return err |
| ... | ... |
@@ -127,7 +136,11 @@ func (pm *Manager) Remove(name string) error {
|
| 127 | 127 |
if err != nil {
|
| 128 | 128 |
return err |
| 129 | 129 |
} |
| 130 |
- return pm.remove(p) |
|
| 130 |
+ if err := pm.remove(p); err != nil {
|
|
| 131 |
+ return err |
|
| 132 |
+ } |
|
| 133 |
+ pm.pluginEventLogger(p.PluginObj.ID, name, "remove") |
|
| 134 |
+ return nil |
|
| 131 | 135 |
} |
| 132 | 136 |
|
| 133 | 137 |
// Set sets plugin args |
| ... | ... |
@@ -43,7 +43,7 @@ func (e ErrInadequateCapability) Error() string {
|
| 43 | 43 |
|
| 44 | 44 |
type plugin struct {
|
| 45 | 45 |
//sync.RWMutex TODO |
| 46 |
- P types.Plugin `json:"plugin"` |
|
| 46 |
+ PluginObj types.Plugin `json:"plugin"` |
|
| 47 | 47 |
client *plugins.Client |
| 48 | 48 |
restartManager restartmanager.RestartManager |
| 49 | 49 |
runtimeSourcePath string |
| ... | ... |
@@ -60,51 +60,53 @@ func (p *plugin) IsLegacy() bool {
|
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 | 62 |
func (p *plugin) Name() string {
|
| 63 |
- name := p.P.Name |
|
| 64 |
- if len(p.P.Tag) > 0 {
|
|
| 63 |
+ name := p.PluginObj.Name |
|
| 64 |
+ if len(p.PluginObj.Tag) > 0 {
|
|
| 65 | 65 |
// TODO: this feels hacky, maybe we should be storing the distribution reference rather than splitting these |
| 66 |
- name += ":" + p.P.Tag |
|
| 66 |
+ name += ":" + p.PluginObj.Tag |
|
| 67 | 67 |
} |
| 68 | 68 |
return name |
| 69 | 69 |
} |
| 70 | 70 |
|
| 71 | 71 |
func (pm *Manager) newPlugin(ref reference.Named, id string) *plugin {
|
| 72 | 72 |
p := &plugin{
|
| 73 |
- P: types.Plugin{
|
|
| 73 |
+ PluginObj: types.Plugin{
|
|
| 74 | 74 |
Name: ref.Name(), |
| 75 | 75 |
ID: id, |
| 76 | 76 |
}, |
| 77 | 77 |
runtimeSourcePath: filepath.Join(pm.runRoot, id), |
| 78 | 78 |
} |
| 79 | 79 |
if ref, ok := ref.(reference.NamedTagged); ok {
|
| 80 |
- p.P.Tag = ref.Tag() |
|
| 80 |
+ p.PluginObj.Tag = ref.Tag() |
|
| 81 | 81 |
} |
| 82 | 82 |
return p |
| 83 | 83 |
} |
| 84 | 84 |
|
| 85 | 85 |
func (pm *Manager) restorePlugin(p *plugin) error {
|
| 86 |
- p.runtimeSourcePath = filepath.Join(pm.runRoot, p.P.ID) |
|
| 87 |
- if p.P.Active {
|
|
| 86 |
+ p.runtimeSourcePath = filepath.Join(pm.runRoot, p.PluginObj.ID) |
|
| 87 |
+ if p.PluginObj.Active {
|
|
| 88 | 88 |
return pm.restore(p) |
| 89 | 89 |
} |
| 90 | 90 |
return nil |
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 | 93 |
type pluginMap map[string]*plugin |
| 94 |
+type eventLogger func(id, name, action string) |
|
| 94 | 95 |
|
| 95 | 96 |
// Manager controls the plugin subsystem. |
| 96 | 97 |
type Manager struct {
|
| 97 | 98 |
sync.RWMutex |
| 98 |
- libRoot string |
|
| 99 |
- runRoot string |
|
| 100 |
- plugins pluginMap // TODO: figure out why save() doesn't json encode *plugin object |
|
| 101 |
- nameToID map[string]string |
|
| 102 |
- handlers map[string]func(string, *plugins.Client) |
|
| 103 |
- containerdClient libcontainerd.Client |
|
| 104 |
- registryService registry.Service |
|
| 105 |
- handleLegacy bool |
|
| 106 |
- liveRestore bool |
|
| 107 |
- shutdown bool |
|
| 99 |
+ libRoot string |
|
| 100 |
+ runRoot string |
|
| 101 |
+ plugins pluginMap // TODO: figure out why save() doesn't json encode *plugin object |
|
| 102 |
+ nameToID map[string]string |
|
| 103 |
+ handlers map[string]func(string, *plugins.Client) |
|
| 104 |
+ containerdClient libcontainerd.Client |
|
| 105 |
+ registryService registry.Service |
|
| 106 |
+ handleLegacy bool |
|
| 107 |
+ liveRestore bool |
|
| 108 |
+ shutdown bool |
|
| 109 |
+ pluginEventLogger eventLogger |
|
| 108 | 110 |
} |
| 109 | 111 |
|
| 110 | 112 |
// GetManager returns the singleton plugin Manager |
| ... | ... |
@@ -114,21 +116,22 @@ func GetManager() *Manager {
|
| 114 | 114 |
|
| 115 | 115 |
// Init (was NewManager) instantiates the singleton Manager. |
| 116 | 116 |
// TODO: revert this to NewManager once we get rid of all the singletons. |
| 117 |
-func Init(root string, remote libcontainerd.Remote, rs registry.Service, liveRestore bool) (err error) {
|
|
| 117 |
+func Init(root string, remote libcontainerd.Remote, rs registry.Service, liveRestore bool, evL eventLogger) (err error) {
|
|
| 118 | 118 |
if manager != nil {
|
| 119 | 119 |
return nil |
| 120 | 120 |
} |
| 121 | 121 |
|
| 122 | 122 |
root = filepath.Join(root, "plugins") |
| 123 | 123 |
manager = &Manager{
|
| 124 |
- libRoot: root, |
|
| 125 |
- runRoot: "/run/docker", |
|
| 126 |
- plugins: make(map[string]*plugin), |
|
| 127 |
- nameToID: make(map[string]string), |
|
| 128 |
- handlers: make(map[string]func(string, *plugins.Client)), |
|
| 129 |
- registryService: rs, |
|
| 130 |
- handleLegacy: true, |
|
| 131 |
- liveRestore: liveRestore, |
|
| 124 |
+ libRoot: root, |
|
| 125 |
+ runRoot: "/run/docker", |
|
| 126 |
+ plugins: make(map[string]*plugin), |
|
| 127 |
+ nameToID: make(map[string]string), |
|
| 128 |
+ handlers: make(map[string]func(string, *plugins.Client)), |
|
| 129 |
+ registryService: rs, |
|
| 130 |
+ handleLegacy: true, |
|
| 131 |
+ liveRestore: liveRestore, |
|
| 132 |
+ pluginEventLogger: evL, |
|
| 132 | 133 |
} |
| 133 | 134 |
if err := os.MkdirAll(manager.runRoot, 0700); err != nil {
|
| 134 | 135 |
return err |
| ... | ... |
@@ -180,7 +183,7 @@ func FindWithCapability(capability string) ([]Plugin, error) {
|
| 180 | 180 |
defer manager.RUnlock() |
| 181 | 181 |
pluginLoop: |
| 182 | 182 |
for _, p := range manager.plugins {
|
| 183 |
- for _, typ := range p.P.Manifest.Interface.Types {
|
|
| 183 |
+ for _, typ := range p.PluginObj.Manifest.Interface.Types {
|
|
| 184 | 184 |
if typ.Capability != capability || typ.Prefix != "docker" {
|
| 185 | 185 |
continue pluginLoop |
| 186 | 186 |
} |
| ... | ... |
@@ -242,7 +245,7 @@ func LookupWithCapability(name, capability string) (Plugin, error) {
|
| 242 | 242 |
} |
| 243 | 243 |
|
| 244 | 244 |
capability = strings.ToLower(capability) |
| 245 |
- for _, typ := range p.P.Manifest.Interface.Types {
|
|
| 245 |
+ for _, typ := range p.PluginObj.Manifest.Interface.Types {
|
|
| 246 | 246 |
if typ.Capability == capability && typ.Prefix == "docker" {
|
| 247 | 247 |
return p, nil |
| 248 | 248 |
} |
| ... | ... |
@@ -312,8 +315,8 @@ func (pm *Manager) init() error {
|
| 312 | 312 |
} |
| 313 | 313 |
|
| 314 | 314 |
pm.Lock() |
| 315 |
- pm.nameToID[p.Name()] = p.P.ID |
|
| 316 |
- requiresManualRestore := !pm.liveRestore && p.P.Active |
|
| 315 |
+ pm.nameToID[p.Name()] = p.PluginObj.ID |
|
| 316 |
+ requiresManualRestore := !pm.liveRestore && p.PluginObj.Active |
|
| 317 | 317 |
pm.Unlock() |
| 318 | 318 |
|
| 319 | 319 |
if requiresManualRestore {
|
| ... | ... |
@@ -329,44 +332,44 @@ func (pm *Manager) init() error {
|
| 329 | 329 |
} |
| 330 | 330 |
|
| 331 | 331 |
func (pm *Manager) initPlugin(p *plugin) error {
|
| 332 |
- dt, err := os.Open(filepath.Join(pm.libRoot, p.P.ID, "manifest.json")) |
|
| 332 |
+ dt, err := os.Open(filepath.Join(pm.libRoot, p.PluginObj.ID, "manifest.json")) |
|
| 333 | 333 |
if err != nil {
|
| 334 | 334 |
return err |
| 335 | 335 |
} |
| 336 |
- err = json.NewDecoder(dt).Decode(&p.P.Manifest) |
|
| 336 |
+ err = json.NewDecoder(dt).Decode(&p.PluginObj.Manifest) |
|
| 337 | 337 |
dt.Close() |
| 338 | 338 |
if err != nil {
|
| 339 | 339 |
return err |
| 340 | 340 |
} |
| 341 | 341 |
|
| 342 |
- p.P.Config.Mounts = make([]types.PluginMount, len(p.P.Manifest.Mounts)) |
|
| 343 |
- for i, mount := range p.P.Manifest.Mounts {
|
|
| 344 |
- p.P.Config.Mounts[i] = mount |
|
| 342 |
+ p.PluginObj.Config.Mounts = make([]types.PluginMount, len(p.PluginObj.Manifest.Mounts)) |
|
| 343 |
+ for i, mount := range p.PluginObj.Manifest.Mounts {
|
|
| 344 |
+ p.PluginObj.Config.Mounts[i] = mount |
|
| 345 | 345 |
} |
| 346 |
- p.P.Config.Env = make([]string, 0, len(p.P.Manifest.Env)) |
|
| 347 |
- for _, env := range p.P.Manifest.Env {
|
|
| 346 |
+ p.PluginObj.Config.Env = make([]string, 0, len(p.PluginObj.Manifest.Env)) |
|
| 347 |
+ for _, env := range p.PluginObj.Manifest.Env {
|
|
| 348 | 348 |
if env.Value != nil {
|
| 349 |
- p.P.Config.Env = append(p.P.Config.Env, fmt.Sprintf("%s=%s", env.Name, *env.Value))
|
|
| 349 |
+ p.PluginObj.Config.Env = append(p.PluginObj.Config.Env, fmt.Sprintf("%s=%s", env.Name, *env.Value))
|
|
| 350 | 350 |
} |
| 351 | 351 |
} |
| 352 |
- copy(p.P.Config.Args, p.P.Manifest.Args.Value) |
|
| 352 |
+ copy(p.PluginObj.Config.Args, p.PluginObj.Manifest.Args.Value) |
|
| 353 | 353 |
|
| 354 |
- f, err := os.Create(filepath.Join(pm.libRoot, p.P.ID, "plugin-config.json")) |
|
| 354 |
+ f, err := os.Create(filepath.Join(pm.libRoot, p.PluginObj.ID, "plugin-config.json")) |
|
| 355 | 355 |
if err != nil {
|
| 356 | 356 |
return err |
| 357 | 357 |
} |
| 358 |
- err = json.NewEncoder(f).Encode(&p.P.Config) |
|
| 358 |
+ err = json.NewEncoder(f).Encode(&p.PluginObj.Config) |
|
| 359 | 359 |
f.Close() |
| 360 | 360 |
return err |
| 361 | 361 |
} |
| 362 | 362 |
|
| 363 | 363 |
func (pm *Manager) remove(p *plugin) error {
|
| 364 |
- if p.P.Active {
|
|
| 364 |
+ if p.PluginObj.Active {
|
|
| 365 | 365 |
return fmt.Errorf("plugin %s is active", p.Name())
|
| 366 | 366 |
} |
| 367 | 367 |
pm.Lock() // fixme: lock single record |
| 368 | 368 |
defer pm.Unlock() |
| 369 |
- delete(pm.plugins, p.P.ID) |
|
| 369 |
+ delete(pm.plugins, p.PluginObj.ID) |
|
| 370 | 370 |
delete(pm.nameToID, p.Name()) |
| 371 | 371 |
pm.save() |
| 372 | 372 |
return nil |
| ... | ... |
@@ -21,7 +21,7 @@ import ( |
| 21 | 21 |
) |
| 22 | 22 |
|
| 23 | 23 |
func (pm *Manager) enable(p *plugin) error {
|
| 24 |
- if p.P.Active {
|
|
| 24 |
+ if p.PluginObj.Active {
|
|
| 25 | 25 |
return fmt.Errorf("plugin %s is already enabled", p.Name())
|
| 26 | 26 |
} |
| 27 | 27 |
spec, err := pm.initSpec(p) |
| ... | ... |
@@ -30,14 +30,14 @@ func (pm *Manager) enable(p *plugin) error {
|
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 | 32 |
p.restartManager = restartmanager.New(container.RestartPolicy{Name: "always"}, 0)
|
| 33 |
- if err := pm.containerdClient.Create(p.P.ID, libcontainerd.Spec(*spec), libcontainerd.WithRestartManager(p.restartManager)); err != nil { // POC-only
|
|
| 33 |
+ if err := pm.containerdClient.Create(p.PluginObj.ID, libcontainerd.Spec(*spec), libcontainerd.WithRestartManager(p.restartManager)); err != nil { // POC-only
|
|
| 34 | 34 |
if err := p.restartManager.Cancel(); err != nil {
|
| 35 | 35 |
logrus.Errorf("enable: restartManager.Cancel failed due to %v", err)
|
| 36 | 36 |
} |
| 37 | 37 |
return err |
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 |
- socket := p.P.Manifest.Interface.Socket |
|
| 40 |
+ socket := p.PluginObj.Manifest.Interface.Socket |
|
| 41 | 41 |
p.client, err = plugins.NewClient("unix://"+filepath.Join(p.runtimeSourcePath, socket), nil)
|
| 42 | 42 |
if err != nil {
|
| 43 | 43 |
if err := p.restartManager.Cancel(); err != nil {
|
| ... | ... |
@@ -47,11 +47,11 @@ func (pm *Manager) enable(p *plugin) error {
|
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 | 49 |
pm.Lock() // fixme: lock single record |
| 50 |
- p.P.Active = true |
|
| 50 |
+ p.PluginObj.Active = true |
|
| 51 | 51 |
pm.save() |
| 52 | 52 |
pm.Unlock() |
| 53 | 53 |
|
| 54 |
- for _, typ := range p.P.Manifest.Interface.Types {
|
|
| 54 |
+ for _, typ := range p.PluginObj.Manifest.Interface.Types {
|
|
| 55 | 55 |
if handler := pm.handlers[typ.String()]; handler != nil {
|
| 56 | 56 |
handler(p.Name(), p.Client()) |
| 57 | 57 |
} |
| ... | ... |
@@ -62,19 +62,19 @@ func (pm *Manager) enable(p *plugin) error {
|
| 62 | 62 |
|
| 63 | 63 |
func (pm *Manager) restore(p *plugin) error {
|
| 64 | 64 |
p.restartManager = restartmanager.New(container.RestartPolicy{Name: "always"}, 0)
|
| 65 |
- return pm.containerdClient.Restore(p.P.ID, libcontainerd.WithRestartManager(p.restartManager)) |
|
| 65 |
+ return pm.containerdClient.Restore(p.PluginObj.ID, libcontainerd.WithRestartManager(p.restartManager)) |
|
| 66 | 66 |
} |
| 67 | 67 |
|
| 68 | 68 |
func (pm *Manager) initSpec(p *plugin) (*specs.Spec, error) {
|
| 69 | 69 |
s := oci.DefaultSpec() |
| 70 | 70 |
|
| 71 |
- rootfs := filepath.Join(pm.libRoot, p.P.ID, "rootfs") |
|
| 71 |
+ rootfs := filepath.Join(pm.libRoot, p.PluginObj.ID, "rootfs") |
|
| 72 | 72 |
s.Root = specs.Root{
|
| 73 | 73 |
Path: rootfs, |
| 74 | 74 |
Readonly: false, // TODO: all plugins should be readonly? settable in manifest? |
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 |
- mounts := append(p.P.Config.Mounts, types.PluginMount{
|
|
| 77 |
+ mounts := append(p.PluginObj.Config.Mounts, types.PluginMount{
|
|
| 78 | 78 |
Source: &p.runtimeSourcePath, |
| 79 | 79 |
Destination: defaultPluginRuntimeDestination, |
| 80 | 80 |
Type: "bind", |
| ... | ... |
@@ -104,12 +104,12 @@ func (pm *Manager) initSpec(p *plugin) (*specs.Spec, error) {
|
| 104 | 104 |
s.Mounts = append(s.Mounts, m) |
| 105 | 105 |
} |
| 106 | 106 |
|
| 107 |
- envs := make([]string, 1, len(p.P.Config.Env)+1) |
|
| 107 |
+ envs := make([]string, 1, len(p.PluginObj.Config.Env)+1) |
|
| 108 | 108 |
envs[0] = "PATH=" + system.DefaultPathEnv |
| 109 |
- envs = append(envs, p.P.Config.Env...) |
|
| 109 |
+ envs = append(envs, p.PluginObj.Config.Env...) |
|
| 110 | 110 |
|
| 111 |
- args := append(p.P.Manifest.Entrypoint, p.P.Config.Args...) |
|
| 112 |
- cwd := p.P.Manifest.Workdir |
|
| 111 |
+ args := append(p.PluginObj.Manifest.Entrypoint, p.PluginObj.Config.Args...) |
|
| 112 |
+ cwd := p.PluginObj.Manifest.Workdir |
|
| 113 | 113 |
if len(cwd) == 0 {
|
| 114 | 114 |
cwd = "/" |
| 115 | 115 |
} |
| ... | ... |
@@ -124,19 +124,19 @@ func (pm *Manager) initSpec(p *plugin) (*specs.Spec, error) {
|
| 124 | 124 |
} |
| 125 | 125 |
|
| 126 | 126 |
func (pm *Manager) disable(p *plugin) error {
|
| 127 |
- if !p.P.Active {
|
|
| 127 |
+ if !p.PluginObj.Active {
|
|
| 128 | 128 |
return fmt.Errorf("plugin %s is already disabled", p.Name())
|
| 129 | 129 |
} |
| 130 | 130 |
if err := p.restartManager.Cancel(); err != nil {
|
| 131 | 131 |
logrus.Error(err) |
| 132 | 132 |
} |
| 133 |
- if err := pm.containerdClient.Signal(p.P.ID, int(syscall.SIGKILL)); err != nil {
|
|
| 133 |
+ if err := pm.containerdClient.Signal(p.PluginObj.ID, int(syscall.SIGKILL)); err != nil {
|
|
| 134 | 134 |
logrus.Error(err) |
| 135 | 135 |
} |
| 136 | 136 |
os.RemoveAll(p.runtimeSourcePath) |
| 137 | 137 |
pm.Lock() // fixme: lock single record |
| 138 | 138 |
defer pm.Unlock() |
| 139 |
- p.P.Active = false |
|
| 139 |
+ p.PluginObj.Active = false |
|
| 140 | 140 |
pm.save() |
| 141 | 141 |
return nil |
| 142 | 142 |
} |
| ... | ... |
@@ -148,7 +148,7 @@ func (pm *Manager) Shutdown() {
|
| 148 | 148 |
|
| 149 | 149 |
pm.shutdown = true |
| 150 | 150 |
for _, p := range pm.plugins {
|
| 151 |
- if pm.liveRestore && p.P.Active {
|
|
| 151 |
+ if pm.liveRestore && p.PluginObj.Active {
|
|
| 152 | 152 |
logrus.Debug("Plugin active when liveRestore is set, skipping shutdown")
|
| 153 | 153 |
continue |
| 154 | 154 |
} |
| ... | ... |
@@ -157,9 +157,9 @@ func (pm *Manager) Shutdown() {
|
| 157 | 157 |
logrus.Error(err) |
| 158 | 158 |
} |
| 159 | 159 |
} |
| 160 |
- if pm.containerdClient != nil && p.P.Active {
|
|
| 160 |
+ if pm.containerdClient != nil && p.PluginObj.Active {
|
|
| 161 | 161 |
p.exitChan = make(chan bool) |
| 162 |
- err := pm.containerdClient.Signal(p.P.ID, int(syscall.SIGTERM)) |
|
| 162 |
+ err := pm.containerdClient.Signal(p.PluginObj.ID, int(syscall.SIGTERM)) |
|
| 163 | 163 |
if err != nil {
|
| 164 | 164 |
logrus.Errorf("Sending SIGTERM to plugin failed with error: %v", err)
|
| 165 | 165 |
} else {
|
| ... | ... |
@@ -168,14 +168,14 @@ func (pm *Manager) Shutdown() {
|
| 168 | 168 |
logrus.Debug("Clean shutdown of plugin")
|
| 169 | 169 |
case <-time.After(time.Second * 10): |
| 170 | 170 |
logrus.Debug("Force shutdown plugin")
|
| 171 |
- if err := pm.containerdClient.Signal(p.P.ID, int(syscall.SIGKILL)); err != nil {
|
|
| 171 |
+ if err := pm.containerdClient.Signal(p.PluginObj.ID, int(syscall.SIGKILL)); err != nil {
|
|
| 172 | 172 |
logrus.Errorf("Sending SIGKILL to plugin failed with error: %v", err)
|
| 173 | 173 |
} |
| 174 | 174 |
} |
| 175 | 175 |
} |
| 176 | 176 |
close(p.exitChan) |
| 177 | 177 |
pm.Lock() |
| 178 |
- p.P.Active = false |
|
| 178 |
+ p.PluginObj.Active = false |
|
| 179 | 179 |
pm.save() |
| 180 | 180 |
pm.Unlock() |
| 181 | 181 |
} |