mirror of https://github.com/docker/docs.git
Merge pull request #2135 from janeczku/plugin-versioning
Fail gracefully when plugin binary implements outdated API
This commit is contained in:
commit
47aa16cff4
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/docker/machine/libmachine/drivers"
|
||||
"github.com/docker/machine/libmachine/drivers/plugin/localbinary"
|
||||
"github.com/docker/machine/libmachine/drivers/rpc"
|
||||
"github.com/docker/machine/libmachine/version"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -20,9 +21,11 @@ var (
|
|||
|
||||
func RegisterDriver(d drivers.Driver) {
|
||||
if os.Getenv(localbinary.PluginEnvKey) != localbinary.PluginEnvVal {
|
||||
fmt.Fprintln(os.Stderr, `This is a Docker Machine plugin binary.
|
||||
fmt.Fprintf(os.Stderr, `This is a Docker Machine plugin binary.
|
||||
Plugin binaries are not intended to be invoked directly.
|
||||
Please use this plugin through the main 'docker-machine' binary.`)
|
||||
Please use this plugin through the main 'docker-machine' binary.
|
||||
(API version: %d)
|
||||
`, version.ApiVersion)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/docker/machine/libmachine/log"
|
||||
"github.com/docker/machine/libmachine/mcnflag"
|
||||
"github.com/docker/machine/libmachine/state"
|
||||
"github.com/docker/machine/libmachine/version"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -93,11 +94,15 @@ func NewRpcClientDriver(rawDriverData []byte, driverName string) (*RpcClientDriv
|
|||
}
|
||||
}(c)
|
||||
|
||||
var version int
|
||||
if err := c.Client.Call("RpcServerDriver.GetVersion", struct{}{}, &version); err != nil {
|
||||
var serverVersion int
|
||||
if err := c.Client.Call("RpcServerDriver.GetVersion", struct{}{}, &serverVersion); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Debug("Using API Version ", version)
|
||||
|
||||
if serverVersion != version.ApiVersion {
|
||||
return nil, fmt.Errorf("Driver binary uses an incompatible API version (%d)", serverVersion)
|
||||
}
|
||||
log.Debug("Using API Version ", serverVersion)
|
||||
|
||||
if err := c.SetConfigRaw(rawDriverData); err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in New Issue