Skip to content

Commit 1c006f2

Browse files
authored
Merge pull request moby#50832 from thaJeztah/events_remove_deprecated
api/types/events: Message: remove deprecated Status, ID, and From fields
2 parents 183f151 + 1b74b3e commit 1c006f2

File tree

6 files changed

+45
-51
lines changed

6 files changed

+45
-51
lines changed

api/docs/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ keywords: "API, Docker, rcli, REST, documentation"
2222
saved.
2323
* `POST /images/load` now accepts multiple `platform` query-arguments
2424
to allow selecting which platform(s) of a multi-platform image to load.
25+
* `GET /events` no longer includes the deprecated `status`, `id`, and `from`
26+
fields. These fields were removed in API v1.22, but still included
27+
in the response.
2528
* Deprecated: the Engine was automatically backfilling empty `PortBindings` lists with
2629
a PortBinding with an empty HostIP and HostPort when calling `POST /containers/{id}/start`.
2730
This behavior is now deprecated, and a warning is returned by `POST /containers/create`.

api/types/events/events.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,6 @@ type Actor struct {
110110

111111
// Message represents the information an event contains
112112
type Message struct {
113-
// Deprecated: use Action instead.
114-
// Information from JSONMessage.
115-
// With data only in container events.
116-
Status string `json:"status,omitempty"`
117-
// Deprecated: use Actor.ID instead.
118-
ID string `json:"id,omitempty"`
119-
// Deprecated: use Actor.Attributes["image"] instead.
120-
From string `json:"from,omitempty"`
121-
122113
Type Type
123114
Action Action
124115
Actor Actor

daemon/events/events.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,14 @@ func (e *Events) Evict(l chan any) {
8282
// Log creates a local scope message and publishes it
8383
func (e *Events) Log(action eventtypes.Action, eventType eventtypes.Type, actor eventtypes.Actor) {
8484
now := time.Now().UTC()
85-
jm := eventtypes.Message{
85+
e.PublishMessage(eventtypes.Message{
8686
Action: action,
8787
Type: eventType,
8888
Actor: actor,
8989
Scope: "local",
9090
Time: now.Unix(),
9191
TimeNano: now.UnixNano(),
92-
}
93-
94-
// fill deprecated fields for container and images
95-
switch eventType {
96-
case eventtypes.ContainerEventType:
97-
jm.ID = actor.ID //nolint:staticcheck // ignore SA1019: field is deprecated but set for backward compatibility.
98-
jm.Status = string(action) //nolint:staticcheck // ignore SA1019: field is deprecated but set for backward compatibility.
99-
jm.From = actor.Attributes["image"] //nolint:staticcheck // ignore SA1019: field is deprecated but set for backward compatibility.
100-
case eventtypes.ImageEventType:
101-
jm.ID = actor.ID //nolint:staticcheck // ignore SA1019: field is deprecated but set for backward compatibility.
102-
jm.Status = string(action) //nolint:staticcheck // ignore SA1019: field is deprecated but set for backward compatibility.
103-
default:
104-
// TODO(thaJeztah): make switch exhaustive
105-
}
106-
107-
e.PublishMessage(jm)
92+
})
10893
}
10994

11095
// PublishMessage broadcasts event to listeners. Each listener has 100 milliseconds to

daemon/events/events_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@ import (
1212
is "gotest.tools/v3/assert/cmp"
1313
)
1414

15-
// validateLegacyFields validates that the legacy "Status", "ID", and "From"
16-
// fields are set to the same value as their "current" (non-legacy) fields.
17-
//
18-
// These fields were deprecated since v1.10 (https://github.com/moby/moby/pull/18888).
19-
//
20-
// TODO remove this once we removed the deprecated `ID`, `Status`, and `From` fields.
21-
func validateLegacyFields(t *testing.T, msg events.Message) {
22-
t.Helper()
23-
assert.Check(t, is.Equal(msg.Status, string(msg.Action)), "Legacy Status field does not match Action") //nolint:staticcheck // ignore SA1019: field is deprecated but set for backward compatibility.
24-
assert.Check(t, is.Equal(msg.ID, msg.Actor.ID), "Legacy ID field does not match Actor.ID") //nolint:staticcheck // ignore SA1019: field is deprecated but set for backward compatibility.
25-
assert.Check(t, is.Equal(msg.From, msg.Actor.Attributes["image"]), "Legacy From field does not match Actor.Attributes.image") //nolint:staticcheck // ignore SA1019: field is deprecated but set for backward compatibility.
26-
}
27-
2815
func TestEventsLog(t *testing.T) {
2916
e := New()
3017
_, l1, _ := e.Subscribe()
@@ -44,7 +31,6 @@ func TestEventsLog(t *testing.T) {
4431

4532
jmsg, ok := msg.(events.Message)
4633
assert.Assert(t, ok, "unexpected type: %T", msg)
47-
validateLegacyFields(t, jmsg)
4834
assert.Check(t, is.Equal(jmsg.Action, events.Action("test")))
4935
assert.Check(t, is.Equal(jmsg.Actor.ID, "cont"))
5036
assert.Check(t, is.Equal(jmsg.Actor.Attributes["image"], "image"))
@@ -57,7 +43,6 @@ func TestEventsLog(t *testing.T) {
5743

5844
jmsg, ok := msg.(events.Message)
5945
assert.Assert(t, ok, "unexpected type: %T", msg)
60-
validateLegacyFields(t, jmsg)
6146
assert.Check(t, is.Equal(jmsg.Action, events.Action("test")))
6247
assert.Check(t, is.Equal(jmsg.Actor.ID, "cont"))
6348
assert.Check(t, is.Equal(jmsg.Actor.Attributes["image"], "image"))
@@ -120,7 +105,6 @@ func TestLogEvents(t *testing.T) {
120105
assert.Assert(t, is.Len(current, eventsLimit))
121106

122107
first := current[0]
123-
validateLegacyFields(t, first)
124108
assert.Check(t, is.Equal(first.Action, events.Action("action_16")))
125109

126110
last := current[len(current)-1]

daemon/server/router/system/system_routes.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/moby/moby/api/types/swarm"
1818
"github.com/moby/moby/api/types/system"
1919
"github.com/moby/moby/api/types/versions"
20+
"github.com/moby/moby/v2/daemon/internal/compat"
2021
"github.com/moby/moby/v2/daemon/internal/timestamp"
2122
"github.com/moby/moby/v2/daemon/server/backend"
2223
"github.com/moby/moby/v2/daemon/server/httputils"
@@ -369,10 +370,21 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
369370
}
370371
}
371372

373+
var includeLegacyFields bool
374+
if versions.LessThan(httputils.VersionFromContext(ctx), "1.52") {
375+
includeLegacyFields = true
376+
}
377+
372378
for _, ev := range buffered {
373379
if shouldSkip(ev) {
374380
continue
375381
}
382+
if includeLegacyFields {
383+
if err := enc.Encode(backFillLegacy(&ev)); err != nil {
384+
return err
385+
}
386+
continue
387+
}
376388
if err := enc.Encode(ev); err != nil {
377389
return err
378390
}
@@ -393,6 +405,12 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
393405
if shouldSkip(jev) {
394406
continue
395407
}
408+
if includeLegacyFields {
409+
if err := enc.Encode(backFillLegacy(&jev)); err != nil {
410+
return err
411+
}
412+
continue
413+
}
396414
if err := enc.Encode(jev); err != nil {
397415
return err
398416
}
@@ -430,3 +448,25 @@ func eventTime(formTime string) (time.Time, error) {
430448
}
431449
return time.Unix(t, tNano), nil
432450
}
451+
452+
// These fields were deprecated in docker v1.10, API v1.22, but not removed
453+
// from the API responses. Unfortunately, the Docker CLI (and compose indirectly),
454+
// continued using these fields up until v25.0.0, and panic if the fields are
455+
// omitted, or left empty (due to a bug), see: https://github.com/moby/moby/pull/50832#issuecomment-3276600925
456+
func backFillLegacy(ev *events.Message) any {
457+
switch ev.Type {
458+
case events.ContainerEventType:
459+
return compat.Wrap(ev, compat.WithExtraFields(map[string]any{
460+
"id": ev.Actor.ID,
461+
"status": ev.Action,
462+
"from": ev.Actor.Attributes["image"],
463+
}))
464+
case events.ImageEventType:
465+
return compat.Wrap(ev, compat.WithExtraFields(map[string]any{
466+
"id": ev.Actor.ID,
467+
"status": ev.Action,
468+
}))
469+
default:
470+
return &ev
471+
}
472+
}

vendor/github.com/moby/moby/api/types/events/events.go

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)