mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add DisableGatewayService in JoinInfo to offering drivers the ability to disable default gateway
Signed-off-by: Chun Chen <ramichen@tencent.com>
This commit is contained in:
parent
6f3c0e34f3
commit
141c51273f
8 changed files with 48 additions and 21 deletions
|
@ -92,6 +92,8 @@ func (ep *endpoint) AddStaticRoute(destination *net.IPNet, routeType int,
|
|||
return nil
|
||||
}
|
||||
|
||||
func (ep *endpoint) DisableGatewayService() {}
|
||||
|
||||
func main() {
|
||||
if reexec.Init() {
|
||||
return
|
||||
|
|
|
@ -103,6 +103,9 @@ func (sb *sandbox) needDefaultGW() bool {
|
|||
if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" {
|
||||
continue
|
||||
}
|
||||
if ep.joinInfo.disableGatewayService {
|
||||
return false
|
||||
}
|
||||
// TODO v6 needs to be handled.
|
||||
if len(ep.Gateway()) > 0 {
|
||||
return false
|
||||
|
|
|
@ -91,6 +91,9 @@ type JoinInfo interface {
|
|||
// AddStaticRoute adds a routes to the sandbox.
|
||||
// It may be used in addtion to or instead of a default gateway (as above).
|
||||
AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error
|
||||
|
||||
// DisableGatewayService tells libnetwork not to provide Default GW for the container
|
||||
DisableGatewayService()
|
||||
}
|
||||
|
||||
// DriverCallback provides a Callback interface for Drivers into LibNetwork
|
||||
|
|
|
@ -416,6 +416,8 @@ func (te *testEndpoint) AddStaticRoute(destination *net.IPNet, routeType int, ne
|
|||
return nil
|
||||
}
|
||||
|
||||
func (te *testEndpoint) DisableGatewayService() {}
|
||||
|
||||
func TestQueryEndpointInfo(t *testing.T) {
|
||||
testQueryEndpointInfo(t, true)
|
||||
}
|
||||
|
|
|
@ -138,6 +138,7 @@ type JoinResponse struct {
|
|||
Gateway string
|
||||
GatewayIPv6 string
|
||||
StaticRoutes []StaticRoute
|
||||
DisableGatewayService bool
|
||||
}
|
||||
|
||||
// LeaveRequest describes the API for detaching an endpoint from a sandbox.
|
||||
|
|
|
@ -231,6 +231,9 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
|
|||
}
|
||||
}
|
||||
}
|
||||
if res.DisableGatewayService {
|
||||
jinfo.DisableGatewayService()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ type testEndpoint struct {
|
|||
nextHop string
|
||||
destination string
|
||||
routeType int
|
||||
disableGatewayService bool
|
||||
}
|
||||
|
||||
func (test *testEndpoint) Interface() driverapi.InterfaceInfo {
|
||||
|
@ -191,6 +192,10 @@ func (test *testEndpoint) AddStaticRoute(destination *net.IPNet, routeType int,
|
|||
return nil
|
||||
}
|
||||
|
||||
func (test *testEndpoint) DisableGatewayService() {
|
||||
test.disableGatewayService = true
|
||||
}
|
||||
|
||||
func TestGetEmptyCapabilities(t *testing.T) {
|
||||
var plugin = "test-net-driver-empty-cap"
|
||||
|
||||
|
@ -343,7 +348,7 @@ func TestRemoteDriver(t *testing.T) {
|
|||
"DstPrefix": ep.dst,
|
||||
},
|
||||
"StaticRoutes": []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
{
|
||||
"Destination": ep.destination,
|
||||
"RouteType": ep.routeType,
|
||||
"NextHop": ep.nextHop,
|
||||
|
|
|
@ -139,6 +139,7 @@ type endpointJoinInfo struct {
|
|||
gw net.IP
|
||||
gw6 net.IP
|
||||
StaticRoutes []*types.StaticRoute
|
||||
disableGatewayService bool
|
||||
}
|
||||
|
||||
func (ep *endpoint) Info() EndpointInfo {
|
||||
|
@ -340,3 +341,10 @@ func (ep *endpoint) retrieveFromStore() (*endpoint, error) {
|
|||
}
|
||||
return n.getEndpointFromStore(ep.ID())
|
||||
}
|
||||
|
||||
func (ep *endpoint) DisableGatewayService() {
|
||||
ep.Lock()
|
||||
defer ep.Unlock()
|
||||
|
||||
ep.joinInfo.disableGatewayService = true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue