- Add Endpoints() API to Sandbox interface
- Fixes #19677
Signed-off-by: Madhu Venugopal <madhu@docker.com>
| ... | ... |
@@ -27,7 +27,7 @@ clone git github.com/RackSec/srslog 6eb773f331e46fbba8eecb8e794e635e75fc04de |
| 27 | 27 |
clone git github.com/imdario/mergo 0.2.1 |
| 28 | 28 |
|
| 29 | 29 |
#get libnetwork packages |
| 30 |
-clone git github.com/docker/libnetwork v0.6.0-rc3 |
|
| 30 |
+clone git github.com/docker/libnetwork v0.6.0-rc4 |
|
| 31 | 31 |
clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec |
| 32 | 32 |
clone git github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b |
| 33 | 33 |
clone git github.com/hashicorp/memberlist 9a1e242e454d2443df330bdd51a436d5a9058fc4 |
| ... | ... |
@@ -12,6 +12,8 @@ const ( |
| 12 | 12 |
gwEPlen = 12 |
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 |
+var procGwNetwork = make(chan (bool), 1) |
|
| 16 |
+ |
|
| 15 | 17 |
/* |
| 16 | 18 |
libnetwork creates a bridge network "docker_gw_bridge" for provding |
| 17 | 19 |
default gateway for the containers if none of the container's endpoints |
| ... | ... |
@@ -35,13 +37,11 @@ func (sb *sandbox) setupDefaultGW(srcEp *endpoint) error {
|
| 35 | 35 |
return nil |
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 |
+ // Look for default gw network. In case of error (includes not found), |
|
| 39 |
+ // retry and create it if needed in a serialized execution. |
|
| 38 | 40 |
n, err := c.NetworkByName(libnGWNetwork) |
| 39 | 41 |
if err != nil {
|
| 40 |
- if _, ok := err.(types.NotFoundError); !ok {
|
|
| 41 |
- return err |
|
| 42 |
- } |
|
| 43 |
- n, err = c.createGWNetwork() |
|
| 44 |
- if err != nil {
|
|
| 42 |
+ if n, err = c.defaultGwNetwork(); err != nil {
|
|
| 45 | 43 |
return err |
| 46 | 44 |
} |
| 47 | 45 |
} |
| ... | ... |
@@ -150,3 +150,18 @@ func (sb *sandbox) getEPwithoutGateway() *endpoint {
|
| 150 | 150 |
} |
| 151 | 151 |
return nil |
| 152 | 152 |
} |
| 153 |
+ |
|
| 154 |
+// Looks for the default gw network and creates it if not there. |
|
| 155 |
+// Parallel executions are serialized. |
|
| 156 |
+func (c *controller) defaultGwNetwork() (Network, error) {
|
|
| 157 |
+ procGwNetwork <- true |
|
| 158 |
+ defer func() { <-procGwNetwork }()
|
|
| 159 |
+ |
|
| 160 |
+ n, err := c.NetworkByName(libnGWNetwork) |
|
| 161 |
+ if err != nil {
|
|
| 162 |
+ if _, ok := err.(types.NotFoundError); ok {
|
|
| 163 |
+ n, err = c.createGWNetwork() |
|
| 164 |
+ } |
|
| 165 |
+ } |
|
| 166 |
+ return n, err |
|
| 167 |
+} |
| ... | ... |
@@ -47,6 +47,8 @@ type Sandbox interface {
|
| 47 | 47 |
// ResolveIP returns the service name for the passed in IP. IP is in reverse dotted |
| 48 | 48 |
// notation; the format used for DNS PTR records |
| 49 | 49 |
ResolveIP(name string) string |
| 50 |
+ // Endpoints returns all the endpoints connected to the sandbox |
|
| 51 |
+ Endpoints() []Endpoint |
|
| 50 | 52 |
} |
| 51 | 53 |
|
| 52 | 54 |
// SandboxOption is a option setter function type used to pass varios options to |
| ... | ... |
@@ -347,6 +349,17 @@ func (sb *sandbox) setupResolutionFiles() error {
|
| 347 | 347 |
return nil |
| 348 | 348 |
} |
| 349 | 349 |
|
| 350 |
+func (sb *sandbox) Endpoints() []Endpoint {
|
|
| 351 |
+ sb.Lock() |
|
| 352 |
+ defer sb.Unlock() |
|
| 353 |
+ |
|
| 354 |
+ endpoints := make([]Endpoint, len(sb.endpoints)) |
|
| 355 |
+ for i, ep := range sb.endpoints {
|
|
| 356 |
+ endpoints[i] = ep |
|
| 357 |
+ } |
|
| 358 |
+ return endpoints |
|
| 359 |
+} |
|
| 360 |
+ |
|
| 350 | 361 |
func (sb *sandbox) getConnectedEndpoints() []*endpoint {
|
| 351 | 362 |
sb.Lock() |
| 352 | 363 |
defer sb.Unlock() |