Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func resolveAddr(addrOrInterface string) (string, error) {
}

func (c *controller) agentInit(bindAddrOrInterface string) error {
if !c.cfg.Daemon.IsAgent {
if !c.isAgent() {
return nil
}

Expand Down Expand Up @@ -94,12 +94,12 @@ func (c *controller) agentInit(bindAddrOrInterface string) error {
return nil
}

func (c *controller) agentJoin(remotes []string) error {
func (c *controller) agentJoin(remote string) error {
if c.agent == nil {
return nil
}

return c.agent.networkDB.Join(remotes)
return c.agent.networkDB.Join([]string{remote})
}

func (c *controller) agentDriverNotify(d driverapi.Driver) {
Expand All @@ -126,6 +126,7 @@ func (c *controller) agentClose() {
c.agent.epTblCancel()

c.agent.networkDB.Close()
c.agent = nil
}

func (n *network) isClusterEligible() bool {
Expand Down
10 changes: 10 additions & 0 deletions cluster/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cluster

// Provider provides clustering config details
type Provider interface {
IsManager() bool
IsAgent() bool
GetListenAddress() string
GetRemoteAddress() string
ListenClusterEvents() <-chan struct{}
}
73 changes: 60 additions & 13 deletions cmd/dnet/dnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"syscall"
"time"

"github.com/BurntSushi/toml"
"github.com/codegangsta/cli"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/discovery"
Expand Down Expand Up @@ -64,13 +65,31 @@ func main() {
}
}

func parseConfig(cfgFile string) (*config.Config, error) {
// ParseConfig parses the libnetwork configuration file
func (d *dnetConnection) parseOrchestrationConfig(tomlCfgFile string) error {
dummy := &dnetConnection{}

if _, err := toml.DecodeFile(tomlCfgFile, dummy); err != nil {
return err
}

if dummy.Orchestration != nil {
d.Orchestration = dummy.Orchestration
}
return nil
}

func (d *dnetConnection) parseConfig(cfgFile string) (*config.Config, error) {
if strings.Trim(cfgFile, " ") == "" {
cfgFile = os.Getenv(cfgFileEnv)
if strings.Trim(cfgFile, " ") == "" {
cfgFile = defaultCfgFile
}
}

if err := d.parseOrchestrationConfig(cfgFile); err != nil {
return nil, err
}
return config.ParseConfig(cfgFile)
}

Expand All @@ -91,15 +110,6 @@ func processConfig(cfg *config.Config) []config.Option {
dd = cfg.Daemon.DefaultDriver
}
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 {
options = append(options, config.OptionLabels(cfg.Daemon.Labels))
Expand Down Expand Up @@ -220,18 +230,30 @@ type dnetConnection struct {
// proto holds the client protocol i.e. unix.
proto string
// addr holds the client address.
addr string
addr string
Orchestration *NetworkOrchestration
configEvent chan struct{}
}

// NetworkOrchestration exported
type NetworkOrchestration struct {
Agent bool
Manager bool
Bind string
Peer string
}

func (d *dnetConnection) dnetDaemon(cfgFile string) error {
if err := startTestDriver(); err != nil {
return fmt.Errorf("failed to start test driver: %v\n", err)
}

cfg, err := parseConfig(cfgFile)
cfg, err := d.parseConfig(cfgFile)
var cOptions []config.Option
if err == nil {
cOptions = processConfig(cfg)
} else {
logrus.Errorf("Error parsing config %v", err)
}

bridgeConfig := options.Generic{
Expand All @@ -248,6 +270,11 @@ func (d *dnetConnection) dnetDaemon(cfgFile string) error {
fmt.Println("Error starting dnetDaemon :", err)
return err
}
controller.SetClusterProvider(d)

if d.Orchestration.Agent || d.Orchestration.Manager {
d.configEvent <- struct{}{}
}

createDefaultNetwork(controller)
httpHandler := api.NewHTTPHandler(controller)
Expand All @@ -271,6 +298,26 @@ func (d *dnetConnection) dnetDaemon(cfgFile string) error {
return http.ListenAndServe(d.addr, r)
}

func (d *dnetConnection) IsManager() bool {
return d.Orchestration.Manager
}

func (d *dnetConnection) IsAgent() bool {
return d.Orchestration.Agent
}

func (d *dnetConnection) GetListenAddress() string {
return d.Orchestration.Bind
}

func (d *dnetConnection) GetRemoteAddress() string {
return d.Orchestration.Peer
}

func (d *dnetConnection) ListenClusterEvents() <-chan struct{} {
return d.configEvent
}

func handleSignals(controller libnetwork.NetworkController) {
c := make(chan os.Signal, 1)
signals := []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT}
Expand Down Expand Up @@ -354,7 +401,7 @@ func newDnetConnection(val string) (*dnetConnection, error) {
return nil, fmt.Errorf("dnet currently only supports tcp transport")
}

return &dnetConnection{protoAddrParts[0], protoAddrParts[1]}, nil
return &dnetConnection{protoAddrParts[0], protoAddrParts[1], &NetworkOrchestration{}, make(chan struct{}, 10)}, nil
}

func (d *dnetConnection) httpCall(method, path string, data interface{}, headers map[string][]string) (io.ReadCloser, http.Header, int, error) {
Expand Down
3 changes: 3 additions & 0 deletions cmd/dnet/libnetwork.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ title = "LibNetwork Configuration file"
[datastore.client]
provider = "consul"
Address = "localhost:8500"
[orchestration]
agent = true
peer="2.2.2.2"
38 changes: 8 additions & 30 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/docker/docker/pkg/discovery"
"github.com/docker/docker/pkg/tlsconfig"
"github.com/docker/libkv/store"
"github.com/docker/libnetwork/cluster"
"github.com/docker/libnetwork/datastore"
"github.com/docker/libnetwork/netlabel"
)
Expand All @@ -21,15 +22,13 @@ type Config struct {

// DaemonCfg represents libnetwork core configuration
type DaemonCfg struct {
Debug bool
IsAgent bool
DataDir string
DefaultNetwork string
DefaultDriver string
Bind string
Neighbors []string
Labels []string
DriverCfg map[string]interface{}
Debug bool
DataDir string
DefaultNetwork string
DefaultDriver string
Labels []string
DriverCfg map[string]interface{}
ClusterProvider cluster.Provider
}

// ClusterCfg represents cluster configuration
Expand Down Expand Up @@ -84,27 +83,6 @@ func ParseConfigOptions(cfgOptions ...Option) *Config {
// to the controller
type Option func(c *Config)

// OptionBind function returns an option setter for setting a bind interface or address
func OptionBind(bind string) Option {
return func(c *Config) {
c.Daemon.Bind = bind
}
}

// OptionAgent function returns an option setter for setting agent mode
func OptionAgent() Option {
return func(c *Config) {
c.Daemon.IsAgent = true
}
}

// OptionNeighbors function returns an option setter for setting a list of neighbors to join.
func OptionNeighbors(neighbors []string) Option {
return func(c *Config) {
c.Daemon.Neighbors = neighbors
}
}

// OptionDefaultNetwork function returns an option setter for a default network
func OptionDefaultNetwork(dn string) Option {
return func(c *Config) {
Expand Down
Loading