libnet: Return proper error when overlay network can't be created
The commitbefff0e13f
inadvertendly disabled the error returned when trying to create an overlay network on a node which is not part of a Swarm cluster. Since commite3708a89cc
the overlay netdriver returns the error: `no VNI provided`. This commit reinstate the original error message by checking if the node is a manager before calling libnetwork's `controller.NewNetwork()`. Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
parent
c57097bcd4
commit
21dcbada2d
1 changed files with 10 additions and 10 deletions
|
@ -293,6 +293,16 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create types.NetworkCrea
|
|||
return nil, PredefinedNetworkError(create.Name)
|
||||
}
|
||||
|
||||
c := daemon.netController
|
||||
driver := create.Driver
|
||||
if driver == "" {
|
||||
driver = c.Config().DefaultDriver
|
||||
}
|
||||
|
||||
if driver == "overlay" && !daemon.cluster.IsManager() && !agent {
|
||||
return nil, errors.New(`This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.`)
|
||||
}
|
||||
|
||||
var warning string
|
||||
nw, err := daemon.GetNetworkByName(create.Name)
|
||||
if err != nil {
|
||||
|
@ -311,12 +321,6 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create types.NetworkCrea
|
|||
warning = fmt.Sprintf("Network with name %s (id : %s) already exists", nw.Name(), nw.ID())
|
||||
}
|
||||
|
||||
c := daemon.netController
|
||||
driver := create.Driver
|
||||
if driver == "" {
|
||||
driver = c.Config().DefaultDriver
|
||||
}
|
||||
|
||||
networkOptions := make(map[string]string)
|
||||
for k, v := range create.Options {
|
||||
networkOptions[k] = v
|
||||
|
@ -375,10 +379,6 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create types.NetworkCrea
|
|||
|
||||
n, err := c.NewNetwork(driver, create.Name, id, nwOptions...)
|
||||
if err != nil {
|
||||
if errors.Is(err, libnetwork.ErrDataStoreNotInitialized) {
|
||||
//nolint: revive
|
||||
return nil, errors.New(`This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.`)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue