Skip to content

Commit de2303b

Browse files
committed
libnet: Endpoint: populate dnsNames on UnmarshalJSON
We need this to properly handle daemon upgrades. Signed-off-by: Albin Kerouanton <[email protected]>
1 parent 82550da commit de2303b

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

libnetwork/endpoint.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,24 @@ func (ep *Endpoint) UnmarshalJSON(b []byte) (err error) {
200200
json.Unmarshal(ma, &myAliases) //nolint:errcheck
201201
ep.myAliases = myAliases
202202

203+
_, hasDNSNames := epMap["dnsNames"]
203204
dn, _ := json.Marshal(epMap["dnsNames"])
204205
var dnsNames []string
205206
json.Unmarshal(dn, &dnsNames)
206207
ep.dnsNames = dnsNames
207208

209+
if !hasDNSNames {
210+
// The field dnsNames was introduced in v25.0. If we don't have it, the on-disk state was written by an older
211+
// daemon, thus we need to populate dnsNames based off of myAliases and anonymous values.
212+
var name string
213+
if !ep.anonymous {
214+
name = ep.name
215+
}
216+
// Hostname and id fields are purposefully left empty here as they should have been put into myAliases when the
217+
// endpoint was originally created.
218+
ep.dnsNames = BuildEndpointDNSNames(name, "", "", myAliases)
219+
}
220+
208221
return nil
209222
}
210223

0 commit comments

Comments
 (0)