Skip to content

Commit 33e9d70

Browse files
author
Arnaud Porterie
committed
Merge pull request #16718 from mavenugo/discovery
Vendoring libnetwork integrated with Docker discovery service
2 parents 80f2e3f + 139ea5b commit 33e9d70

29 files changed

Lines changed: 1148 additions & 210 deletions

daemon/daemon.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,17 @@ func NewDaemon(config *Config, registryService *registry.Service) (daemon *Daemo
751751
}
752752
}
753753

754-
d.netController, err = initNetworkController(config)
754+
// Discovery is only enabled when the daemon is launched with an address to advertise. When
755+
// initialized, the daemon is registered and we can store the discovery backend as its read-only
756+
// DiscoveryWatcher version.
757+
if config.ClusterStore != "" && config.ClusterAdvertise != "" {
758+
var err error
759+
if d.discoveryWatcher, err = initDiscovery(config.ClusterStore, config.ClusterAdvertise); err != nil {
760+
return nil, fmt.Errorf("discovery initialization failed (%v)", err)
761+
}
762+
}
763+
764+
d.netController, err = d.initNetworkController(config)
755765
if err != nil {
756766
return nil, fmt.Errorf("Error initializing network controller: %v", err)
757767
}
@@ -785,16 +795,6 @@ func NewDaemon(config *Config, registryService *registry.Service) (daemon *Daemo
785795
return nil, err
786796
}
787797

788-
// Discovery is only enabled when the daemon is launched with an address to advertise. When
789-
// initialized, the daemon is registered and we can store the discovery backend as its read-only
790-
// DiscoveryWatcher version.
791-
if config.ClusterStore != "" && config.ClusterAdvertise != "" {
792-
var err error
793-
if d.discoveryWatcher, err = initDiscovery(config.ClusterStore, config.ClusterAdvertise); err != nil {
794-
return nil, fmt.Errorf("discovery initialization failed (%v)", err)
795-
}
796-
}
797-
798798
d.ID = trustKey.PublicKey().KeyID()
799799
d.repository = daemonRepo
800800
d.containers = &contStore{s: make(map[string]*Container)}

daemon/daemon_unix.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func isBridgeNetworkDisabled(config *Config) bool {
302302
return config.Bridge.Iface == disableNetworkBridge
303303
}
304304

