mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Avoid adding local reserved networks (bridge, none, host) to the datastore
Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
parent
87161e8935
commit
594361552e
2 changed files with 28 additions and 1 deletions
|
@ -47,6 +47,7 @@ package libnetwork
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -60,6 +61,9 @@ import (
|
||||||
"github.com/docker/swarm/pkg/store"
|
"github.com/docker/swarm/pkg/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: Move it to error.go once the error refactoring is done
|
||||||
|
var ErrInvalidDatastore = errors.New("Datastore is not initialized")
|
||||||
|
|
||||||
// NetworkController provides the interface for controller instance which manages
|
// NetworkController provides the interface for controller instance which manages
|
||||||
// networks.
|
// networks.
|
||||||
type NetworkController interface {
|
type NetworkController interface {
|
||||||
|
@ -198,6 +202,9 @@ func (c *controller) NewNetwork(networkType, name string, options ...NetworkOpti
|
||||||
}
|
}
|
||||||
|
|
||||||
network.processOptions(options...)
|
network.processOptions(options...)
|
||||||
|
if err := c.addNetworkToStore(network); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
// Create the network
|
// Create the network
|
||||||
if err := d.CreateNetwork(network.id, network.generic); err != nil {
|
if err := d.CreateNetwork(network.id, network.generic); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -206,7 +213,6 @@ func (c *controller) NewNetwork(networkType, name string, options ...NetworkOpti
|
||||||
// Store the network handler in controller
|
// Store the network handler in controller
|
||||||
c.Lock()
|
c.Lock()
|
||||||
c.networks[network.id] = network
|
c.networks[network.id] = network
|
||||||
c.store.PutObjectAtomic(network)
|
|
||||||
c.Unlock()
|
c.Unlock()
|
||||||
|
|
||||||
return network, nil
|
return network, nil
|
||||||
|
@ -226,6 +232,16 @@ func (c *controller) newNetworkFromStore(n *network) {
|
||||||
// TODO : Populate n.endpoints back from endpoint dbstore
|
// TODO : Populate n.endpoints back from endpoint dbstore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *controller) addNetworkToStore(n *network) error {
|
||||||
|
if IsReservedNetwork(n.Name()) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if c.store == nil {
|
||||||
|
return ErrInvalidDatastore
|
||||||
|
}
|
||||||
|
return c.store.PutObjectAtomic(n)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *controller) watchNewNetworks() {
|
func (c *controller) watchNewNetworks() {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
store = c.store
|
store = c.store
|
||||||
|
|
|
@ -2,6 +2,7 @@ package libnetwork
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
|
@ -254,3 +255,13 @@ func (n *network) EndpointByID(id string) (Endpoint, error) {
|
||||||
}
|
}
|
||||||
return nil, ErrNoSuchEndpoint(id)
|
return nil, ErrNoSuchEndpoint(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsReservedNetwork(name string) bool {
|
||||||
|
reserved := []string{"bridge", "none", "host"}
|
||||||
|
for _, r := range reserved {
|
||||||
|
if strings.EqualFold(r, name) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue