Skip to content

Commit 6a2542d

Browse files
committed
libnet: remove Endpoint.anonymous
No more concept of "anonymous endpoints". The equivalent is now an endpoint with no DNSNames set. Some of the code removed by this commit was mutating user-supplied endpoint's Aliases to add container's short ID to that list. In order to preserve backward compatibility for the ContainerInspect endpoint, this commit also takes care of adding that short ID (and the container hostname) to `EndpointSettings.Aliases` before returning the response. Signed-off-by: Albin Kerouanton <[email protected]>
1 parent 7a9b680 commit 6a2542d

File tree

8 files changed

+29
-23
lines changed

8 files changed

+29
-23
lines changed

daemon/inspect.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"github.com/docker/docker/daemon/config"
1616
"github.com/docker/docker/daemon/network"
1717
"github.com/docker/docker/errdefs"
18+
"github.com/docker/docker/internal/sliceutil"
19+
"github.com/docker/docker/pkg/stringid"
1820
"github.com/docker/go-connections/nat"
1921
)
2022

@@ -27,6 +29,18 @@ func (daemon *Daemon) ContainerInspect(ctx context.Context, name string, size bo
2729
return daemon.containerInspectPre120(ctx, name)
2830
case versions.Equal(version, "1.20"):
2931
return daemon.containerInspect120(name)
32+
case versions.LessThan(version, "1.45"):
33+
ctr, err := daemon.ContainerInspectCurrent(ctx, name, size)
34+
if err != nil {
35+
return nil, err
36+
}
37+
38+
shortCID := stringid.TruncateID(ctr.ID)
39+
for _, ep := range ctr.NetworkSettings.Networks {
40+
ep.Aliases = sliceutil.Dedup(append(ep.Aliases, shortCID, ctr.Config.Hostname))
41+
}
42+
43+
return ctr, nil
3044
default:
3145
return daemon.ContainerInspectCurrent(ctx, name, size)
3246
}

docs/api/version-history.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ keywords: "API, Docker, rcli, REST, documentation"
7070
* `GET /info` now includes `status` properties in `Runtimes`.
7171
* A new field named `DNSNames` and containing all non-fully qualified DNS names
7272
a container takes on a specific network has been added to `GET /containers/{name:.*}/json`.
73+
* The `Aliases` field returned in calls to `GET /containers/{name:.*}/json` in v1.44 and older
74+
versions contains the short container ID. This will change in the next API version, v1.45.
75+
Starting with that API version, this specific value will be removed from the `Aliases` field
76+
such that this field will reflect exactly the values originally submitted to the
77+
`POST /containers/create` endpoint. The newly introduced `DNSNames` should now be used instead.
7378

7479
## v1.43 API changes
7580

hack/make/test-docker-py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ source hack/make/.integration-test-helpers
1313
# --deselect=tests/integration/api_container_test.py::AttachContainerTest::test_attach_no_stream
1414
# TODO re-enable test_attach_no_stream after https://github.com/docker/docker-py/issues/2513 is resolved
1515
# TODO re-enable test_run_container_reading_socket_ws. It's reported in https://github.com/docker/docker-py/issues/1478, and we're getting that error in our tests.
16-
: "${PY_TEST_OPTIONS:=--junitxml=${DEST}/junit-report.xml --deselect=tests/integration/api_container_test.py::AttachContainerTest::test_attach_no_stream --deselect=tests/integration/api_container_test.py::AttachContainerTest::test_run_container_reading_socket_ws}"
16+
# TODO re-enable test_run_with_networking_config once this issue is fixed: https://github.com/moby/moby/pull/46853#issuecomment-1864679942.
17+
: "${PY_TEST_OPTIONS:=--junitxml=${DEST}/junit-report.xml --deselect=tests/integration/api_container_test.py::AttachContainerTest::test_attach_no_stream --deselect=tests/integration/api_container_test.py::AttachContainerTest::test_run_container_reading_socket_ws --deselect=tests/integration/models_containers_test.py::ContainerCollectionTest::test_run_with_networking_config}"
1718

1819
# build --squash is not supported with containerd integration.
1920
if [ -n "$TEST_INTEGRATION_USE_SNAPSHOTTER" ]; then

integration/service/network_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
containertypes "github.com/docker/docker/api/types/container"
77
"github.com/docker/docker/api/types/network"
8+
"github.com/docker/docker/client"
89
"github.com/docker/docker/integration/internal/container"
910
net "github.com/docker/docker/integration/internal/network"
1011
"github.com/docker/docker/integration/internal/swarm"
@@ -13,13 +14,13 @@ import (
1314
"gotest.tools/v3/skip"
1415
)
1516

