瀏覽代碼

libnet: populate Endpoint.dnsNames on UnmarshalJSON

This new property will be empty if the daemon was upgraded with
live-restore enabled. To not break DNS resolutions for restored
containers, we need to populate dnsNames based on endpoint's myAliases &
anonymous properties.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Albin Kerouanton 1 年之前
父節點
當前提交
f5cc497eac
共有 1 個文件被更改,包括 12 次插入0 次删除
  1. 12 0
      libnetwork/endpoint.go

+ 12 - 0
libnetwork/endpoint.go

@@ -8,6 +8,7 @@ import (
 	"sync"
 	"sync"
 
 
 	"github.com/containerd/log"
 	"github.com/containerd/log"
+	"github.com/docker/docker/internal/sliceutil"
 	"github.com/docker/docker/libnetwork/datastore"
 	"github.com/docker/docker/libnetwork/datastore"
 	"github.com/docker/docker/libnetwork/ipamapi"
 	"github.com/docker/docker/libnetwork/ipamapi"
 	"github.com/docker/docker/libnetwork/netlabel"
 	"github.com/docker/docker/libnetwork/netlabel"
@@ -198,11 +199,22 @@ func (ep *Endpoint) UnmarshalJSON(b []byte) (err error) {
 	json.Unmarshal(ma, &myAliases) //nolint:errcheck
 	json.Unmarshal(ma, &myAliases) //nolint:errcheck
 	ep.myAliases = myAliases
 	ep.myAliases = myAliases
 
 
+	_, hasDNSNames := epMap["dnsNames"]
 	dn, _ := json.Marshal(epMap["dnsNames"])
 	dn, _ := json.Marshal(epMap["dnsNames"])
 	var dnsNames []string
 	var dnsNames []string
 	json.Unmarshal(dn, &dnsNames)
 	json.Unmarshal(dn, &dnsNames)
 	ep.dnsNames = dnsNames
 	ep.dnsNames = dnsNames
 
 
+	// TODO(aker): remove this migration code in v27
+	if !hasDNSNames {
+		// The field dnsNames was introduced in v25.0. If we don't have it, the on-disk state was written by an older
+		// daemon, thus we need to populate dnsNames based off of myAliases and anonymous values.
+		if !ep.anonymous {
+			myAliases = append([]string{ep.name}, myAliases...)
+		}
+		ep.dnsNames = sliceutil.Dedup(myAliases)
+	}
+
 	return nil
 	return nil
 }
 }