mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Dnet agent mode support and IT
Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
parent
0580043718
commit
bd74df7b41
8 changed files with 224 additions and 36 deletions
|
@ -307,7 +307,17 @@ func procCreateNetwork(c libnetwork.NetworkController, vars map[string]string, b
|
||||||
if len(create.DriverOpts) > 0 {
|
if len(create.DriverOpts) > 0 {
|
||||||
options = append(options, libnetwork.NetworkOptionDriverOpts(create.DriverOpts))
|
options = append(options, libnetwork.NetworkOptionDriverOpts(create.DriverOpts))
|
||||||
}
|
}
|
||||||
nw, err := c.NewNetwork(create.NetworkType, create.Name, "", options...)
|
|
||||||
|
if len(create.IPv4Conf) > 0 {
|
||||||
|
ipamV4Conf := &libnetwork.IpamConf{
|
||||||
|
PreferredPool: create.IPv4Conf[0].PreferredPool,
|
||||||
|
SubPool: create.IPv4Conf[0].SubPool,
|
||||||
|
}
|
||||||
|
|
||||||
|
options = append(options, libnetwork.NetworkOptionIpam("default", "", []*libnetwork.IpamConf{ipamV4Conf}, nil, nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
nw, err := c.NewNetwork(create.NetworkType, create.Name, create.ID, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, convertNetworkError(err)
|
return nil, convertNetworkError(err)
|
||||||
}
|
}
|
||||||
|
@ -697,6 +707,7 @@ func procAttachBackend(c libnetwork.NetworkController, vars map[string]string, b
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, convertNetworkError(err)
|
return nil, convertNetworkError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.Key(), &successResponse
|
return sb.Key(), &successResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,10 +32,19 @@ type sandboxResource struct {
|
||||||
Body types
|
Body types
|
||||||
************/
|
************/
|
||||||
|
|
||||||
|
type ipamConf struct {
|
||||||
|
PreferredPool string
|
||||||
|
SubPool string
|
||||||
|
Gateway string
|
||||||
|
AuxAddresses map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
// networkCreate is the expected body of the "create network" http request message
|
// networkCreate is the expected body of the "create network" http request message
|
||||||
type networkCreate struct {
|
type networkCreate struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
ID string `json:"id"`
|
||||||
NetworkType string `json:"network_type"`
|
NetworkType string `json:"network_type"`
|
||||||
|
IPv4Conf []ipamConf `json:"ipv4_configuration"`
|
||||||
DriverOpts map[string]string `json:"driver_opts"`
|
DriverOpts map[string]string `json:"driver_opts"`
|
||||||
NetworkOpts map[string]string `json:"network_opts"`
|
NetworkOpts map[string]string `json:"network_opts"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
|
@ -42,8 +43,13 @@ func (cli *NetworkCli) CmdNetwork(chain string, args ...string) error {
|
||||||
func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error {
|
func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error {
|
||||||
cmd := cli.Subcmd(chain, "create", "NETWORK-NAME", "Creates a new network with a name specified by the user", false)
|
cmd := cli.Subcmd(chain, "create", "NETWORK-NAME", "Creates a new network with a name specified by the user", false)
|
||||||
flDriver := cmd.String([]string{"d", "-driver"}, "", "Driver to manage the Network")
|
flDriver := cmd.String([]string{"d", "-driver"}, "", "Driver to manage the Network")
|
||||||
|
flID := cmd.String([]string{"-id"}, "", "Network ID string")
|
||||||
|
flOpts := cmd.String([]string{"o", "-opt"}, "", "Network options")
|
||||||
flInternal := cmd.Bool([]string{"-internal"}, false, "Config the network to be internal")
|
flInternal := cmd.Bool([]string{"-internal"}, false, "Config the network to be internal")
|
||||||
flIPv6 := cmd.Bool([]string{"-ipv6"}, false, "Enable IPv6 on the network")
|
flIPv6 := cmd.Bool([]string{"-ipv6"}, false, "Enable IPv6 on the network")
|
||||||
|
flSubnet := cmd.String([]string{"-subnet"}, "", "Subnet option")
|
||||||
|
flRange := cmd.String([]string{"-ip-range"}, "", "Range option")
|
||||||
|
|
||||||
cmd.Require(flag.Exact, 1)
|
cmd.Require(flag.Exact, 1)
|
||||||
err := cmd.ParseFlags(args, true)
|
err := cmd.ParseFlags(args, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -56,9 +62,30 @@ func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error {
|
||||||
if *flIPv6 {
|
if *flIPv6 {
|
||||||
networkOpts[netlabel.EnableIPv6] = "true"
|
networkOpts[netlabel.EnableIPv6] = "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
driverOpts := make(map[string]string)
|
||||||
|
if *flOpts != "" {
|
||||||
|
opts := strings.Split(*flOpts, ",")
|
||||||
|
for _, opt := range opts {
|
||||||
|
driverOpts[netlabel.Key(opt)] = netlabel.Value(opt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var icList []ipamConf
|
||||||
|
if *flSubnet != "" {
|
||||||
|
ic := ipamConf{
|
||||||
|
PreferredPool: *flSubnet,
|
||||||
|
}
|
||||||
|
|
||||||
|
if *flRange != "" {
|
||||||
|
ic.SubPool = *flRange
|
||||||
|
}
|
||||||
|
|
||||||
|
icList = append(icList, ic)
|
||||||
|
}
|
||||||
|
|
||||||
// Construct network create request body
|
// Construct network create request body
|
||||||
var driverOpts []string
|
nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, ID: *flID, IPv4Conf: icList, DriverOpts: driverOpts, NetworkOpts: networkOpts}
|
||||||
nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, DriverOpts: driverOpts, NetworkOpts: networkOpts}
|
|
||||||
obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
|
obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -31,12 +31,20 @@ type SandboxResource struct {
|
||||||
/***********
|
/***********
|
||||||
Body types
|
Body types
|
||||||
************/
|
************/
|
||||||
|
type ipamConf struct {
|
||||||
|
PreferredPool string
|
||||||
|
SubPool string
|
||||||
|
Gateway string
|
||||||
|
AuxAddresses map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
// networkCreate is the expected body of the "create network" http request message
|
// networkCreate is the expected body of the "create network" http request message
|
||||||
type networkCreate struct {
|
type networkCreate struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
ID string `json:"id"`
|
||||||
NetworkType string `json:"network_type"`
|
NetworkType string `json:"network_type"`
|
||||||
DriverOpts []string `json:"driver_opts"`
|
IPv4Conf []ipamConf `json:"ipv4_configuration"`
|
||||||
|
DriverOpts map[string]string `json:"driver_opts"`
|
||||||
NetworkOpts map[string]string `json:"network_opts"`
|
NetworkOpts map[string]string `json:"network_opts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,15 @@ func processConfig(cfg *config.Config) []config.Option {
|
||||||
dd = cfg.Daemon.DefaultDriver
|
dd = cfg.Daemon.DefaultDriver
|
||||||
}
|
}
|
||||||
options = append(options, config.OptionDefaultDriver(dd))
|
options = append(options, config.OptionDefaultDriver(dd))
|
||||||
|
if cfg.Daemon.IsAgent {
|
||||||
|
options = append(options, config.OptionAgent())
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.Daemon.Bind != "" {
|
||||||
|
options = append(options, config.OptionBind(cfg.Daemon.Bind))
|
||||||
|
}
|
||||||
|
|
||||||
|
options = append(options, config.OptionNeighbors(cfg.Daemon.Neighbors))
|
||||||
|
|
||||||
if cfg.Daemon.Labels != nil {
|
if cfg.Daemon.Labels != nil {
|
||||||
options = append(options, config.OptionLabels(cfg.Daemon.Labels))
|
options = append(options, config.OptionLabels(cfg.Daemon.Labels))
|
||||||
|
|
|
@ -10,6 +10,10 @@ function dnet_container_name() {
|
||||||
echo dnet-$1-$2
|
echo dnet-$1-$2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dnet_container_ip() {
|
||||||
|
docker inspect --format '{{.NetworkSettings.IPAddress}}' dnet-$1-$2
|
||||||
|
}
|
||||||
|
|
||||||
function get_sbox_id() {
|
function get_sbox_id() {
|
||||||
local line
|
local line
|
||||||
|
|
||||||
|
@ -107,7 +111,7 @@ function parse_discovery_str() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function start_dnet() {
|
function start_dnet() {
|
||||||
local inst suffix name hport cport hopt store bridge_ip labels tomlfile
|
local inst suffix name hport cport hopt store bridge_ip labels tomlfile nip
|
||||||
local discovery provider address
|
local discovery provider address
|
||||||
|
|
||||||
inst=$1
|
inst=$1
|
||||||
|
@ -115,13 +119,16 @@ function start_dnet() {
|
||||||
suffix=$1
|
suffix=$1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
stop_dnet ${inst} ${suffix}
|
store=$(echo $suffix | cut -d":" -f1)
|
||||||
name=$(dnet_container_name ${inst} ${suffix})
|
nip=$(echo $suffix | cut -s -d":" -f2)
|
||||||
|
|
||||||
|
|
||||||
|
stop_dnet ${inst} ${store}
|
||||||
|
name=$(dnet_container_name ${inst} ${store})
|
||||||
|
|
||||||
hport=$((41000+${inst}-1))
|
hport=$((41000+${inst}-1))
|
||||||
cport=2385
|
cport=2385
|
||||||
hopt=""
|
hopt=""
|
||||||
store=${suffix}
|
|
||||||
|
|
||||||
while [ -n "$1" ]
|
while [ -n "$1" ]
|
||||||
do
|
do
|
||||||
|
@ -138,20 +145,31 @@ function start_dnet() {
|
||||||
|
|
||||||
bridge_ip=$(get_docker_bridge_ip)
|
bridge_ip=$(get_docker_bridge_ip)
|
||||||
|
|
||||||
echo "start_dnet parsed values: " ${inst} ${suffix} ${name} ${hport} ${cport} ${hopt} ${store} ${labels}
|
echo "start_dnet parsed values: " ${inst} ${suffix} ${name} ${hport} ${cport} ${hopt} ${store}
|
||||||
|
|
||||||
mkdir -p /tmp/dnet/${name}
|
mkdir -p /tmp/dnet/${name}
|
||||||
tomlfile="/tmp/dnet/${name}/libnetwork.toml"
|
tomlfile="/tmp/dnet/${name}/libnetwork.toml"
|
||||||
|
|
||||||
# Try discovery URLs with or without path
|
# Try discovery URLs with or without path
|
||||||
|
neigh_ip=""
|
||||||
|
neighbors=""
|
||||||
if [ "$store" = "zookeeper" ]; then
|
if [ "$store" = "zookeeper" ]; then
|
||||||
read discovery provider address < <(parse_discovery_str zk://${bridge_ip}:2182)
|
read discovery provider address < <(parse_discovery_str zk://${bridge_ip}:2182)
|
||||||
elif [ "$store" = "etcd" ]; then
|
elif [ "$store" = "etcd" ]; then
|
||||||
read discovery provider address < <(parse_discovery_str etcd://${bridge_ip}:42000/custom_prefix)
|
read discovery provider address < <(parse_discovery_str etcd://${bridge_ip}:42000/custom_prefix)
|
||||||
else
|
elif [ "$store" = "consul" ]; then
|
||||||
read discovery provider address < <(parse_discovery_str consul://${bridge_ip}:8500/custom_prefix)
|
read discovery provider address < <(parse_discovery_str consul://${bridge_ip}:8500/custom_prefix)
|
||||||
|
else
|
||||||
|
if [ "$nip" != "" ]; then
|
||||||
|
neighbors="neighbors = [\"${nip}:7946\"]"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
discovery=""
|
||||||
|
provider=""
|
||||||
|
address=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$discovery" != "" ]; then
|
||||||
cat > ${tomlfile} <<EOF
|
cat > ${tomlfile} <<EOF
|
||||||
title = "LibNetwork Configuration file for ${name}"
|
title = "LibNetwork Configuration file for ${name}"
|
||||||
|
|
||||||
|
@ -166,9 +184,22 @@ title = "LibNetwork Configuration file for ${name}"
|
||||||
provider = "${provider}"
|
provider = "${provider}"
|
||||||
address = "${address}"
|
address = "${address}"
|
||||||
EOF
|
EOF
|
||||||
|
else
|
||||||
|
cat > ${tomlfile} <<EOF
|
||||||
|
title = "LibNetwork Configuration file for ${name}"
|
||||||
|
|
||||||
|
[daemon]
|
||||||
|
debug = false
|
||||||
|
isagent = true
|
||||||
|
bind = "eth0"
|
||||||
|
${neighbors}
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
cat ${tomlfile}
|
cat ${tomlfile}
|
||||||
docker run \
|
docker run \
|
||||||
-d \
|
-d \
|
||||||
|
--hostname=${name} \
|
||||||
--name=${name} \
|
--name=${name} \
|
||||||
--privileged \
|
--privileged \
|
||||||
-p ${hport}:${cport} \
|
-p ${hport}:${cport} \
|
||||||
|
@ -183,6 +214,19 @@ EOF
|
||||||
wait_for_dnet $(inst_id2port ${inst}) ${name}
|
wait_for_dnet $(inst_id2port ${inst}) ${name}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function start_ovrouter() {
|
||||||
|
local name=${1}
|
||||||
|
local parent=${2}
|
||||||
|
|
||||||
|
docker run \
|
||||||
|
-d \
|
||||||
|
--name=${name} \
|
||||||
|
--net=container:${parent} \
|
||||||
|
--volumes-from ${parent} \
|
||||||
|
-w /go/src/github.com/docker/libnetwork \
|
||||||
|
mrjana/golang ./cmd/ovrouter/ovrouter eth0
|
||||||
|
}
|
||||||
|
|
||||||
function skip_for_circleci() {
|
function skip_for_circleci() {
|
||||||
if [ -n "$CIRCLECI" ]; then
|
if [ -n "$CIRCLECI" ]; then
|
||||||
skip
|
skip
|
||||||
|
|
58
libnetwork/test/integration/dnet/overlay-local.bats
Normal file
58
libnetwork/test/integration/dnet/overlay-local.bats
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
# -*- mode: sh -*-
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
load helpers
|
||||||
|
|
||||||
|
function test_overlay_local() {
|
||||||
|
dnet_suffix=$1
|
||||||
|
|
||||||
|
echo $(docker ps)
|
||||||
|
|
||||||
|
start=1
|
||||||
|
end=3
|
||||||
|
for i in `seq ${start} ${end}`;
|
||||||
|
do
|
||||||
|
echo "iteration count ${i}"
|
||||||
|
dnet_cmd $(inst_id2port $i) network create -d overlay --id=mhid --subnet=10.1.0.0/16 --ip-range=10.1.${i}.0/24 --opt=com.docker.network.driver.overlay.vxlanid_list=1024 multihost
|
||||||
|
dnet_cmd $(inst_id2port $i) container create container_${i}
|
||||||
|
net_connect ${i} container_${i} multihost
|
||||||
|
done
|
||||||
|
|
||||||
|
# Now test connectivity between all the containers using service names
|
||||||
|
for i in `seq ${start} ${end}`;
|
||||||
|
do
|
||||||
|
if [ -z "${2}" -o "${2}" != "internal" ]; then
|
||||||
|
runc $(dnet_container_name $i $dnet_suffix) $(get_sbox_id ${i} container_${i}) \
|
||||||
|
"ping -c 1 www.google.com"
|
||||||
|
else
|
||||||
|
default_route=`runc $(dnet_container_name $i $dnet_suffix) $(get_sbox_id ${i} container_${i}) "ip route | grep default"`
|
||||||
|
[ "$default_route" = "" ]
|
||||||
|
fi
|
||||||
|
for j in `seq ${start} ${end}`;
|
||||||
|
do
|
||||||
|
if [ "$i" -eq "$j" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
#runc $(dnet_container_name $i $dnet_suffix) $(get_sbox_id ${i} container_${i}) "ping -c 1 10.1.${j}.1"
|
||||||
|
runc $(dnet_container_name $i $dnet_suffix) $(get_sbox_id ${i} container_${i}) "ping -c 1 container_${j}"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
# Teardown the container connections and the network
|
||||||
|
for i in `seq ${start} ${end}`;
|
||||||
|
do
|
||||||
|
net_disconnect ${i} container_${i} multihost
|
||||||
|
dnet_cmd $(inst_id2port $i) container rm container_${i}
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "${2}" -o "${2}" != "skip_rm" ]; then
|
||||||
|
dnet_cmd $(inst_id2port 2) network rm multihost
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Test overlay network in local scope" {
|
||||||
|
skip_for_circleci
|
||||||
|
test_overlay_local local
|
||||||
|
}
|
||||||
|
|
||||||
|
#"ping -c 1 10.1.${j}.1"
|
|
@ -34,6 +34,28 @@ function run_bridge_tests() {
|
||||||
unset cmap[dnet-1-bridge]
|
unset cmap[dnet-1-bridge]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function run_overlay_local_tests() {
|
||||||
|
## Test overlay network in local scope
|
||||||
|
## Setup
|
||||||
|
start_dnet 1 local 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
|
cmap[dnet-1-local]=dnet-1-local
|
||||||
|
start_dnet 2 local:$(dnet_container_ip 1 local) 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
|
cmap[dnet-2-local]=dnet-2-local
|
||||||
|
start_dnet 3 local:$(dnet_container_ip 1 local) 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
|
cmap[dnet-3-local]=dnet-3-local
|
||||||
|
|
||||||
|
## Run the test cases
|
||||||
|
./integration-tmp/bin/bats ./test/integration/dnet/overlay-local.bats
|
||||||
|
|
||||||
|
## Teardown
|
||||||
|
stop_dnet 1 local 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
|
unset cmap[dnet-1-local]
|
||||||
|
stop_dnet 2 local 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
|
unset cmap[dnet-2-local]
|
||||||
|
stop_dnet 3 local 1>>${INTEGRATION_ROOT}/test.log 2>&1
|
||||||
|
unset cmap[dnet-3-local]
|
||||||
|
}
|
||||||
|
|
||||||
function run_overlay_consul_tests() {
|
function run_overlay_consul_tests() {
|
||||||
## Test overlay network with consul
|
## Test overlay network with consul
|
||||||
## Setup
|
## Setup
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue