From 3accde6dee079fbde42f1928002bce43cb15833d Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Fri, 3 Jun 2016 10:11:52 -0700 Subject: [PATCH] attach: replace interface with simple type Also add docs to detach events Signed-off-by: Alexander Morozov --- container/container.go | 16 ++++------------ daemon/attach.go | 3 +-- daemon/exec.go | 7 +++---- docs/reference/api/docker_remote_api.md | 4 ++++ docs/reference/api/docker_remote_api_v1.24.md | 2 +- docs/reference/commandline/events.md | 2 +- man/docker-events.1.md | 2 +- 7 files changed, 15 insertions(+), 21 deletions(-) diff --git a/container/container.go b/container/container.go index 34bce015ad..2e93430a1a 100644 --- a/container/container.go +++ b/container/container.go @@ -48,18 +48,10 @@ var ( errInvalidNetwork = fmt.Errorf("invalid network settings while building port map info") ) -// AttachError represents errors of attach -type AttachError interface { - IsDetached() bool -} +// DetachError is special error which returned in case of container detach. +type DetachError struct{} -type detachError struct{} - -func (e detachError) IsDetached() bool { - return true -} - -func (e detachError) Error() string { +func (DetachError) Error() string { return "detached from container" } @@ -507,7 +499,7 @@ func copyEscapable(dst io.Writer, src io.ReadCloser, keys []byte) (written int64 } if i == len(keys)-1 { src.Close() - return 0, detachError{} + return 0, DetachError{} } nr, er = src.Read(buf) } diff --git a/daemon/attach.go b/daemon/attach.go index dd5c6b45af..eb263ac7f7 100644 --- a/daemon/attach.go +++ b/daemon/attach.go @@ -121,8 +121,7 @@ func (daemon *Daemon) containerAttach(c *container.Container, stdin io.ReadClose } err := <-c.Attach(stdinPipe, stdout, stderr, keys) if err != nil { - e, ok := err.(container.AttachError) - if ok && e.IsDetached() { + if _, ok := err.(container.DetachError); ok { daemon.LogContainerEvent(c, "detach") } else { logrus.Errorf("attach failed with error: %v", err) diff --git a/daemon/exec.go b/daemon/exec.go index b8b1b2994f..9f8c5cd757 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -222,11 +222,10 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R return fmt.Errorf("context cancelled") case err := <-attachErr: if err != nil { - e, ok := err.(container.AttachError) - if !ok || !e.IsDetached() { - return fmt.Errorf("attach failed with error: %v", err) + if _, ok := err.(container.DetachError); !ok { + return fmt.Errorf("exec attach failed with error: %v", err) } - d.LogContainerEvent(c, "detach") + d.LogContainerEvent(c, "exec_detach") } } return nil diff --git a/docs/reference/api/docker_remote_api.md b/docs/reference/api/docker_remote_api.md index 58c0743959..0786676bcb 100644 --- a/docs/reference/api/docker_remote_api.md +++ b/docs/reference/api/docker_remote_api.md @@ -99,6 +99,8 @@ Some container-related events are not affected by container state, so they are n * **export** emitted by `docker export` * **exec_create** emitted by `docker exec` * **exec_start** emitted by `docker exec` after **exec_create** +* **detach** emitted when client is detached from container process +* **exec_detach** emitted when client is detached from exec process Running `docker rmi` emits an **untag** event when removing an image name. The `rmi` command may also emit **delete** events when images are deleted by ID directly or by deleting the last tag referring to the image. @@ -121,6 +123,8 @@ This section lists each version from latest to oldest. Each listing includes a * `GET /images/search` now takes a `filters` query parameter. * `GET /events` now supports a `reload` event that is emitted when the daemon configuration is reloaded. * `GET /events` now supports filtering by daemon name or ID. +* `GET /events` now supports a `detach` event that is emitted on detaching from container process. +* `GET /events` now supports an `exec_detach ` event that is emitted on detaching from exec process. * `GET /images/json` now supports filters `since` and `before`. * `POST /containers/(id or name)/start` no longer accepts a `HostConfig`. * `POST /images/(name)/tag` no longer has a `force` query parameter. diff --git a/docs/reference/api/docker_remote_api_v1.24.md b/docs/reference/api/docker_remote_api_v1.24.md index 5fd040389a..452b8b4cbe 100644 --- a/docs/reference/api/docker_remote_api_v1.24.md +++ b/docs/reference/api/docker_remote_api_v1.24.md @@ -2404,7 +2404,7 @@ Get container events from docker, either in real time via streaming, or via poll Docker containers report the following events: - attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update + attach, commit, copy, create, destroy, detach, die, exec_create, exec_detach, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update Docker images report the following events: diff --git a/docs/reference/commandline/events.md b/docs/reference/commandline/events.md index a958a3a1ed..688c05a907 100644 --- a/docs/reference/commandline/events.md +++ b/docs/reference/commandline/events.md @@ -21,7 +21,7 @@ parent = "smn_cli" Docker containers report the following events: - attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update + attach, commit, copy, create, destroy, detach, die, exec_create, exec_detach, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update Docker images report the following events: diff --git a/man/docker-events.1.md b/man/docker-events.1.md index 15a5d516a5..4e38b53687 100644 --- a/man/docker-events.1.md +++ b/man/docker-events.1.md @@ -18,7 +18,7 @@ information and real-time information. Docker containers will report the following events: - attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update + attach, commit, copy, create, destroy, detach, die, exec_create, exec_detach, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update Docker images report the following events: