This new property is meant to replace myAliases and anonymous
properties.
The end goal is to get rid of both properties by letting the daemon
determine what (non fully qualified) DNS names should be associated to
them.
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
| ... | ... |
@@ -23,14 +23,17 @@ type EndpointOption func(ep *Endpoint) |
| 23 | 23 |
|
| 24 | 24 |
// Endpoint represents a logical connection between a network and a sandbox. |
| 25 | 25 |
type Endpoint struct {
|
| 26 |
- name string |
|
| 27 |
- id string |
|
| 28 |
- network *Network |
|
| 29 |
- iface *EndpointInterface |
|
| 30 |
- joinInfo *endpointJoinInfo |
|
| 31 |
- sandboxID string |
|
| 32 |
- exposedPorts []types.TransportPort |
|
| 33 |
- anonymous bool |
|
| 26 |
+ name string |
|
| 27 |
+ id string |
|
| 28 |
+ network *Network |
|
| 29 |
+ iface *EndpointInterface |
|
| 30 |
+ joinInfo *endpointJoinInfo |
|
| 31 |
+ sandboxID string |
|
| 32 |
+ exposedPorts []types.TransportPort |
|
| 33 |
+ anonymous bool |
|
| 34 |
+ // dnsNames holds all the non-fully qualified DNS names associated to this endpoint. Order matters: first entry |
|
| 35 |
+ // will be used for the PTR records associated to the endpoint's IPv4 and IPv6 addresses. |
|
| 36 |
+ dnsNames []string |
|
| 34 | 37 |
disableResolution bool |
| 35 | 38 |
generic map[string]interface{}
|
| 36 | 39 |
prefAddress net.IP |
| ... | ... |
@@ -65,6 +68,7 @@ func (ep *Endpoint) MarshalJSON() ([]byte, error) {
|
| 65 | 65 |
} |
| 66 | 66 |
epMap["sandbox"] = ep.sandboxID |
| 67 | 67 |
epMap["anonymous"] = ep.anonymous |
| 68 |
+ epMap["dnsNames"] = ep.dnsNames |
|
| 68 | 69 |
epMap["disableResolution"] = ep.disableResolution |
| 69 | 70 |
epMap["myAliases"] = ep.myAliases |
| 70 | 71 |
epMap["svcName"] = ep.svcName |
| ... | ... |
@@ -193,6 +197,12 @@ func (ep *Endpoint) UnmarshalJSON(b []byte) (err error) {
|
| 193 | 193 |
var myAliases []string |
| 194 | 194 |
json.Unmarshal(ma, &myAliases) //nolint:errcheck |
| 195 | 195 |
ep.myAliases = myAliases |
| 196 |
+ |
|
| 197 |
+ dn, _ := json.Marshal(epMap["dnsNames"]) |
|
| 198 |
+ var dnsNames []string |
|
| 199 |
+ json.Unmarshal(dn, &dnsNames) |
|
| 200 |
+ ep.dnsNames = dnsNames |
|
| 201 |
+ |
|
| 196 | 202 |
return nil |
| 197 | 203 |
} |
| 198 | 204 |
|
| ... | ... |
@@ -243,6 +253,9 @@ func (ep *Endpoint) CopyTo(o datastore.KVObject) error {
|
| 243 | 243 |
dstEp.myAliases = make([]string, len(ep.myAliases)) |
| 244 | 244 |
copy(dstEp.myAliases, ep.myAliases) |
| 245 | 245 |
|
| 246 |
+ dstEp.dnsNames = make([]string, len(ep.dnsNames)) |
|
| 247 |
+ copy(dstEp.dnsNames, ep.dnsNames) |
|
| 248 |
+ |
|
| 246 | 249 |
dstEp.generic = options.Generic{}
|
| 247 | 250 |
for k, v := range ep.generic {
|
| 248 | 251 |
dstEp.generic[k] = v |
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"encoding/json" |
| 6 | 6 |
"fmt" |
| 7 | 7 |
"net" |
| 8 |
+ "reflect" |
|
| 8 | 9 |
"runtime" |
| 9 | 10 |
"testing" |
| 10 | 11 |
"time" |
| ... | ... |
@@ -205,6 +206,7 @@ func TestEndpointMarshalling(t *testing.T) {
|
| 205 | 205 |
v6PoolID: "poolv6", |
| 206 | 206 |
llAddrs: lla, |
| 207 | 207 |
}, |
| 208 |
+ dnsNames: []string{"test", "foobar", "baz"},
|
|
| 208 | 209 |
} |
| 209 | 210 |
|
| 210 | 211 |
b, err := json.Marshal(e) |
| ... | ... |
@@ -218,7 +220,7 @@ func TestEndpointMarshalling(t *testing.T) {
|
| 218 | 218 |
t.Fatal(err) |
| 219 | 219 |
} |
| 220 | 220 |
|
| 221 |
- if e.name != ee.name || e.id != ee.id || e.sandboxID != ee.sandboxID || !compareEndpointInterface(e.iface, ee.iface) || e.anonymous != ee.anonymous {
|
|
| 221 |
+ if e.name != ee.name || e.id != ee.id || e.sandboxID != ee.sandboxID || !reflect.DeepEqual(e.dnsNames, ee.dnsNames) || !compareEndpointInterface(e.iface, ee.iface) || e.anonymous != ee.anonymous {
|
|
| 222 | 222 |
t.Fatalf("JSON marsh/unmarsh failed.\nOriginal:\n%#v\nDecoded:\n%#v\nOriginal iface: %#v\nDecodediface:\n%#v", e, ee, e.iface, ee.iface)
|
| 223 | 223 |
} |
| 224 | 224 |
} |