- Allow to create an endpoint as anonymous.
An anonymous endpoint does not get added
to the network service records.
Signed-off-by: Alessandro Boch <aboch@docker.com>
| ... | ... |
@@ -57,6 +57,7 @@ type endpoint struct {
|
| 57 | 57 |
joinInfo *endpointJoinInfo |
| 58 | 58 |
sandboxID string |
| 59 | 59 |
exposedPorts []types.TransportPort |
| 60 |
+ anonymous bool |
|
| 60 | 61 |
generic map[string]interface{}
|
| 61 | 62 |
joinLeaveDone chan struct{}
|
| 62 | 63 |
dbIndex uint64 |
| ... | ... |
@@ -77,6 +78,7 @@ func (ep *endpoint) MarshalJSON() ([]byte, error) {
|
| 77 | 77 |
epMap["generic"] = ep.generic |
| 78 | 78 |
} |
| 79 | 79 |
epMap["sandbox"] = ep.sandboxID |
| 80 |
+ epMap["anonymous"] = ep.anonymous |
|
| 80 | 81 |
return json.Marshal(epMap) |
| 81 | 82 |
} |
| 82 | 83 |
|
| ... | ... |
@@ -105,6 +107,10 @@ func (ep *endpoint) UnmarshalJSON(b []byte) (err error) {
|
| 105 | 105 |
if v, ok := epMap["generic"]; ok {
|
| 106 | 106 |
ep.generic = v.(map[string]interface{})
|
| 107 | 107 |
} |
| 108 |
+ |
|
| 109 |
+ if v, ok := epMap["anonymous"]; ok {
|
|
| 110 |
+ ep.anonymous = v.(bool) |
|
| 111 |
+ } |
|
| 108 | 112 |
return nil |
| 109 | 113 |
} |
| 110 | 114 |
|
| ... | ... |
@@ -122,6 +128,7 @@ func (ep *endpoint) CopyTo(o datastore.KVObject) error {
|
| 122 | 122 |
dstEp.sandboxID = ep.sandboxID |
| 123 | 123 |
dstEp.dbIndex = ep.dbIndex |
| 124 | 124 |
dstEp.dbExists = ep.dbExists |
| 125 |
+ dstEp.anonymous = ep.anonymous |
|
| 125 | 126 |
|
| 126 | 127 |
if ep.iface != nil {
|
| 127 | 128 |
dstEp.iface = &endpointInterface{}
|
| ... | ... |
@@ -161,6 +168,12 @@ func (ep *endpoint) Network() string {
|
| 161 | 161 |
return ep.network.name |
| 162 | 162 |
} |
| 163 | 163 |
|
| 164 |
+func (ep *endpoint) isAnonymous() bool {
|
|
| 165 |
+ ep.Lock() |
|
| 166 |
+ defer ep.Unlock() |
|
| 167 |
+ return ep.anonymous |
|
| 168 |
+} |
|
| 169 |
+ |
|
| 164 | 170 |
// endpoint Key structure : endpoint/network-id/endpoint-id |
| 165 | 171 |
func (ep *endpoint) Key() []string {
|
| 166 | 172 |
if ep.network == nil {
|
| ... | ... |
@@ -603,6 +616,14 @@ func CreateOptionPortMapping(portBindings []types.PortBinding) EndpointOption {
|
| 603 | 603 |
} |
| 604 | 604 |
} |
| 605 | 605 |
|
| 606 |
+// CreateOptionAnonymous function returns an option setter for setting |
|
| 607 |
+// this endpoint as anonymous |
|
| 608 |
+func CreateOptionAnonymous() EndpointOption {
|
|
| 609 |
+ return func(ep *endpoint) {
|
|
| 610 |
+ ep.anonymous = true |
|
| 611 |
+ } |
|
| 612 |
+} |
|
| 613 |
+ |
|
| 606 | 614 |
// JoinOptionPriority function returns an option setter for priority option to |
| 607 | 615 |
// be passed to the endpoint.Join() method. |
| 608 | 616 |
func JoinOptionPriority(ep Endpoint, prio int) EndpointOption {
|
| ... | ... |
@@ -189,6 +189,7 @@ func TestEndpointMarshalling(t *testing.T) {
|
| 189 | 189 |
name: "Bau", |
| 190 | 190 |
id: "efghijklmno", |
| 191 | 191 |
sandboxID: "ambarabaciccicocco", |
| 192 |
+ anonymous: true, |
|
| 192 | 193 |
iface: &endpointInterface{
|
| 193 | 194 |
mac: []byte{11, 12, 13, 14, 15, 16},
|
| 194 | 195 |
addr: &net.IPNet{
|
| ... | ... |
@@ -214,7 +215,7 @@ func TestEndpointMarshalling(t *testing.T) {
|
| 214 | 214 |
t.Fatal(err) |
| 215 | 215 |
} |
| 216 | 216 |
|
| 217 |
- if e.name != ee.name || e.id != ee.id || e.sandboxID != ee.sandboxID || !compareEndpointInterface(e.iface, ee.iface) {
|
|
| 217 |
+ if e.name != ee.name || e.id != ee.id || e.sandboxID != ee.sandboxID || !compareEndpointInterface(e.iface, ee.iface) || e.anonymous != ee.anonymous {
|
|
| 218 | 218 |
t.Fatalf("JSON marsh/unmarsh failed.\nOriginal:\n%#v\nDecoded:\n%#v\nOriginal iface: %#v\nDecodediface:\n%#v", e, ee, e.iface, ee.iface)
|
| 219 | 219 |
} |
| 220 | 220 |
} |
| ... | ... |
@@ -302,7 +303,7 @@ func TestAuxAddresses(t *testing.T) {
|
| 302 | 302 |
} |
| 303 | 303 |
defer c.Stop() |
| 304 | 304 |
|
| 305 |
- n := &network{ipamType: ipamapi.DefaultIPAM, ctrlr: c.(*controller)}
|
|
| 305 |
+ n := &network{ipamType: ipamapi.DefaultIPAM, networkType: "bridge", ctrlr: c.(*controller)}
|
|
| 306 | 306 |
|
| 307 | 307 |
input := []struct {
|
| 308 | 308 |
masterPool string |
| ... | ... |
@@ -753,6 +753,10 @@ func (n *network) EndpointByID(id string) (Endpoint, error) {
|
| 753 | 753 |
} |
| 754 | 754 |
|
| 755 | 755 |
func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool) {
|
| 756 |
+ if ep.isAnonymous() {
|
|
| 757 |
+ return |
|
| 758 |
+ } |
|
| 759 |
+ |
|
| 756 | 760 |
c := n.getController() |
| 757 | 761 |
sr, ok := c.svcDb[n.ID()] |
| 758 | 762 |
if !ok {
|