diff --git a/network.go b/network.go index 972212918e..9f99064e11 100644 --- a/network.go +++ b/network.go @@ -1237,12 +1237,14 @@ func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool } serviceID := ep.svcID + if serviceID == "" { + serviceID = ep.ID() + } if isAdd { // If anonymous endpoint has an alias use the first alias // for ip->name mapping. Not having the reverse mapping // breaks some apps if ep.isAnonymous() { - serviceID = ep.ID() if len(myAliases) > 0 { n.addSvcRecords(ep.ID(), myAliases[0], serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord") } @@ -1254,7 +1256,6 @@ func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool } } else { if ep.isAnonymous() { - serviceID = ep.ID() if len(myAliases) > 0 { n.deleteSvcRecords(ep.ID(), myAliases[0], serviceID, iface.Address().IP, ipv6, true, "updateSvcRecord") } diff --git a/service_common.go b/service_common.go index dd42743603..7e3367c71c 100644 --- a/service_common.go +++ b/service_common.go @@ -20,24 +20,30 @@ func (c *controller) addEndpointNameResolution(svcName, svcID, nID, eID, contain // Add container resolution mappings c.addContainerNameResolution(nID, eID, containerName, taskAliases, ip, method) + serviceID := svcID + if serviceID == "" { + // This is the case of a normal container not part of a service + serviceID = eID + } + // Add endpoint IP to special "tasks.svc_name" so that the applications have access to DNS RR. - n.(*network).addSvcRecords(eID, "tasks."+svcName, svcID, ip, nil, false, method) + n.(*network).addSvcRecords(eID, "tasks."+svcName, serviceID, ip, nil, false, method) for _, alias := range serviceAliases { - n.(*network).addSvcRecords(eID, "tasks."+alias, svcID, ip, nil, false, method) + n.(*network).addSvcRecords(eID, "tasks."+alias, serviceID, ip, nil, false, method) } // Add service name to vip in DNS, if vip is valid. Otherwise resort to DNS RR if len(vip) == 0 { - n.(*network).addSvcRecords(eID, svcName, eID, ip, nil, false, method) + n.(*network).addSvcRecords(eID, svcName, serviceID, ip, nil, false, method) for _, alias := range serviceAliases { - n.(*network).addSvcRecords(eID, alias, eID, ip, nil, false, method) + n.(*network).addSvcRecords(eID, alias, serviceID, ip, nil, false, method) } } if addService && len(vip) != 0 { - n.(*network).addSvcRecords(eID, svcName, svcID, vip, nil, false, method) + n.(*network).addSvcRecords(eID, svcName, serviceID, vip, nil, false, method) for _, alias := range serviceAliases { - n.(*network).addSvcRecords(eID, alias, svcID, vip, nil, false, method) + n.(*network).addSvcRecords(eID, alias, serviceID, vip, nil, false, method) } } @@ -73,27 +79,33 @@ func (c *controller) deleteEndpointNameResolution(svcName, svcID, nID, eID, cont // Delete container resolution mappings c.delContainerNameResolution(nID, eID, containerName, taskAliases, ip, method) + serviceID := svcID + if serviceID == "" { + // This is the case of a normal container not part of a service + serviceID = eID + } + // Delete the special "tasks.svc_name" backend record. if !multipleEntries { - n.(*network).deleteSvcRecords(eID, "tasks."+svcName, svcID, ip, nil, false, method) + n.(*network).deleteSvcRecords(eID, "tasks."+svcName, serviceID, ip, nil, false, method) for _, alias := range serviceAliases { - n.(*network).deleteSvcRecords(eID, "tasks."+alias, svcID, ip, nil, false, method) + n.(*network).deleteSvcRecords(eID, "tasks."+alias, serviceID, ip, nil, false, method) } } // If we are doing DNS RR delete the endpoint IP from DNS record right away. if !multipleEntries && len(vip) == 0 { - n.(*network).deleteSvcRecords(eID, svcName, eID, ip, nil, false, method) + n.(*network).deleteSvcRecords(eID, svcName, serviceID, ip, nil, false, method) for _, alias := range serviceAliases { - n.(*network).deleteSvcRecords(eID, alias, eID, ip, nil, false, method) + n.(*network).deleteSvcRecords(eID, alias, serviceID, ip, nil, false, method) } } // Remove the DNS record for VIP only if we are removing the service if rmService && len(vip) != 0 && !multipleEntries { - n.(*network).deleteSvcRecords(eID, svcName, svcID, vip, nil, false, method) + n.(*network).deleteSvcRecords(eID, svcName, serviceID, vip, nil, false, method) for _, alias := range serviceAliases { - n.(*network).deleteSvcRecords(eID, alias, svcID, vip, nil, false, method) + n.(*network).deleteSvcRecords(eID, alias, serviceID, vip, nil, false, method) } }