- Moved label definitions to a new package
- Added a network scope well-defined label to enable ipv6 Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
parent
1402220ec3
commit
c9b54861e7
11 changed files with 62 additions and 52 deletions
|
@ -29,7 +29,7 @@ There are many networking solutions available to suit a broad range of use-cases
|
|||
|
||||
driverOptions := options.Generic{}
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = driverOptions
|
||||
genericOption[netlabel.GenericData] = driverOptions
|
||||
err := controller.ConfigureNetworkDriver(networkType, genericOption)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -64,7 +64,7 @@ There are many networking solutions available to suit a broad range of use-cases
|
|||
|
||||
// libentwork client can check the endpoint's operational data via the Info() API
|
||||
epInfo, err := ep.Info()
|
||||
mapData, ok := epInfo[options.PortMap]
|
||||
mapData, ok := epInfo[netlabel.PortMap]
|
||||
if ok {
|
||||
portMapping, ok := mapData.([]netutils.PortBinding)
|
||||
if ok {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/docker/libnetwork"
|
||||
"github.com/docker/libnetwork/netutils"
|
||||
"github.com/docker/libnetwork/pkg/netlabel"
|
||||
"github.com/docker/libnetwork/pkg/options"
|
||||
)
|
||||
|
||||
|
@ -17,7 +18,7 @@ func main() {
|
|||
|
||||
driverOptions := options.Generic{}
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = driverOptions
|
||||
genericOption[netlabel.GenericData] = driverOptions
|
||||
err := controller.ConfigureNetworkDriver(networkType, genericOption)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -52,7 +53,7 @@ func main() {
|
|||
|
||||
// libentwork client can check the endpoint's operational data via the Info() API
|
||||
epInfo, err := ep.Info()
|
||||
mapData, ok := epInfo[options.PortMap]
|
||||
mapData, ok := epInfo[netlabel.PortMap]
|
||||
if ok {
|
||||
portMapping, ok := mapData.([]netutils.PortBinding)
|
||||
if ok {
|
||||
|
|
|
@ -10,7 +10,7 @@ create network namespaces and allocate interfaces for containers to use.
|
|||
|
||||
driverOptions := options.Generic{}
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = driverOptions
|
||||
genericOption[netlabel.GenericData] = driverOptions
|
||||
err := controller.ConfigureNetworkDriver(networkType, genericOption)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/docker/libnetwork/driverapi"
|
||||
"github.com/docker/libnetwork/ipallocator"
|
||||
"github.com/docker/libnetwork/netutils"
|
||||
"github.com/docker/libnetwork/pkg/netlabel"
|
||||
"github.com/docker/libnetwork/pkg/options"
|
||||
"github.com/docker/libnetwork/portmapper"
|
||||
"github.com/docker/libnetwork/sandbox"
|
||||
|
@ -156,7 +157,7 @@ func (d *driver) Config(option map[string]interface{}) error {
|
|||
return ErrConfigExists
|
||||
}
|
||||
|
||||
genericData := option[options.GenericData]
|
||||
genericData := option[netlabel.GenericData]
|
||||
if genericData != nil {
|
||||
switch opt := genericData.(type) {
|
||||
case options.Generic:
|
||||
|
@ -617,11 +618,11 @@ func (d *driver) EndpointInfo(nid, eid types.UUID) (map[string]interface{}, erro
|
|||
for _, pm := range ep.portMapping {
|
||||
pmc = append(pmc, pm.GetCopy())
|
||||
}
|
||||
m[options.PortMap] = pmc
|
||||
m[netlabel.PortMap] = pmc
|
||||
}
|
||||
|
||||
if len(ep.macAddress) != 0 {
|
||||
m[options.MacAddress] = ep.macAddress
|
||||
m[netlabel.MacAddress] = ep.macAddress
|
||||
}
|
||||
|
||||
return m, nil
|
||||
|
@ -762,7 +763,7 @@ func parseEndpointOptions(epOptions map[string]interface{}) (*EndpointConfigurat
|
|||
|
||||
ec := &EndpointConfiguration{}
|
||||
|
||||
if opt, ok := epOptions[options.MacAddress]; ok {
|
||||
if opt, ok := epOptions[netlabel.MacAddress]; ok {
|
||||
if mac, ok := opt.(net.HardwareAddr); ok {
|
||||
ec.MacAddress = mac
|
||||
} else {
|
||||
|
@ -770,7 +771,7 @@ func parseEndpointOptions(epOptions map[string]interface{}) (*EndpointConfigurat
|
|||
}
|
||||
}
|
||||
|
||||
if opt, ok := epOptions[options.PortMap]; ok {
|
||||
if opt, ok := epOptions[netlabel.PortMap]; ok {
|
||||
if bs, ok := opt.([]netutils.PortBinding); ok {
|
||||
ec.PortBindings = bs
|
||||
} else {
|
||||
|
@ -778,7 +779,7 @@ func parseEndpointOptions(epOptions map[string]interface{}) (*EndpointConfigurat
|
|||
}
|
||||
}
|
||||
|
||||
if opt, ok := epOptions[options.ExposedPorts]; ok {
|
||||
if opt, ok := epOptions[netlabel.ExposedPorts]; ok {
|
||||
if ports, ok := opt.([]netutils.TransportPort); ok {
|
||||
ec.ExposedPorts = ports
|
||||
} else {
|
||||
|
@ -793,7 +794,7 @@ func parseContainerOptions(cOptions map[string]interface{}) (*ContainerConfigura
|
|||
if cOptions == nil {
|
||||
return nil, nil
|
||||
}
|
||||
genericData := cOptions[options.GenericData]
|
||||
genericData := cOptions[netlabel.GenericData]
|
||||
if genericData == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
"github.com/docker/docker/pkg/iptables"
|
||||
"github.com/docker/libnetwork/netutils"
|
||||
"github.com/docker/libnetwork/pkg/options"
|
||||
"github.com/docker/libnetwork/pkg/netlabel"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
|
@ -26,7 +26,7 @@ func TestCreateFullOptions(t *testing.T) {
|
|||
}
|
||||
_, config.FixedCIDRv6, _ = net.ParseCIDR("2001:db8::/48")
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = config
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.Config(genericOption); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
|
@ -44,7 +44,7 @@ func TestCreate(t *testing.T) {
|
|||
|
||||
config := &Configuration{BridgeName: DefaultBridgeName}
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = config
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.Config(genericOption); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
|
@ -61,7 +61,7 @@ func TestCreateFail(t *testing.T) {
|
|||
|
||||
config := &Configuration{BridgeName: "dummy0"}
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = config
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.Config(genericOption); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
|
@ -83,7 +83,7 @@ func TestQueryEndpointInfo(t *testing.T) {
|
|||
EnableICC: false,
|
||||
}
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = config
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.Config(genericOption); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
|
@ -96,7 +96,7 @@ func TestQueryEndpointInfo(t *testing.T) {
|
|||
|
||||
portMappings := getPortMapping()
|
||||
epOptions := make(map[string]interface{})
|
||||
epOptions[options.PortMap] = portMappings
|
||||
epOptions[netlabel.PortMap] = portMappings
|
||||
|
||||
_, err = d.CreateEndpoint("net1", "ep1", epOptions)
|
||||
if err != nil {
|
||||
|
@ -109,7 +109,7 @@ func TestQueryEndpointInfo(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Failed to ask for endpoint operational data: %v", err)
|
||||
}
|
||||
pmd, ok := data[options.PortMap]
|
||||
pmd, ok := data[netlabel.PortMap]
|
||||
if !ok {
|
||||
t.Fatalf("Endpoint operational data does not contain port mapping data")
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ func TestCreateLinkWithOptions(t *testing.T) {
|
|||
|
||||
config := &Configuration{BridgeName: DefaultBridgeName}
|
||||
driverOptions := make(map[string]interface{})
|
||||
driverOptions[options.GenericData] = config
|
||||
driverOptions[netlabel.GenericData] = config
|
||||
|
||||
if err := d.Config(driverOptions); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
|
@ -153,7 +153,7 @@ func TestCreateLinkWithOptions(t *testing.T) {
|
|||
|
||||
mac := net.HardwareAddr([]byte{0x1e, 0x67, 0x66, 0x44, 0x55, 0x66})
|
||||
epOptions := make(map[string]interface{})
|
||||
epOptions[options.MacAddress] = mac
|
||||
epOptions[netlabel.MacAddress] = mac
|
||||
|
||||
sinfo, err := d.CreateEndpoint("net1", "ep", epOptions)
|
||||
if err != nil {
|
||||
|
@ -198,7 +198,7 @@ func TestLinkContainers(t *testing.T) {
|
|||
EnableICC: false,
|
||||
}
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = config
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.Config(genericOption); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
|
@ -211,7 +211,7 @@ func TestLinkContainers(t *testing.T) {
|
|||
|
||||
exposedPorts := getExposedPorts()
|
||||
epOptions := make(map[string]interface{})
|
||||
epOptions[options.ExposedPorts] = exposedPorts
|
||||
epOptions[netlabel.ExposedPorts] = exposedPorts
|
||||
|
||||
sinfo, err := d.CreateEndpoint("net1", "ep1", epOptions)
|
||||
if err != nil {
|
||||
|
@ -236,7 +236,7 @@ func TestLinkContainers(t *testing.T) {
|
|||
ce := []string{"ep1"}
|
||||
cConfig := &ContainerConfiguration{ChildEndpoints: ce}
|
||||
genericOption = make(map[string]interface{})
|
||||
genericOption[options.GenericData] = cConfig
|
||||
genericOption[netlabel.GenericData] = cConfig
|
||||
|
||||
_, err = d.Join("net1", "ep2", "", genericOption)
|
||||
if err != nil {
|
||||
|
@ -284,7 +284,7 @@ func TestLinkContainers(t *testing.T) {
|
|||
ce = []string{"ep1", "ep4"}
|
||||
cConfig = &ContainerConfiguration{ChildEndpoints: ce}
|
||||
genericOption = make(map[string]interface{})
|
||||
genericOption[options.GenericData] = cConfig
|
||||
genericOption[netlabel.GenericData] = cConfig
|
||||
|
||||
_, err = d.Join("net1", "ep2", "", genericOption)
|
||||
if err != nil {
|
||||
|
@ -415,7 +415,7 @@ func TestSetDefaultGw(t *testing.T) {
|
|||
}
|
||||
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = config
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.Config(genericOption); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
|
||||
"github.com/docker/libnetwork/driverapi"
|
||||
"github.com/docker/libnetwork/netutils"
|
||||
"github.com/docker/libnetwork/pkg/options"
|
||||
"github.com/docker/libnetwork/pkg/netlabel"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
|
@ -21,7 +21,7 @@ func TestLinkCreate(t *testing.T) {
|
|||
EnableIPv6: true,
|
||||
}
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = config
|
||||
genericOption[netlabel.GenericData] = config
|
||||
if err := d.Config(genericOption); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func TestLinkCreateTwo(t *testing.T) {
|
|||
BridgeName: DefaultBridgeName,
|
||||
EnableIPv6: true}
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = config
|
||||
genericOption[netlabel.GenericData] = config
|
||||
if err := d.Config(genericOption); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ func TestLinkCreateNoEnableIPv6(t *testing.T) {
|
|||
config := &Configuration{
|
||||
BridgeName: DefaultBridgeName}
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = config
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.Config(genericOption); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
|
@ -172,7 +172,7 @@ func TestLinkDelete(t *testing.T) {
|
|||
BridgeName: DefaultBridgeName,
|
||||
EnableIPv6: true}
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = config
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.Config(genericOption); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
"github.com/docker/docker/pkg/reexec"
|
||||
"github.com/docker/libnetwork/netutils"
|
||||
"github.com/docker/libnetwork/pkg/options"
|
||||
"github.com/docker/libnetwork/pkg/netlabel"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
@ -25,14 +25,14 @@ func TestPortMappingConfig(t *testing.T) {
|
|||
portBindings := []netutils.PortBinding{binding1, binding2}
|
||||
|
||||
epOptions := make(map[string]interface{})
|
||||
epOptions[options.PortMap] = portBindings
|
||||
epOptions[netlabel.PortMap] = portBindings
|
||||
|
||||
driverConfig := &Configuration{
|
||||
BridgeName: DefaultBridgeName,
|
||||
EnableIPTables: true,
|
||||
}
|
||||
driverOptions := make(map[string]interface{})
|
||||
driverOptions[options.GenericData] = driverConfig
|
||||
driverOptions[netlabel.GenericData] = driverConfig
|
||||
|
||||
if err := d.Config(driverOptions); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/docker/docker/pkg/resolvconf"
|
||||
"github.com/docker/libnetwork/driverapi"
|
||||
"github.com/docker/libnetwork/netutils"
|
||||
"github.com/docker/libnetwork/pkg/options"
|
||||
"github.com/docker/libnetwork/pkg/netlabel"
|
||||
"github.com/docker/libnetwork/sandbox"
|
||||
"github.com/docker/libnetwork/types"
|
||||
)
|
||||
|
@ -504,7 +504,7 @@ func CreateOptionExposedPorts(exposedPorts []netutils.TransportPort) EndpointOpt
|
|||
copy(eps, exposedPorts)
|
||||
// Store endpoint label and in generic because driver needs it
|
||||
ep.exposedPorts = eps
|
||||
ep.generic[options.ExposedPorts] = eps
|
||||
ep.generic[netlabel.ExposedPorts] = eps
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -515,7 +515,7 @@ func CreateOptionPortMapping(portBindings []netutils.PortBinding) EndpointOption
|
|||
// Store a copy of the bindings as generic data to pass to the driver
|
||||
pbs := make([]netutils.PortBinding, len(portBindings))
|
||||
copy(pbs, portBindings)
|
||||
ep.generic[options.PortMap] = pbs
|
||||
ep.generic[netlabel.PortMap] = pbs
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/docker/docker/pkg/reexec"
|
||||
"github.com/docker/libnetwork"
|
||||
"github.com/docker/libnetwork/netutils"
|
||||
"github.com/docker/libnetwork/pkg/netlabel"
|
||||
"github.com/docker/libnetwork/pkg/options"
|
||||
)
|
||||
|
||||
|
@ -27,7 +28,7 @@ func TestMain(m *testing.M) {
|
|||
func createTestNetwork(networkType, networkName string, option options.Generic) (libnetwork.Network, error) {
|
||||
controller := libnetwork.New()
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = option
|
||||
genericOption[netlabel.GenericData] = option
|
||||
|
||||
err := controller.ConfigureNetworkDriver(networkType, genericOption)
|
||||
if err != nil {
|
||||
|
@ -44,7 +45,7 @@ func createTestNetwork(networkType, networkName string, option options.Generic)
|
|||
|
||||
func getEmptyGenericOption() map[string]interface{} {
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = options.Generic{}
|
||||
genericOption[netlabel.GenericData] = options.Generic{}
|
||||
return genericOption
|
||||
}
|
||||
|
||||
|
@ -170,7 +171,7 @@ func TestBridge(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pmd, ok := epInfo[options.PortMap]
|
||||
pmd, ok := epInfo[netlabel.PortMap]
|
||||
if !ok {
|
||||
t.Fatalf("Could not find expected info in endpoint data")
|
||||
}
|
||||
|
@ -237,7 +238,7 @@ func TestDuplicateNetwork(t *testing.T) {
|
|||
controller := libnetwork.New()
|
||||
|
||||
genericOption := make(map[string]interface{})
|
||||
genericOption[options.GenericData] = options.Generic{}
|
||||
genericOption[netlabel.GenericData] = options.Generic{}
|
||||
|
||||
err := controller.ConfigureNetworkDriver(bridgeNetType, genericOption)
|
||||
if err != nil {
|
||||
|
|
18
libnetwork/pkg/netlabel/labels.go
Normal file
18
libnetwork/pkg/netlabel/labels.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package netlabel
|
||||
|
||||
const (
|
||||
// GenericData constant that helps to identify an option as a Generic constant
|
||||
GenericData = "io.docker.network.generic"
|
||||
|
||||
// PortMap constant represents Port Mapping
|
||||
PortMap = "io.docker.network.endpoint.portmap"
|
||||
|
||||
// MacAddress constant represents Mac Address config of a Container
|
||||
MacAddress = "io.docker.network.endpoint.macaddress"
|
||||
|
||||
// ExposedPorts constant represents exposedports of a Container
|
||||
ExposedPorts = "io.docker.network.endpoint.exposedports"
|
||||
|
||||
//EnableIPv6 constant represents enabling IPV6 at network level
|
||||
EnableIPv6 = "io.docker.network.enable_ipv6"
|
||||
)
|
|
@ -7,17 +7,6 @@ import (
|
|||
"reflect"
|
||||
)
|
||||
|
||||
const (
|
||||
// GenericData constant that helps to identify an option as a Generic constant
|
||||
GenericData = "io.docker.network.generic"
|
||||
// PortMap constant represents Port Mapping
|
||||
PortMap = "io.docker.network.endpoint.portmap"
|
||||
// MacAddress constant represents Mac Address config of a Container
|
||||
MacAddress = "io.docker.network.endpoint.macaddress"
|
||||
// ExposedPorts constant represents exposedports of a Container
|
||||
ExposedPorts = "io.docker.network.endpoint.exposedports"
|
||||
)
|
||||
|
||||
// NoSuchFieldError is the error returned when the generic parameters hold a
|
||||
// value for a field absent from the destination structure.
|
||||
type NoSuchFieldError struct {
|
||||
|
|
Loading…
Reference in a new issue