Add ConnectivityScope capability for network drivers along with scope… · kelify/libnetwork@596122e · GitHub
Skip to content

Commit 596122e

Browse files
committed
Add ConnectivityScope capability for network drivers along with scope network option
- It specifies whether the network driver can provide containers connectivity across hosts. - As of now, the data scope of the driver was being overloaded with this notion. - The driver scope information is still valid and it defines whether the data allocation of the network resources can be done globally or only locally. - With the scope network option, user can now force a network as swarm scoped regardless of the driver data scope. - In case the network is configured as swarm scoped, and the network driver is multihost capable, a network DB instance will be launched for it. Signed-off-by: Alessandro Boch <aboch@docker.com>
1 parent 16406c8 commit 596122e

21 files changed

Lines changed: 103 additions & 42 deletions

File tree

agent.go

Lines changed: 2 additions & 2 deletions

controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ func (c *controller) pushNodeDiscovery(d driverapi.Driver, cap driverapi.Capabil
621621
}
622622
}
623623

624-
if d == nil || cap.DataScope != datastore.GlobalScope || nodes == nil {
624+
if d == nil || cap.ConnectivityScope != datastore.GlobalScope || nodes == nil {
625625
return
626626
}
627627

@@ -747,11 +747,17 @@ func (c *controller) NewNetwork(networkType, name string, id string, options ...
747747
return nil, err
748748
}
749749

750+
if network.scope == datastore.LocalScope && cap.DataScope == datastore.GlobalScope {
751+
return nil, types.ForbiddenErrorf("cannot downgrade network scope for %s networks", networkType)
752+
753+
}
750754
if network.ingress && cap.DataScope != datastore.GlobalScope {
751755
return nil, types.ForbiddenErrorf("Ingress network can only be global scope network")
752756
}
753757

754-
if cap.DataScope == datastore.GlobalScope && !c.isDistributedControl() && !network.dynamic {
758+
// At this point the network scope is still unknown if not set by user
759+
if (cap.DataScope == datastore.GlobalScope || network.scope == datastore.SwarmScope) &&
760+
!c.isDistributedControl() && !network.dynamic {
755761
if c.isManager() {
756762
// For non-distributed controlled environment, globalscoped non-dynamic networks are redirected to Manager
757763
return nil, ManagerRedirectError(name)

datastore/datastore.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ const (
115115
// LocalScope indicates to store the KV object in local datastore such as boltdb
116116
LocalScope = "local"
117117
// GlobalScope indicates to store the KV object in global datastore such as consul/etcd/zookeeper
118-
GlobalScope = "global"
118+
GlobalScope = "global"
119+
// SwarmScope is not indicating a datastore location. It is defined here
120+
// along with the other two scopes just for consistency.
121+
SwarmScope = "swarm"
119122
defaultPrefix = "/var/lib/docker/network/files"
120123
)
121124

docs/remote.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ Other entries in the list value are allowed; `"NetworkDriver"` indicates that th
5656
After Handshake, the remote driver will receive another POST message to the URL `/NetworkDriver.GetCapabilities` with no payload. The driver's response should have the form:
5757

5858
{
59-
"Scope": "local"
59+
"Scope": "local"
60+
"ConnectivityScope": "global"
6061
}
6162

62-
Value of "Scope" should be either "local" or "global" which indicates the capability of remote driver, values beyond these will fail driver's registration and return an error to the caller.
63+
Value of "Scope" should be either "local" or "global" which indicates whether the resource allocations for this driver's network can be done only locally to the node or globally across the cluster of nodes. Any other value will fail driver's registration and return an error to the caller.
64+
Similarly, value of "ConnectivityScope" should be either "local" or "global" which indicates whether the driver's network can provide connectivity only locally to this node or globally across the cluster of nodes. If the value is missing, libnetwork will set it to the value of "Scope". should be either "local" or "global" which indicates
6365

6466
### Create network
6567

driverapi/driverapi.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ type DriverCallback interface {
161161

162162
// Capability represents the high level capabilities of the drivers which libnetwork can make use of
163163
type Capability struct {
164-
DataScope string
164+
DataScope string
165+
ConnectivityScope string
165166
}
166167

167168
// IPAMData represents the per-network ip related

drivers/bridge/bridge.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
153153
}
154154

155155
c := driverapi.Capability{
156-
DataScope: datastore.LocalScope,
156+
DataScope: datastore.LocalScope,
157+
ConnectivityScope: datastore.LocalScope,
157158
}
158159
return dc.RegisterDriver(networkType, d, c)
159160
}

drivers/host/host.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ type driver struct {
1919
// Init registers a new instance of host driver
2020
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
2121
c := driverapi.Capability{
22-
DataScope: datastore.LocalScope,
22+
DataScope: datastore.LocalScope,
23+
ConnectivityScope: datastore.LocalScope,
2324
}
2425
return dc.RegisterDriver(networkType, &driver{}, c)
2526
}

drivers/ipvlan/ipvlan.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ type network struct {
5858
// Init initializes and registers the libnetwork ipvlan driver
5959
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
6060
c := driverapi.Capability{
61-
DataScope: datastore.LocalScope,
61+
DataScope: datastore.LocalScope,
62+
ConnectivityScope: datastore.GlobalScope,
6263
}
6364
d := &driver{
6465
networks: networkTable{},

drivers/macvlan/macvlan.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ type network struct {
6060
// Init initializes and registers the libnetwork macvlan driver
6161
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
6262
c := driverapi.Capability{
63-
DataScope: datastore.LocalScope,
63+
DataScope: datastore.LocalScope,
64+
ConnectivityScope: datastore.GlobalScope,
6465
}
6566
d := &driver{
6667
networks: networkTable{},

drivers/overlay/overlay.go

Lines changed: 2 additions & 1 deletion

0 commit comments

Comments
 (0)