Skip to content

Commit

Permalink
cleanup tools container using defer
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Jul 17, 2019
1 parent 081ec61 commit 96c883a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func removeContainer(ID string) error {
}

if err := docker.ContainerRemove(ctx, ID, options); err != nil {
return fmt.Errorf("FAILURE: couldn't delete container [%s] -> %+v", ID, err)
return fmt.Errorf("ERROR: couldn't delete container [%s] -> %+v", ID, err)
}
return nil
}
15 changes: 8 additions & 7 deletions cli/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ func importImage(clusterName string, images []string, noRemove bool) error {
return err
}

defer func() {
if err = docker.ContainerRemove(ctx, toolsContainerID, types.ContainerRemoveOptions{
Force: true,
}); err != nil {
log.Println(fmt.Errorf("WARN: couldn't remove tools container\n%+v", err))
}
}()

// loop to wait for tools container to exit (failed or successfully saved images)
for {
cont, err := docker.ContainerInspect(ctx, toolsContainerID)
Expand Down Expand Up @@ -92,13 +100,6 @@ func importImage(clusterName string, images []string, noRemove bool) error {
time.Sleep(time.Second / 2) // wait for half a second so we don't spam the docker API too much
}

// clean up tools container
if err = docker.ContainerRemove(ctx, toolsContainerID, types.ContainerRemoveOptions{
Force: true,
}); err != nil {
return fmt.Errorf("ERROR: couldn't remove tools container\n%+v", err)
}

// Get the container IDs for all containers in the cluster
clusters, err := getClusters(false, clusterName)
if err != nil {
Expand Down

0 comments on commit 96c883a

Please sign in to comment.