github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/daemon/graphdriver/plugin.go (about)

     1  package graphdriver // import "github.com/demonoid81/moby/daemon/graphdriver"
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  
     7  	"github.com/demonoid81/moby/errdefs"
     8  	"github.com/demonoid81/moby/pkg/plugingetter"
     9  	"github.com/demonoid81/moby/pkg/plugins"
    10  	v2 "github.com/demonoid81/moby/plugin/v2"
    11  	"github.com/pkg/errors"
    12  )
    13  
    14  func lookupPlugin(name string, pg plugingetter.PluginGetter, config Options) (Driver, error) {
    15  	if !config.ExperimentalEnabled {
    16  		return nil, fmt.Errorf("graphdriver plugins are only supported with experimental mode")
    17  	}
    18  	pl, err := pg.Get(name, "GraphDriver", plugingetter.Acquire)
    19  	if err != nil {
    20  		return nil, fmt.Errorf("Error looking up graphdriver plugin %s: %v", name, err)
    21  	}
    22  	return newPluginDriver(name, pl, config)
    23  }
    24  
    25  func newPluginDriver(name string, pl plugingetter.CompatPlugin, config Options) (Driver, error) {
    26  	home := config.Root
    27  	if !pl.IsV1() {
    28  		if p, ok := pl.(*v2.Plugin); ok {
    29  			if p.PluginObj.Config.PropagatedMount != "" {
    30  				home = p.PluginObj.Config.PropagatedMount
    31  			}
    32  		}
    33  	}
    34  
    35  	var proxy *graphDriverProxy
    36  
    37  	switch pt := pl.(type) {
    38  	case plugingetter.PluginWithV1Client:
    39  		proxy = &graphDriverProxy{name, pl, Capabilities{}, pt.Client()}
    40  	case plugingetter.PluginAddr:
    41  		if pt.Protocol() != plugins.ProtocolSchemeHTTPV1 {
    42  			return nil, errors.Errorf("plugin protocol not supported: %s", pt.Protocol())
    43  		}
    44  		addr := pt.Addr()
    45  		client, err := plugins.NewClientWithTimeout(addr.Network()+"://"+addr.String(), nil, pt.Timeout())
    46  		if err != nil {
    47  			return nil, errors.Wrap(err, "error creating plugin client")
    48  		}
    49  		proxy = &graphDriverProxy{name, pl, Capabilities{}, client}
    50  	default:
    51  		return nil, errdefs.System(errors.Errorf("got unknown plugin type %T", pt))
    52  	}
    53  
    54  	return proxy, proxy.Init(filepath.Join(home, name), config.DriverOptions, config.UIDMaps, config.GIDMaps)
    55  }