From 6f507f53e3017bbec77cac1c042a1ada035b45e4 Mon Sep 17 00:00:00 2001 From: Santhosh Manohar Date: Thu, 19 Jan 2017 14:25:26 -0800 Subject: [PATCH] Fix the data model inconsistency that breaks daemon upgrade to 1.14-dev Signed-off-by: Santhosh Manohar --- libnetwork/resolver.go | 12 ++++++------ libnetwork/sandbox_dns_unix.go | 4 ++-- libnetwork/sandbox_store.go | 31 ++++++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/libnetwork/resolver.go b/libnetwork/resolver.go index c11aa58ed4..cc7692621f 100644 --- a/libnetwork/resolver.go +++ b/libnetwork/resolver.go @@ -72,8 +72,8 @@ const ( ) type extDNSEntry struct { - ipStr string - hostLoopback bool + IPStr string + HostLoopback bool } // resolver implements the Resolver interface @@ -413,15 +413,15 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) { } else { for i := 0; i < maxExtDNS; i++ { extDNS := &r.extDNSList[i] - if extDNS.ipStr == "" { + if extDNS.IPStr == "" { break } extConnect := func() { - addr := fmt.Sprintf("%s:%d", extDNS.ipStr, 53) + addr := fmt.Sprintf("%s:%d", extDNS.IPStr, 53) extConn, err = net.DialTimeout(proto, addr, extIOTimeout) } - if extDNS.hostLoopback { + if extDNS.HostLoopback { extConnect() } else { execErr := r.backend.ExecFunc(extConnect) @@ -435,7 +435,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) { continue } logrus.Debugf("Query %s[%d] from %s, forwarding to %s:%s", name, query.Question[0].Qtype, - extConn.LocalAddr().String(), proto, extDNS.ipStr) + extConn.LocalAddr().String(), proto, extDNS.IPStr) // Timeout has to be set for every IO operation. extConn.SetDeadline(time.Now().Add(extIOTimeout)) diff --git a/libnetwork/sandbox_dns_unix.go b/libnetwork/sandbox_dns_unix.go index 464793d71f..867cc8abb4 100644 --- a/libnetwork/sandbox_dns_unix.go +++ b/libnetwork/sandbox_dns_unix.go @@ -174,8 +174,8 @@ func (sb *sandbox) setExternalResolvers(content []byte, addrType int, checkLoopb hostLoopback = dns.IsIPv4Localhost(ip) } sb.extDNS = append(sb.extDNS, extDNSEntry{ - ipStr: ip, - hostLoopback: hostLoopback, + IPStr: ip, + HostLoopback: hostLoopback, }) } } diff --git a/libnetwork/sandbox_store.go b/libnetwork/sandbox_store.go index d50163ded5..38b2bd7e8b 100644 --- a/libnetwork/sandbox_store.go +++ b/libnetwork/sandbox_store.go @@ -27,7 +27,12 @@ type sbState struct { dbExists bool Eps []epState EpPriority map[string]int - ExtDNS []extDNSEntry + // external servers have to be persisted so that on restart of a live-restore + // enabled daemon we get the external servers for the running containers. + // We have two versions of ExtDNS to support upgrade & downgrade of the daemon + // between >=1.14 and <1.14 versions. + ExtDNS []string + ExtDNS2 []extDNSEntry } func (sbs *sbState) Key() []string { @@ -114,8 +119,16 @@ func (sbs *sbState) CopyTo(o datastore.KVObject) error { dstSbs.Eps = append(dstSbs.Eps, eps) } + if len(sbs.ExtDNS2) > 0 { + for _, dns := range sbs.ExtDNS2 { + dstSbs.ExtDNS2 = append(dstSbs.ExtDNS2, dns) + dstSbs.ExtDNS = append(dstSbs.ExtDNS, dns.IPStr) + } + return nil + } for _, dns := range sbs.ExtDNS { dstSbs.ExtDNS = append(dstSbs.ExtDNS, dns) + dstSbs.ExtDNS2 = append(dstSbs.ExtDNS2, extDNSEntry{IPStr: dns}) } return nil @@ -131,7 +144,11 @@ func (sb *sandbox) storeUpdate() error { ID: sb.id, Cid: sb.containerID, EpPriority: sb.epPriority, - ExtDNS: sb.extDNS, + ExtDNS2: sb.extDNS, + } + + for _, ext := range sb.extDNS { + sbs.ExtDNS = append(sbs.ExtDNS, ext.IPStr) } retry: @@ -205,7 +222,15 @@ func (c *controller) sandboxCleanup(activeSandboxes map[string]interface{}) { dbIndex: sbs.dbIndex, isStub: true, dbExists: true, - extDNS: sbs.ExtDNS, + } + // If we are restoring from a older version extDNSEntry won't have the + // HostLoopback field + if len(sbs.ExtDNS2) > 0 { + sb.extDNS = sbs.ExtDNS2 + } else { + for _, dns := range sbs.ExtDNS { + sb.extDNS = append(sb.extDNS, extDNSEntry{IPStr: dns}) + } } msg := " for cleanup"