305-
func networkOptions(dconfig *Config) ([]nwconfig.Option, error) {
305+
func (daemon *Daemon) networkOptions(dconfig *Config) ([]nwconfig.Option, error) {
306306
options := []nwconfig.Option{}
307307
if dconfig == nil {
308308
return options, nil
@@ -330,13 +330,21 @@ func networkOptions(dconfig *Config) ([]nwconfig.Option, error) {
330330
options = append(options, nwconfig.OptionKVProviderURL(strings.Join(kv[1:], "://")))
331331
}
332332

333+
if daemon.discoveryWatcher != nil {
334+
options = append(options, nwconfig.OptionDiscoveryWatcher(daemon.discoveryWatcher))
335+
}
336+
337+
if dconfig.ClusterAdvertise != "" {
338+
options = append(options, nwconfig.OptionDiscoveryAddress(dconfig.ClusterAdvertise))
339+
}
340+
333341
options = append(options, nwconfig.OptionLabels(dconfig.Labels))
334342
options = append(options, driverOptions(dconfig)...)
335343
return options, nil
336344
}
337345

338-
func initNetworkController(config *Config) (libnetwork.NetworkController, error) {
339-
netOptions, err := networkOptions(config)
346+
func (daemon *Daemon) initNetworkController(config *Config) (libnetwork.NetworkController, error) {
347+
netOptions, err := daemon.networkOptions(config)
340348
if err != nil {
341349
return nil, err
342350
}

daemon/daemon_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func isBridgeNetworkDisabled(config *Config) bool {
9898
return false
9999
}
100100

101-
func initNetworkController(config *Config) (libnetwork.NetworkController, error) {
101+
func (daemon *Daemon) initNetworkController(config *Config) (libnetwork.NetworkController, error) {
102102
// Set the name of the virtual switch if not specified by -b on daemon start
103103
if config.Bridge.VirtualSwitchName == "" {
104104
config.Bridge.VirtualSwitchName = defaultVirtualSwitch

hack/vendor.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ clone git github.com/tchap/go-patricia v2.1.0
2020
clone git golang.org/x/net 3cffabab72adf04f8e3b01c5baf775361837b5fe https://github.com/golang/net.git
2121

2222
#get libnetwork packages
23-
clone git github.com/docker/libnetwork 70409acbcd661e6a7bfe04e2b81412a465d29512
23+
clone git github.com/docker/libnetwork c3a9e0d8d0c53f3db251620e5f48470e267f292b
2424
clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
2525
clone git github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b
2626
clone git github.com/hashicorp/memberlist 9a1e242e454d2443df330bdd51a436d5a9058fc4
@@ -30,6 +30,7 @@ clone git github.com/vishvananda/netns 604eaf189ee867d8c147fafc28def2394e878d25
3030
clone git github.com/vishvananda/netlink 4b5dce31de6d42af5bb9811c6d265472199e0fec
3131
clone git github.com/BurntSushi/toml f706d00e3de6abe700c994cdd545a1a4915af060
3232
clone git github.com/samuel/go-zookeeper d0e0d8e11f318e000a8cc434616d69e329edc374
33+
clone git github.com/deckarep/golang-set ef32fa3046d9f249d399f98ebaf9be944430fd1d
3334
clone git github.com/coreos/go-etcd v2.0.0
3435
clone git github.com/hashicorp/consul v0.5.2
3536
clone git github.com/boltdb/bolt v1.0
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2+
*.o
3+
*.a
4+
*.so
5+
6+
# Folders
7+
_obj
8+
_test
9+
10+
# Architecture specific extensions/prefixes
11+
*.[568vq]
12+
[568vq].out
13+
14+
*.cgo1.go
15+
*.cgo2.c
16+
_cgo_defun.c
17+
_cgo_gotypes.go
18+
_cgo_export.*
19+
20+
_testmain.go
21+
22+
*.exe
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: go
2+
3+
go:
4+
- 1.2
5+
6+
script:
7+
- go test ./...
8+
#- go test -race ./...
9+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Open Source Initiative OSI - The MIT License (MIT):Licensing
2+
3+
The MIT License (MIT)
4+
Copyright (c) 2013 Ralph Caraveo ([email protected])
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
this software and associated documentation files (the "Software"), to deal in
8+
the Software without restriction, including without limitation the rights to
9+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10+
of the Software, and to permit persons to whom the Software is furnished to do
11+
so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[![Build Status](https://travis-ci.org/deckarep/golang-set.png?branch=master)](https://travis-ci.org/deckarep/golang-set)
2+
[![GoDoc](https://godoc.org/github.com/deckarep/golang-set?status.png)](http://godoc.org/github.com/deckarep/golang-set)
3+
4+
## golang-set
5+
6+
7+
The missing set collection for the Go language. Until Go has sets built-in...use this.
8+
9+
Coming from Python one of the things I miss is the superbly wonderful set collection. This is my attempt to mimic the primary features of the set from Python.
10+
You can of course argue that there is no need for a set in Go, otherwise the creators would have added one to the standard library. To those I say simply ignore this repository
11+
and carry-on and to the rest that find this useful please contribute in helping me make it better by:
12+
13+
* Helping to make more idiomatic improvements to the code.
14+
* Helping to increase the performance of it. ~~(So far, no attempt has been made, but since it uses a map internally, I expect it to be mostly performant.)~~
15+
* Helping to make the unit-tests more robust and kick-ass.
16+
* Helping to fill in the [documentation.](http://godoc.org/github.com/deckarep/golang-set)
17+
* Simply offering feedback and suggestions. (Positive, constructive feedback is appreciated.)
18+
19+
I have to give some credit for helping seed the idea with this post on [stackoverflow.](http://programmers.stackexchange.com/questions/177428/sets-data-structure-in-golang)
20+
21+
*Update* - as of 3/9/2014, you can use a compile-time generic version of this package in the [gen](http://clipperhouse.github.io/gen/) framework. This framework allows you to use the golang-set in a completely generic and type-safe way by allowing you to generate a supporting .go file based on your custom types.
22+
23+
## Features (as of 9/22/2014)
24+
25+
* a CartesionProduct() method has been added with unit-tests: [Read more about the cartesion product](http://en.wikipedia.org/wiki/Cartesian_product)
26+
27+
## Features (as of 9/15/2014)
28+
29+
* a PowerSet() method has been added with unit-tests: [Read more about the Power set](http://en.wikipedia.org/wiki/Power_set)
30+
31+
## Features (as of 4/22/2014)
32+
33+
* One common interface to both implementations
34+
* Two set implementations to choose from
35+
* a thread-safe implementation designed for concurrent use
36+
* a non-thread-safe implementation designed for performance
37+
* 75 benchmarks for both implementations
38+
* 35 unit tests for both implementations
39+
* 14 concurrent tests for the thread-safe implementation
40+
41+
42+
43+
Please see the unit test file for additional usage examples. The Python set documentation will also do a better job than I can of explaining how a set typically [works.](http://docs.python.org/2/library/sets.html) Please keep in mind
44+
however that the Python set is a built-in type and supports additional features and syntax that make it awesome.
45+
46+
## Examples but not exhaustive:
47+
48+
```go
49+
requiredClasses := mapset.NewSet()
50+
requiredClasses.Add("Cooking")
51+
requiredClasses.Add("English")
52+
requiredClasses.Add("Math")
53+
requiredClasses.Add("Biology")
54+
55+
scienceSlice := []interface{}{"Biology", "Chemistry"}
56+
scienceClasses := mapset.NewSetFromSlice(scienceSlice)
57+
58+
electiveClasses := mapset.NewSet()
59+
electiveClasses.Add("Welding")
60+
electiveClasses.Add("Music")
61+
electiveClasses.Add("Automotive")
62+
63+
bonusClasses := mapset.NewSet()
64+
bonusClasses.Add("Go Programming")
65+
bonusClasses.Add("Python Programming")
66+
67+
//Show me all the available classes I can take
68+
allClasses := requiredClasses.Union(scienceClasses).Union(electiveClasses).Union(bonusClasses)
69+
fmt.Println(allClasses) //Set{Cooking, English, Math, Chemistry, Welding, Biology, Music, Automotive, Go Programming, Python Programming}
70+
71+
72+
//Is cooking considered a science class?
73+
fmt.Println(scienceClasses.Contains("Cooking")) //false
74+
75+
//Show me all classes that are not science classes, since I hate science.
76+
fmt.Println(allClasses.Difference(scienceClasses)) //Set{Music, Automotive, Go Programming, Python Programming, Cooking, English, Math, Welding}
77+
78+
//Which science classes are also required classes?
79+
fmt.Println(scienceClasses.Intersect(requiredClasses)) //Set{Biology}
80+
81+
//How many bonus classes do you offer?
82+
fmt.Println(bonusClasses.Cardinality()) //2
83+
84+
//Do you have the following classes? Welding, Automotive and English?
85+
fmt.Println(allClasses.IsSuperset(mapset.NewSetFromSlice([]interface{}{"Welding", "Automotive", "English"}))) //true
86+
```
87+
88+
Thanks!
89+
90+
-Ralph
91+
92+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/deckarep/golang-set/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
93+
94+
[![Analytics](https://ga-beacon.appspot.com/UA-42584447-2/deckarep/golang-set)](https://github.com/igrigorik/ga-beacon)

0 commit comments

Comments
 (0)