Skip to content

Commit fefea80

Browse files
Make graphdrivers work with pluginv2.
As part of making graphdrivers support pluginv2, a PluginGetter interface was necessary for cleaner separation and avoiding import cycles. This commit creates a PluginGetter interface and makes pluginStore implement it. Then the pluginStore object is created in the daemon (rather than by the plugin manager) and passed to plugin init as well as to the different subsystems (eg. graphdrivers, volumedrivers). A side effect of this change was that some code was moved out of experimental. This is good, since plugin support will be stable soon. Signed-off-by: Anusha Ragunathan <anusha@docker.com>
1 parent beea098 commit fefea80

File tree

24 files changed

+629
-569
lines changed

24 files changed

+629
-569
lines changed

api/types/plugin.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// +build experimental
2-
31
package types
42

53
import (

daemon/daemon.go

100755100644
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
"github.com/docker/docker/pkg/sysinfo"
4848
"github.com/docker/docker/pkg/system"
4949
"github.com/docker/docker/pkg/truncindex"
50+
pluginstore "github.com/docker/docker/plugin/store"
5051
"github.com/docker/docker/reference"
5152
"github.com/docker/docker/registry"
5253
"github.com/docker/docker/runconfig"
@@ -94,6 +95,7 @@ type Daemon struct {
9495
gidMaps []idtools.IDMap
9596
layerStore layer.Store
9697
imageStore image.Store
98+
pluginStore *pluginstore.Store
9799
nameIndex *registrar.Registrar
98100
linkIndex *linkIndex
99101
containerd libcontainerd.Client
@@ -548,13 +550,17 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
548550
if driverName == "" {
549551
driverName = config.GraphDriver
550552
}
553+
554+
d.pluginStore = pluginstore.NewStore(config.Root)
555+
551556
d.layerStore, err = layer.NewStoreFromOptions(layer.StoreOptions{
552557
StorePath: config.Root,
553558
MetadataStorePathTemplate: filepath.Join(config.Root, "image", "%s", "layerdb"),
554559
GraphDriver: driverName,
555560
GraphDriverOptions: config.GraphOptions,
556561
UIDMaps: uidMaps,
557562
GIDMaps: gidMaps,
563+
PluginGetter: d.pluginStore,
558564
})
559565
if err != nil {
560566
return nil, err
@@ -911,6 +917,8 @@ func (daemon *Daemon) configureVolumes(rootUID, rootGID int) (*store.VolumeStore
911917
return nil, err
912918
}
913919

920+
volumedrivers.RegisterPluginGetter(daemon.pluginStore)
921+
914922
if !volumedrivers.Register(volumesDriver, volumesDriver.Name()) {
915923
return nil, fmt.Errorf("local volume driver could not be registered")
916924
}

daemon/daemon_experimental.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (daemon *Daemon) verifyExperimentalContainerSettings(hostConfig *container.
1313
}
1414

1515
func pluginInit(d *Daemon, cfg *Config, remote libcontainerd.Remote) error {
16-
return plugin.Init(cfg.Root, remote, d.RegistryService, cfg.LiveRestoreEnabled, d.LogPluginEvent)
16+
return plugin.Init(cfg.Root, d.pluginStore, remote, d.RegistryService, cfg.LiveRestoreEnabled, d.LogPluginEvent)
1717
}
1818

1919
func pluginShutdown() {

daemon/graphdriver/driver.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/docker/docker/pkg/archive"
1414
"github.com/docker/docker/pkg/idtools"
15+
"github.com/docker/docker/plugin/getter"
1516
)
1617

1718
// FsMagic unsigned id of the filesystem in use.
@@ -134,11 +135,11 @@ func Register(name string, initFunc InitFunc) error {
134135
}
135136

136137
// GetDriver initializes and returns the registered driver
137-
func GetDriver(name, home string, options []string, uidMaps, gidMaps []idtools.IDMap) (Driver, error) {
138+
func GetDriver(name, home string, options []string, uidMaps, gidMaps []idtools.IDMap, plugingetter getter.PluginGetter) (Driver, error) {
138139
if initFunc, exists := drivers[name]; exists {
139140
return initFunc(filepath.Join(home, name), options, uidMaps, gidMaps)
140141
}
141-
if pluginDriver, err := lookupPlugin(name, home, options); err == nil {
142+
if pluginDriver, err := lookupPlugin(name, home, options, plugingetter); err == nil {
142143
return pluginDriver, nil
143144
}
144145
logrus.Errorf("Failed to GetDriver graph %s %s", name, home)
@@ -155,10 +156,10 @@ func getBuiltinDriver(name, home string, options []string, uidMaps, gidMaps []id
155156
}
156157

157158
// New creates the driver and initializes it at the specified root.
158-
func New(root string, name string, options []string, uidMaps, gidMaps []idtools.IDMap) (Driver, error) {
159+
func New(root string, name string, options []string, uidMaps, gidMaps []idtools.IDMap, plugingetter getter.PluginGetter) (Driver, error) {
159160
if name != "" {
160161
logrus.Debugf("[graphdriver] trying provided driver: %s", name) // so the logs show specified driver
161-
return GetDriver(name, root, options, uidMaps, gidMaps)
162+
return GetDriver(name, root, options, uidMaps, gidMaps, plugingetter)
162163
}
163164

164165
// Guess for prior driver

daemon/graphdriver/graphtest/graphtest_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func newDriver(t testing.TB, name string, options []string) *Driver {
4141
t.Fatal(err)
4242
}
4343

44-
d, err := graphdriver.GetDriver(name, root, options, nil, nil)
44+
d, err := graphdriver.GetDriver(name, root, options, nil, nil, nil)
4545
if err != nil {
4646
t.Logf("graphdriver: %v\n", err)
4747
if err == graphdriver.ErrNotSupported || err == graphdriver.ErrPrerequisites || err == graphdriver.ErrIncompatibleFS {

daemon/graphdriver/plugin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77
"io"
88

9-
"github.com/docker/docker/pkg/plugins"
9+
"github.com/docker/docker/plugin/getter"
1010
)
1111

1212
type pluginClient interface {
@@ -18,8 +18,8 @@ type pluginClient interface {
1818
SendFile(string, io.Reader, interface{}) error
1919
}
2020

21-
func lookupPlugin(name, home string, opts []string) (Driver, error) {
22-
pl, err := plugins.Get(name, "GraphDriver")
21+
func lookupPlugin(name, home string, opts []string, pluginGetter getter.PluginGetter) (Driver, error) {
22+
pl, err := pluginGetter.Get(name, "GraphDriver", getter.LOOKUP)
2323
if err != nil {
2424
return nil, fmt.Errorf("Error looking up graphdriver plugin %s: %v", name, err)
2525
}

daemon/graphdriver/plugin_unsupported.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
package graphdriver
44

5-
func lookupPlugin(name, home string, opts []string) (Driver, error) {
5+
import "github.com/docker/docker/plugin/getter"
6+
7+
func lookupPlugin(name, home string, opts []string, plugingetter getter.PluginGetter) (Driver, error) {
68
return nil, ErrNotSupported
79
}

layer/layer_store.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/docker/docker/pkg/archive"
1515
"github.com/docker/docker/pkg/idtools"
1616
"github.com/docker/docker/pkg/stringid"
17+
"github.com/docker/docker/plugin/getter"
1718
"github.com/vbatts/tar-split/tar/asm"
1819
"github.com/vbatts/tar-split/tar/storage"
1920
)
@@ -44,6 +45,7 @@ type StoreOptions struct {
4445
GraphDriverOptions []string
4546
UIDMaps []idtools.IDMap
4647
GIDMaps []idtools.IDMap
48+
PluginGetter getter.PluginGetter
4749
}
4850

4951
// NewStoreFromOptions creates a new Store instance
@@ -53,7 +55,8 @@ func NewStoreFromOptions(options StoreOptions) (Store, error) {
5355
options.GraphDriver,
5456
options.GraphDriverOptions,
5557
options.UIDMaps,
56-
options.GIDMaps)
58+
options.GIDMaps,
59+
options.PluginGetter)
5760
if err != nil {
5861
return nil, fmt.Errorf("error initializing graphdriver: %v", err)
5962
}

layer/layer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func newVFSGraphDriver(td string) (graphdriver.Driver, error) {
3939
},
4040
}
4141

42-
return graphdriver.GetDriver("vfs", td, nil, uidMap, gidMap)
42+
return graphdriver.GetDriver("vfs", td, nil, uidMap, gidMap, nil)
4343
}
4444

4545
func newTestGraphDriver(t *testing.T) (graphdriver.Driver, func()) {

pkg/plugins/plugins.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ func (p *Plugin) Client() *Client {
8383
return p.client
8484
}
8585

86-
// IsLegacy returns true for legacy plugins and false otherwise.
87-
func (p *Plugin) IsLegacy() bool {
86+
// IsV1 returns true for V1 plugins and false otherwise.
87+
func (p *Plugin) IsV1() bool {
8888
return true
8989
}
9090

0 commit comments

Comments
 (0)