Add internal network option
Signed-off-by: Chun Chen <ramichen@tencent.com>
This commit is contained in:
parent
b464d40ce6
commit
186a32acab
|
@ -103,6 +103,9 @@ func (sb *sandbox) needDefaultGW() bool {
|
||||||
if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" {
|
if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if ep.getNetwork().Internal() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if ep.joinInfo.disableGatewayService {
|
if ep.joinInfo.disableGatewayService {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -490,6 +490,12 @@ func parseNetworkOptions(id string, option options.Generic) (*networkConfigurati
|
||||||
config.EnableIPv6 = val.(bool)
|
config.EnableIPv6 = val.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if val, ok := option[netlabel.Internal]; ok {
|
||||||
|
if internal, ok := val.(bool); ok && internal {
|
||||||
|
return nil, &driverapi.ErrNotImplemented{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Finally validate the configuration
|
// Finally validate the configuration
|
||||||
if err = config.Validate(); err != nil {
|
if err = config.Validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -2327,3 +2327,10 @@ func TestParallel2(t *testing.T) {
|
||||||
func TestParallel3(t *testing.T) {
|
func TestParallel3(t *testing.T) {
|
||||||
runParallelTests(t, 3)
|
runParallelTests(t, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNetworkInternal(t *testing.T) {
|
||||||
|
_, err := controller.NewNetwork(bridgeNetType, "testnetworkinternal", libnetwork.NetworkOptionInternalNetwork())
|
||||||
|
if err == nil || err.Error() != (&driverapi.ErrNotImplemented{}).Error() {
|
||||||
|
t.Fatal("bridge network can't be internal")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -41,6 +41,9 @@ const (
|
||||||
|
|
||||||
// Gateway represents the gateway for the network
|
// Gateway represents the gateway for the network
|
||||||
Gateway = Prefix + ".gateway"
|
Gateway = Prefix + ".gateway"
|
||||||
|
|
||||||
|
// Internal constant represents that the network is internal which disables default gateway service
|
||||||
|
Internal = Prefix + ".internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -163,6 +163,7 @@ type network struct {
|
||||||
persist bool
|
persist bool
|
||||||
stopWatchCh chan struct{}
|
stopWatchCh chan struct{}
|
||||||
drvOnce *sync.Once
|
drvOnce *sync.Once
|
||||||
|
internal bool
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,6 +306,7 @@ func (n *network) CopyTo(o datastore.KVObject) error {
|
||||||
dstN.dbIndex = n.dbIndex
|
dstN.dbIndex = n.dbIndex
|
||||||
dstN.dbExists = n.dbExists
|
dstN.dbExists = n.dbExists
|
||||||
dstN.drvOnce = n.drvOnce
|
dstN.drvOnce = n.drvOnce
|
||||||
|
dstN.internal = n.internal
|
||||||
|
|
||||||
for _, v4conf := range n.ipamV4Config {
|
for _, v4conf := range n.ipamV4Config {
|
||||||
dstV4Conf := &IpamConf{}
|
dstV4Conf := &IpamConf{}
|
||||||
|
@ -391,6 +393,7 @@ func (n *network) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
netMap["ipamV6Info"] = string(iis)
|
netMap["ipamV6Info"] = string(iis)
|
||||||
}
|
}
|
||||||
|
netMap["internal"] = n.internal
|
||||||
return json.Marshal(netMap)
|
return json.Marshal(netMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,6 +457,9 @@ func (n *network) UnmarshalJSON(b []byte) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if v, ok := netMap["internal"]; ok {
|
||||||
|
n.internal = v.(bool)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,6 +486,18 @@ func NetworkOptionPersist(persist bool) NetworkOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NetworkOptionInternalNetwork returns an option setter to config the network
|
||||||
|
// to be internal which disables default gateway service
|
||||||
|
func NetworkOptionInternalNetwork() NetworkOption {
|
||||||
|
return func(n *network) {
|
||||||
|
n.internal = true
|
||||||
|
if n.generic == nil {
|
||||||
|
n.generic = make(map[string]interface{})
|
||||||
|
}
|
||||||
|
n.generic[netlabel.Internal] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NetworkOptionIpam function returns an option setter for the ipam configuration for this network
|
// NetworkOptionIpam function returns an option setter for the ipam configuration for this network
|
||||||
func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ipV6 []*IpamConf) NetworkOption {
|
func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ipV6 []*IpamConf) NetworkOption {
|
||||||
return func(n *network) {
|
return func(n *network) {
|
||||||
|
@ -1187,3 +1205,10 @@ func (n *network) IpamInfo() ([]*IpamInfo, []*IpamInfo) {
|
||||||
|
|
||||||
return v4Info, v6Info
|
return v4Info, v6Info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *network) Internal() bool {
|
||||||
|
n.Lock()
|
||||||
|
defer n.Unlock()
|
||||||
|
|
||||||
|
return n.internal
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue