diff --git a/libnetwork/endpoint.go b/libnetwork/endpoint.go index fdd0bf6641..b9933953a5 100644 --- a/libnetwork/endpoint.go +++ b/libnetwork/endpoint.go @@ -57,6 +57,7 @@ type endpoint struct { joinInfo *endpointJoinInfo sandboxID string exposedPorts []types.TransportPort + anonymous bool generic map[string]interface{} joinLeaveDone chan struct{} dbIndex uint64 @@ -77,6 +78,7 @@ func (ep *endpoint) MarshalJSON() ([]byte, error) { epMap["generic"] = ep.generic } epMap["sandbox"] = ep.sandboxID + epMap["anonymous"] = ep.anonymous return json.Marshal(epMap) } @@ -105,6 +107,10 @@ func (ep *endpoint) UnmarshalJSON(b []byte) (err error) { if v, ok := epMap["generic"]; ok { ep.generic = v.(map[string]interface{}) } + + if v, ok := epMap["anonymous"]; ok { + ep.anonymous = v.(bool) + } return nil } @@ -122,6 +128,7 @@ func (ep *endpoint) CopyTo(o datastore.KVObject) error { dstEp.sandboxID = ep.sandboxID dstEp.dbIndex = ep.dbIndex dstEp.dbExists = ep.dbExists + dstEp.anonymous = ep.anonymous if ep.iface != nil { dstEp.iface = &endpointInterface{} @@ -161,6 +168,12 @@ func (ep *endpoint) Network() string { return ep.network.name } +func (ep *endpoint) isAnonymous() bool { + ep.Lock() + defer ep.Unlock() + return ep.anonymous +} + // endpoint Key structure : endpoint/network-id/endpoint-id func (ep *endpoint) Key() []string { if ep.network == nil { @@ -603,6 +616,14 @@ func CreateOptionPortMapping(portBindings []types.PortBinding) EndpointOption { } } +// CreateOptionAnonymous function returns an option setter for setting +// this endpoint as anonymous +func CreateOptionAnonymous() EndpointOption { + return func(ep *endpoint) { + ep.anonymous = true + } +} + // JoinOptionPriority function returns an option setter for priority option to // be passed to the endpoint.Join() method. func JoinOptionPriority(ep Endpoint, prio int) EndpointOption { diff --git a/libnetwork/libnetwork_internal_test.go b/libnetwork/libnetwork_internal_test.go index 33104d573c..7eb259f258 100644 --- a/libnetwork/libnetwork_internal_test.go +++ b/libnetwork/libnetwork_internal_test.go @@ -189,6 +189,7 @@ func TestEndpointMarshalling(t *testing.T) { name: "Bau", id: "efghijklmno", sandboxID: "ambarabaciccicocco", + anonymous: true, iface: &endpointInterface{ mac: []byte{11, 12, 13, 14, 15, 16}, addr: &net.IPNet{ @@ -214,7 +215,7 @@ func TestEndpointMarshalling(t *testing.T) { t.Fatal(err) } - if e.name != ee.name || e.id != ee.id || e.sandboxID != ee.sandboxID || !compareEndpointInterface(e.iface, ee.iface) { + if e.name != ee.name || e.id != ee.id || e.sandboxID != ee.sandboxID || !compareEndpointInterface(e.iface, ee.iface) || e.anonymous != ee.anonymous { t.Fatalf("JSON marsh/unmarsh failed.\nOriginal:\n%#v\nDecoded:\n%#v\nOriginal iface: %#v\nDecodediface:\n%#v", e, ee, e.iface, ee.iface) } } @@ -302,7 +303,7 @@ func TestAuxAddresses(t *testing.T) { } defer c.Stop() - n := &network{ipamType: ipamapi.DefaultIPAM, ctrlr: c.(*controller)} + n := &network{ipamType: ipamapi.DefaultIPAM, networkType: "bridge", ctrlr: c.(*controller)} input := []struct { masterPool string diff --git a/libnetwork/network.go b/libnetwork/network.go index 7b14fc830b..69b0e755a7 100644 --- a/libnetwork/network.go +++ b/libnetwork/network.go @@ -753,6 +753,10 @@ func (n *network) EndpointByID(id string) (Endpoint, error) { } func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool) { + if ep.isAnonymous() { + return + } + c := n.getController() sr, ok := c.svcDb[n.ID()] if !ok {