1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

support for libnetwork daemon labels

Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
Madhu Venugopal 2015-06-14 09:03:42 -07:00
parent 4329f8d185
commit 613e60bcec
3 changed files with 46 additions and 5 deletions

View file

@ -4,6 +4,7 @@ import (
"strings"
"github.com/BurntSushi/toml"
"github.com/docker/libnetwork/netlabel"
)
// Config encapsulates configurations of various Libnetwork components
@ -18,6 +19,7 @@ type DaemonCfg struct {
Debug bool
DefaultNetwork string
DefaultDriver string
Labels []string
}
// ClusterCfg represents cluster configuration
@ -66,6 +68,17 @@ func OptionDefaultDriver(dd string) Option {
}
}
// OptionLabels function returns an option setter for labels
func OptionLabels(labels []string) Option {
return func(c *Config) {
for _, label := range labels {
if strings.HasPrefix(label, netlabel.Prefix) {
c.Daemon.Labels = append(c.Daemon.Labels, label)
}
}
}
}
// OptionKVProvider function returns an option setter for kvstore provider
func OptionKVProvider(provider string) Option {
return func(c *Config) {

View file

@ -1,8 +1,10 @@
package config
import (
"strings"
"testing"
"github.com/docker/libnetwork/netlabel"
_ "github.com/docker/libnetwork/netutils"
)
@ -19,3 +21,23 @@ func TestConfig(t *testing.T) {
t.Fatal("Error parsing a valid configuration file :", err)
}
}
func TestOptionsLabels(t *testing.T) {
c := &Config{}
l := []string{
"com.docker.network.key1=value1",
"com.docker.storage.key1=value1",
"com.docker.network.driver.key1=value1",
"com.docker.network.driver.key2=value2",
}
f := OptionLabels(l)
f(c)
if len(c.Daemon.Labels) != 3 {
t.Fatalf("Expecting 3 labels, seen %d", len(c.Daemon.Labels))
}
for _, l := range c.Daemon.Labels {
if !strings.HasPrefix(l, netlabel.Prefix) {
t.Fatalf("config must accept only libnetwork labels. Not : %s", l)
}
}
}

View file

@ -1,18 +1,24 @@
package netlabel
const (
// Prefix constant marks the reserved label space for libnetwork
Prefix = "com.docker.network"
// DriverPrefix constant marks the reserved label space for libnetwork drivers
DriverPrefix = Prefix + ".driver"
// GenericData constant that helps to identify an option as a Generic constant
GenericData = "io.docker.network.generic"
GenericData = Prefix + ".generic"
// PortMap constant represents Port Mapping
PortMap = "io.docker.network.endpoint.portmap"
PortMap = Prefix + ".portmap"
// MacAddress constant represents Mac Address config of a Container
MacAddress = "io.docker.network.endpoint.macaddress"
MacAddress = Prefix + ".endpoint.macaddress"
// ExposedPorts constant represents exposedports of a Container
ExposedPorts = "io.docker.network.endpoint.exposedports"
ExposedPorts = Prefix + ".endpoint.exposedports"
//EnableIPv6 constant represents enabling IPV6 at network level
EnableIPv6 = "io.docker.network.enable_ipv6"
EnableIPv6 = Prefix + ".enable_ipv6"
)