From c01c6de4812ba611cccb8f9935ee6c7d13fd1910 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Mon, 16 Sep 2019 10:40:56 -0400 Subject: [PATCH] address code review comments --- drivers/docker/driver.go | 4 ++++ drivers/docker/reconciler.go | 5 +++-- drivers/docker/reconciler_test.go | 2 -- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/docker/driver.go b/drivers/docker/driver.go index 67b578bc3..8c900d5d9 100644 --- a/drivers/docker/driver.go +++ b/drivers/docker/driver.go @@ -309,6 +309,10 @@ CREATE: // the container is started runningContainer, err := client.InspectContainer(container.ID) if err != nil { + client.RemoveContainer(docker.RemoveContainerOptions{ + ID: container.ID, + Force: true, + }) msg := "failed to inspect started container" d.logger.Error(msg, "error", err) client.RemoveContainer(docker.RemoveContainerOptions{ diff --git a/drivers/docker/reconciler.go b/drivers/docker/reconciler.go index 77d0eabb1..23eb0bbc9 100644 --- a/drivers/docker/reconciler.go +++ b/drivers/docker/reconciler.go @@ -70,7 +70,8 @@ func (d *Driver) removeDanglingContainersIteration() error { return nil } -// untrackedContainers returns the ids of containers that look +// untrackedContainers returns the ids of containers that suspected +// to have been started by Nomad but aren't tracked by this driver func (d *Driver) untrackedContainers(tracked map[string]bool, creationTimeout time.Duration) ([]string, error) { result := []string{} @@ -116,7 +117,7 @@ func (d *Driver) isNomadContainer(c docker.APIContainers) bool { } // double check before killing process - ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + ctx, cancel := context.WithTimeout(d.ctx, 20*time.Second) defer cancel() ci, err := client.InspectContainerWithContext(c.ID, ctx) diff --git a/drivers/docker/reconciler_test.go b/drivers/docker/reconciler_test.go index 582552f48..06ffbbe00 100644 --- a/drivers/docker/reconciler_test.go +++ b/drivers/docker/reconciler_test.go @@ -111,8 +111,6 @@ func TestDanglingContainerRemoval(t *testing.T) { err = client.StartContainer(c.ID, nil) require.NoError(t, err) - time.Sleep(1 * time.Second) - dd := d.Impl().(*Driver) trackedContainers := map[string]bool{handle.containerID: true}