From 8a01dc2f90293ac51a8d3eaa09ad175aa8ddbab5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 5 Jan 2026 12:34:40 +0100 Subject: [PATCH 1/2] daemon/cluster/executor/container: rename vars that shadowed Signed-off-by: Sebastiaan van Stijn --- .../cluster/executor/container/health_test.go | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/daemon/cluster/executor/container/health_test.go b/daemon/cluster/executor/container/health_test.go index da84a7e9cf..6d0eb27d6c 100644 --- a/daemon/cluster/executor/container/health_test.go +++ b/daemon/cluster/executor/container/health_test.go @@ -37,22 +37,11 @@ func TestHealthStates(t *testing.T) { Annotations: api.Annotations{Name: "name"}, } - c := &container.Container{ - ID: "id", - Name: "name", - Config: &containertypes.Config{ - Image: "image_name", - Labels: map[string]string{ - "com.docker.swarm.task.id": "id", - }, - }, - } - daemon := &daemon.Daemon{ EventsService: e, } - controller, err := newController(daemon, nil, nil, task, nil, nil) + ctrlr, err := newController(daemon, nil, nil, task, nil, nil) if err != nil { t.Fatalf("create controller fail %v", err) } @@ -62,7 +51,7 @@ func TestHealthStates(t *testing.T) { // fire checkHealth go func() { - err := controller.checkHealth(ctx) + err := ctrlr.checkHealth(ctx) select { case errChan <- err: case <-ctx.Done(): @@ -72,7 +61,17 @@ func TestHealthStates(t *testing.T) { // send an event and expect to get expectedErr // if expectedErr is nil, shouldn't get any error logAndExpect := func(msg eventtypes.Action, expectedErr error) { - daemon.LogContainerEvent(c, msg) + ctr := &container.Container{ + ID: "id", + Name: "name", + Config: &containertypes.Config{ + Image: "image_name", + Labels: map[string]string{ + "com.docker.swarm.task.id": "id", + }, + }, + } + daemon.LogContainerEvent(ctr, msg) timer := time.NewTimer(1 * time.Second) defer timer.Stop() From dcb0149ee1430bc1d6f360c7912810194bf22808 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 5 Jan 2026 12:41:41 +0100 Subject: [PATCH 2/2] daemon: inline copyAttributes utilty Signed-off-by: Sebastiaan van Stijn --- daemon/events.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/daemon/events.go b/daemon/events.go index dc8f81d879..40e19fb8c9 100644 --- a/daemon/events.go +++ b/daemon/events.go @@ -24,7 +24,9 @@ func (daemon *Daemon) LogContainerEvent(container *container.Container, action e // LogContainerEventWithAttributes generates an event related to a container with specific given attributes. func (daemon *Daemon) LogContainerEventWithAttributes(container *container.Container, action events.Action, attributes map[string]string) { - copyAttributes(attributes, container.Config.Labels) + if container.Config.Labels != nil { + maps.Copy(attributes, container.Config.Labels) + } if container.Config.Image != "" { attributes["image"] = container.Config.Image } @@ -90,14 +92,6 @@ func (daemon *Daemon) UnsubscribeFromEvents(listener chan any) { daemon.EventsService.Evict(listener) } -// copyAttributes guarantees that labels are not mutated by event triggers. -func copyAttributes(attributes, labels map[string]string) { - if labels == nil { - return - } - maps.Copy(attributes, labels) -} - // ProcessClusterNotifications gets changes from store and add them to event list func (daemon *Daemon) ProcessClusterNotifications(ctx context.Context, watchStream chan *swarmapi.WatchMessage) { for {