diff --git a/daemon/containerd/image_events.go b/daemon/containerd/image_events.go index c3f507e7ba..04dee0a307 100644 --- a/daemon/containerd/image_events.go +++ b/daemon/containerd/image_events.go @@ -21,12 +21,10 @@ func (i *ImageService) LogImageEvent(imageID, refName, action string) { if refName != "" { attributes["name"] = refName } - actor := events.Actor{ + i.eventsService.Log(action, events.ImageEventType, events.Actor{ ID: imageID, Attributes: attributes, - } - - i.eventsService.Log(action, events.ImageEventType, actor) + }) } // copyAttributes guarantees that labels are not mutated by event triggers. diff --git a/daemon/exec.go b/daemon/exec.go index fe166e1d0c..ccf5758517 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -137,11 +137,9 @@ func (daemon *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) } daemon.registerExecCommand(cntr, execConfig) - - attributes := map[string]string{ + daemon.LogContainerEventWithAttributes(cntr, "exec_create: "+execConfig.Entrypoint+" "+strings.Join(execConfig.Args, " "), map[string]string{ "execID": execConfig.ID, - } - daemon.LogContainerEventWithAttributes(cntr, "exec_create: "+execConfig.Entrypoint+" "+strings.Join(execConfig.Args, " "), attributes) + }) return execConfig.ID, nil } @@ -175,10 +173,9 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, optio ec.Unlock() log.G(ctx).Debugf("starting exec command %s in container %s", ec.ID, ec.Container.ID) - attributes := map[string]string{ + daemon.LogContainerEventWithAttributes(ec.Container, "exec_start: "+ec.Entrypoint+" "+strings.Join(ec.Args, " "), map[string]string{ "execID": ec.ID, - } - daemon.LogContainerEventWithAttributes(ec.Container, "exec_start: "+ec.Entrypoint+" "+strings.Join(ec.Args, " "), attributes) + }) defer func() { if err != nil { @@ -311,10 +308,9 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, optio if _, ok := err.(term.EscapeError); !ok { return errdefs.System(errors.Wrap(err, "exec attach failed")) } - attributes := map[string]string{ + daemon.LogContainerEventWithAttributes(ec.Container, "exec_detach", map[string]string{ "execID": ec.ID, - } - daemon.LogContainerEventWithAttributes(ec.Container, "exec_detach", attributes) + }) } } return nil diff --git a/daemon/health.go b/daemon/health.go index a069fcc8dc..d867b32850 100644 --- a/daemon/health.go +++ b/daemon/health.go @@ -87,10 +87,9 @@ func (p *cmdProbe) run(ctx context.Context, d *Daemon, cntr *container.Container execConfig.Env = container.ReplaceOrAppendEnvValues(cntr.CreateDaemonEnvironment(execConfig.Tty, linkedEnv), execConfig.Env) d.registerExecCommand(cntr, execConfig) - attributes := map[string]string{ + d.LogContainerEventWithAttributes(cntr, "exec_create: "+execConfig.Entrypoint+" "+strings.Join(execConfig.Args, " "), map[string]string{ "execID": execConfig.ID, - } - d.LogContainerEventWithAttributes(cntr, "exec_create: "+execConfig.Entrypoint+" "+strings.Join(execConfig.Args, " "), attributes) + }) output := &limitedBuffer{} probeCtx, cancelProbe := context.WithCancel(ctx) diff --git a/daemon/images/image_delete.go b/daemon/images/image_delete.go index de6a5c428a..57153dc267 100644 --- a/daemon/images/image_delete.go +++ b/daemon/images/image_delete.go @@ -243,18 +243,15 @@ func (i *ImageService) removeImageRef(ref reference.Named) (reference.Named, err // daemon's event service. An "Untagged" types.ImageDeleteResponseItem is added to the // given list of records. func (i *ImageService) removeAllReferencesToImageID(imgID image.ID, records *[]types.ImageDeleteResponseItem) error { - imageRefs := i.referenceStore.References(imgID.Digest()) - - for _, imageRef := range imageRefs { + for _, imageRef := range i.referenceStore.References(imgID.Digest()) { parsedRef, err := i.removeImageRef(imageRef) if err != nil { return err } - - untaggedRecord := types.ImageDeleteResponseItem{Untagged: reference.FamiliarString(parsedRef)} - i.LogImageEvent(imgID.String(), imgID.String(), "untag") - *records = append(*records, untaggedRecord) + *records = append(*records, types.ImageDeleteResponseItem{ + Untagged: reference.FamiliarString(parsedRef), + }) } return nil diff --git a/daemon/images/image_events.go b/daemon/images/image_events.go index 84803b4ad8..d096804657 100644 --- a/daemon/images/image_events.go +++ b/daemon/images/image_events.go @@ -21,12 +21,10 @@ func (i *ImageService) LogImageEvent(imageID, refName, action string) { if refName != "" { attributes["name"] = refName } - actor := events.Actor{ + i.eventsService.Log(action, events.ImageEventType, events.Actor{ ID: imageID, Attributes: attributes, - } - - i.eventsService.Log(action, events.ImageEventType, actor) + }) } // copyAttributes guarantees that labels are not mutated by event triggers. diff --git a/daemon/monitor.go b/daemon/monitor.go index 5a4aeb4eb0..c825cd74df 100644 --- a/daemon/monitor.go +++ b/daemon/monitor.go @@ -219,11 +219,10 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerdtypes.EventType, ei }() } } - attributes := map[string]string{ + daemon.LogContainerEventWithAttributes(c, "exec_die", map[string]string{ "execID": ei.ProcessID, "exitCode": strconv.Itoa(exitCode), - } - daemon.LogContainerEventWithAttributes(c, "exec_die", attributes) + }) case libcontainerdtypes.EventStart: c.Lock() defer c.Unlock() diff --git a/daemon/resize.go b/daemon/resize.go index 8e350fbbc2..7731f9df8d 100644 --- a/daemon/resize.go +++ b/daemon/resize.go @@ -25,11 +25,10 @@ func (daemon *Daemon) ContainerResize(name string, height, width int) error { } if err = tsk.Resize(context.Background(), uint32(width), uint32(height)); err == nil { - attributes := map[string]string{ + daemon.LogContainerEventWithAttributes(container, "resize", map[string]string{ "height": strconv.Itoa(height), "width": strconv.Itoa(width), - } - daemon.LogContainerEventWithAttributes(container, "resize", attributes) + }) } return err } diff --git a/daemon/volumes_unix.go b/daemon/volumes_unix.go index abfa070fd1..f2fbb5d9cd 100644 --- a/daemon/volumes_unix.go +++ b/daemon/volumes_unix.go @@ -73,14 +73,13 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er mnt.ReadOnlyForceRecursive = m.Spec.BindOptions.ReadOnlyForceRecursive } if m.Volume != nil { - attributes := map[string]string{ + daemon.LogVolumeEvent(m.Volume.Name(), "mount", map[string]string{ "driver": m.Volume.DriverName(), "container": c.ID, "destination": m.Destination, "read/write": strconv.FormatBool(m.RW), "propagation": string(m.Propagation), - } - daemon.LogVolumeEvent(m.Volume.Name(), "mount", attributes) + }) } mounts = append(mounts, mnt) }