diff --git a/probe/docker/container.go b/probe/docker/container.go index 6ffa10946d..718eccaef3 100644 --- a/probe/docker/container.go +++ b/probe/docker/container.go @@ -373,7 +373,7 @@ func (c *container) GetNode(hostID string, localAddrs []net.IP) report.Node { RestartContainer, StopContainer, PauseContainer, AttachContainer, ExecContainer, ) } else { - result = result.WithControls(StartContainer) + result = result.WithControls(StartContainer, RemoveContainer) } result = AddLabels(result, c.container.Config.Labels) diff --git a/probe/docker/controls.go b/probe/docker/controls.go index 23b8d23ba2..edb3a476fb 100644 --- a/probe/docker/controls.go +++ b/probe/docker/controls.go @@ -17,6 +17,7 @@ const ( RestartContainer = "docker_restart_container" PauseContainer = "docker_pause_container" UnpauseContainer = "docker_unpause_container" + RemoveContainer = "docker_remove_container" AttachContainer = "docker_attach_container" ExecContainer = "docker_exec_container" @@ -48,6 +49,13 @@ func (r *registry) unpauseContainer(containerID string, _ xfer.Request) xfer.Res return xfer.ResponseError(r.client.UnpauseContainer(containerID)) } +func (r *registry) removeContainer(containerID string, _ xfer.Request) xfer.Response { + log.Infof("Removing container %s", containerID) + return xfer.ResponseError(r.client.RemoveContainer(docker_client.RemoveContainerOptions{ + ID: containerID, + })) +} + func (r *registry) attachContainer(containerID string, req xfer.Request) xfer.Response { c, ok := r.GetContainer(containerID) if !ok { @@ -156,6 +164,7 @@ func (r *registry) registerControls() { controls.Register(RestartContainer, captureContainerID(r.restartContainer)) controls.Register(PauseContainer, captureContainerID(r.pauseContainer)) controls.Register(UnpauseContainer, captureContainerID(r.unpauseContainer)) + controls.Register(RemoveContainer, captureContainerID(r.removeContainer)) controls.Register(AttachContainer, captureContainerID(r.attachContainer)) controls.Register(ExecContainer, captureContainerID(r.execContainer)) } @@ -166,6 +175,7 @@ func (r *registry) deregisterControls() { controls.Rm(RestartContainer) controls.Rm(PauseContainer) controls.Rm(UnpauseContainer) + controls.Rm(RemoveContainer) controls.Rm(AttachContainer) controls.Rm(ExecContainer) } diff --git a/probe/docker/registry.go b/probe/docker/registry.go index 962f22b26e..d9f78212c8 100644 --- a/probe/docker/registry.go +++ b/probe/docker/registry.go @@ -67,6 +67,7 @@ type Client interface { RestartContainer(string, uint) error PauseContainer(string) error UnpauseContainer(string) error + RemoveContainer(docker_client.RemoveContainerOptions) error AttachToContainerNonBlocking(docker_client.AttachToContainerOptions) (docker_client.CloseWaiter, error) CreateExec(docker_client.CreateExecOptions) (*docker_client.Exec, error) StartExecNonBlocking(string, docker_client.StartExecOptions) (docker_client.CloseWaiter, error) diff --git a/probe/docker/registry_test.go b/probe/docker/registry_test.go index fefb412d86..23d9aed70c 100644 --- a/probe/docker/registry_test.go +++ b/probe/docker/registry_test.go @@ -136,6 +136,10 @@ func (m *mockDockerClient) UnpauseContainer(_ string) error { return fmt.Errorf("unpaused") } +func (m *mockDockerClient) RemoveContainer(_ client.RemoveContainerOptions) error { + return fmt.Errorf("remove") +} + type mockCloseWaiter struct{} func (mockCloseWaiter) Close() error { return nil } diff --git a/probe/docker/reporter.go b/probe/docker/reporter.go index 872e0f5e2b..346540255c 100644 --- a/probe/docker/reporter.go +++ b/probe/docker/reporter.go @@ -122,6 +122,11 @@ func (r *Reporter) containerTopology(localAddrs []net.IP) report.Topology { Human: "Unpause", Icon: "fa-play", }) + result.Controls.AddControl(report.Control{ + ID: RemoveContainer, + Human: "Remove", + Icon: "fa-trash-o", + }) result.Controls.AddControl(report.Control{ ID: AttachContainer, Human: "Attach",