From f5cc497eac4cdacbb806978cc2de018244c06e98 Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Tue, 28 Nov 2023 11:48:11 +0100 Subject: [PATCH] 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 --- libnetwork/endpoint.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libnetwork/endpoint.go b/libnetwork/endpoint.go index 5fbcc03f5c..177e6d75dd 100644 --- a/libnetwork/endpoint.go +++ b/libnetwork/endpoint.go @@ -8,6 +8,7 @@ import ( "sync" "github.com/containerd/log" + "github.com/docker/docker/internal/sliceutil" "github.com/docker/docker/libnetwork/datastore" "github.com/docker/docker/libnetwork/ipamapi" "github.com/docker/docker/libnetwork/netlabel" @@ -198,11 +199,22 @@ func (ep *Endpoint) UnmarshalJSON(b []byte) (err error) { json.Unmarshal(ma, &myAliases) //nolint:errcheck ep.myAliases = myAliases + _, hasDNSNames := epMap["dnsNames"] dn, _ := json.Marshal(epMap["dnsNames"]) var dnsNames []string json.Unmarshal(dn, &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 }