Skip to content

Commit

Permalink
Addressed comments
Browse files Browse the repository at this point in the history
Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
  • Loading branch information
Flavio Crisciani committed Jun 17, 2017
1 parent ccc21bc commit 5fd5257
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
5 changes: 3 additions & 2 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand Down
36 changes: 24 additions & 12 deletions service_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 5fd5257

Please sign in to comment.