16-
func TestDockerNetworkConnectAlias(t *testing.T) {
17+
func TestDockerNetworkConnectAliasPreV144(t *testing.T) {
1718
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
1819
ctx := setupTest(t)
1920

2021
d := swarm.NewSwarm(ctx, t, testEnv)
2122
defer d.Stop(t)
22-
client := d.NewClientT(t)
23+
client := d.NewClientT(t, client.WithVersion("1.43"))
2324
defer client.Close()
2425

2526
name := t.Name() + "test-alias"

libnetwork/default_gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (sb *Sandbox) setupDefaultGW() error {
4747
}
4848
}
4949

50-
createOptions := []EndpointOption{CreateOptionAnonymous()}
50+
createOptions := []EndpointOption{}
5151

5252
var gwName string
5353
if len(sb.containerID) <= gwEPlen {

libnetwork/endpoint.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ type Endpoint struct {
3131
joinInfo *endpointJoinInfo
3232
sandboxID string
3333
exposedPorts []types.TransportPort
34-
anonymous bool
3534
// dnsNames holds all the non-fully qualified DNS names associated to this endpoint. Order matters: first entry
3635
// will be used for the PTR records associated to the endpoint's IPv4 and IPv6 addresses.
3736
dnsNames []string
@@ -67,7 +66,6 @@ func (ep *Endpoint) MarshalJSON() ([]byte, error) {
6766
epMap["generic"] = ep.generic
6867
}
6968
epMap["sandbox"] = ep.sandboxID
70-
epMap["anonymous"] = ep.anonymous
7169
epMap["dnsNames"] = ep.dnsNames
7270
epMap["disableResolution"] = ep.disableResolution
7371
epMap["svcName"] = ep.svcName
@@ -159,8 +157,9 @@ func (ep *Endpoint) UnmarshalJSON(b []byte) (err error) {
159157
}
160158
}
161159

160+
var anonymous bool
162161
if v, ok := epMap["anonymous"]; ok {
163-
ep.anonymous = v.(bool)
162+
anonymous = v.(bool)
164163
}
165164
if v, ok := epMap["disableResolution"]; ok {
166165
ep.disableResolution = v.(bool)
@@ -206,7 +205,7 @@ func (ep *Endpoint) UnmarshalJSON(b []byte) (err error) {
206205
if !hasDNSNames {
207206
// The field dnsNames was introduced in v25.0. If we don't have it, the on-disk state was written by an older
208207
// daemon, thus we need to populate dnsNames based off of myAliases and anonymous values.
209-
if !ep.anonymous {
208+
if !anonymous {
210209
myAliases = append([]string{ep.name}, myAliases...)
211210
}
212211
ep.dnsNames = sliceutil.Dedup(myAliases)
@@ -229,7 +228,6 @@ func (ep *Endpoint) CopyTo(o datastore.KVObject) error {
229228
dstEp.sandboxID = ep.sandboxID
230229
dstEp.dbIndex = ep.dbIndex
231230
dstEp.dbExists = ep.dbExists
232-
dstEp.anonymous = ep.anonymous
233231
dstEp.disableResolution = ep.disableResolution
234232
dstEp.svcName = ep.svcName
235233
dstEp.svcID = ep.svcID
@@ -949,14 +947,6 @@ func CreateOptionDNS(dns []string) EndpointOption {
949947
}
950948
}
951949

952-
// CreateOptionAnonymous function returns an option setter for setting
953-
// this endpoint as anonymous
954-
func CreateOptionAnonymous() EndpointOption {
955-
return func(ep *Endpoint) {
956-
ep.anonymous = true
957-
}
958-
}
959-
960950
// CreateOptionDNSNames specifies the list of (non fully qualified) DNS names associated to an endpoint. These will be
961951
// used to populate the embedded DNS server. Order matters: first name will be used to generate PTR records.
962952
func CreateOptionDNSNames(names []string) EndpointOption {

libnetwork/libnetwork_internal_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ func TestEndpointMarshalling(t *testing.T) {
192192
name: "Bau",
193193
id: "efghijklmno",
194194
sandboxID: "ambarabaciccicocco",
195-
anonymous: true,
196195
iface: &EndpointInterface{
197196
mac: []byte{11, 12, 13, 14, 15, 16},
198197
addr: &net.IPNet{
@@ -220,7 +219,7 @@ func TestEndpointMarshalling(t *testing.T) {
220219
t.Fatal(err)
221220
}
222221

223-
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+
if e.name != ee.name || e.id != ee.id || e.sandboxID != ee.sandboxID || !reflect.DeepEqual(e.dnsNames, ee.dnsNames) || !compareEndpointInterface(e.iface, ee.iface) {
224223
t.Fatalf("JSON marsh/unmarsh failed.\nOriginal:\n%#v\nDecoded:\n%#v\nOriginal iface: %#v\nDecodediface:\n%#v", e, ee, e.iface, ee.iface)
225224
}
226225
}

libnetwork/network.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,10 +2162,6 @@ func (n *Network) createLoadBalancerSandbox() (retErr error) {
21622162
CreateOptionIpam(n.loadBalancerIP, nil, nil, nil),
21632163
CreateOptionLoadBalancer(),
21642164
}
2165-
if n.hasLoadBalancerEndpoint() && !n.ingress {
2166-
// Mark LB endpoints as anonymous so they don't show up in DNS
2167-
epOptions = append(epOptions, CreateOptionAnonymous())
2168-
}
21692165
ep, err := n.createEndpoint(endpointName, epOptions...)
21702166
if err != nil {
21712167
return err

0 commit comments

Comments
 (0)