Setup external DNS servers after daemon restart with live-restore

Signed-off-by: Santhosh Manohar <santhosh@docker.com>
This commit is contained in:
Santhosh Manohar 2016-06-09 16:05:11 -07:00
parent b2d5daab2a
commit 96cc604cf1
4 changed files with 21 additions and 8 deletions

View File

@ -728,7 +728,7 @@ func (sb *sandbox) restoreOslSandbox() error {
}
}
if ep.needResolver() {
sb.startResolver()
sb.startResolver(true)
}
}
@ -761,7 +761,7 @@ func (sb *sandbox) populateNetworkResources(ep *endpoint) error {
ep.Unlock()
if ep.needResolver() {
sb.startResolver()
sb.startResolver(false)
}
if i != nil && i.srcName != "" {

View File

@ -21,7 +21,7 @@ const (
filePerm = 0644
)
func (sb *sandbox) startResolver() {
func (sb *sandbox) startResolver(restore bool) {
sb.resolverOnce.Do(func() {
var err error
sb.resolver = NewResolver(sb)
@ -31,10 +31,16 @@ func (sb *sandbox) startResolver() {
}
}()
err = sb.rebuildDNS()
if err != nil {
log.Errorf("Updating resolv.conf failed for container %s, %q", sb.ContainerID(), err)
return
// In the case of live restore container is already running with
// right resolv.conf contents created before. Just update the
// external DNS servers from the restored sandbox for embedded
// server to use.
if !restore {
err = sb.rebuildDNS()
if err != nil {
log.Errorf("Updating resolv.conf failed for container %s, %q", sb.ContainerID(), err)
return
}
}
sb.resolver.SetExtServers(sb.extDNS)

View File

@ -8,7 +8,7 @@ import (
// Stub implementations for DNS related functions
func (sb *sandbox) startResolver() {
func (sb *sandbox) startResolver(bool) {
}
func (sb *sandbox) setupResolutionFiles() error {

View File

@ -27,6 +27,7 @@ type sbState struct {
dbExists bool
Eps []epState
EpPriority map[string]int
ExtDNS []string
}
func (sbs *sbState) Key() []string {
@ -113,6 +114,10 @@ func (sbs *sbState) CopyTo(o datastore.KVObject) error {
dstSbs.Eps = append(dstSbs.Eps, eps)
}
for _, dns := range sbs.ExtDNS {
dstSbs.ExtDNS = append(dstSbs.ExtDNS, dns)
}
return nil
}
@ -126,6 +131,7 @@ func (sb *sandbox) storeUpdate() error {
ID: sb.id,
Cid: sb.containerID,
EpPriority: sb.epPriority,
ExtDNS: sb.extDNS,
}
retry:
@ -198,6 +204,7 @@ func (c *controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
dbIndex: sbs.dbIndex,
isStub: true,
dbExists: true,
extDNS: sbs.ExtDNS,
}
msg := " for cleanup"