Skip to content

Commit

Permalink
dockerclient, engine: image removal adds docker sdk client changes
Browse files Browse the repository at this point in the history
  • Loading branch information
adnxn committed Dec 21, 2018
1 parent c201e30 commit 5b910bd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
4 changes: 2 additions & 2 deletions agent/dockerclient/dockerapi/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,11 +1021,11 @@ func (dg *dockerGoClient) ListImages(ctx context.Context, timeout time.Duration)
}

func (dg *dockerGoClient) listImages(ctx context.Context) ListImagesResponse {
client, err := dg.dockerClient()
client, err := dg.sdkDockerClient()
if err != nil {
return ListImagesResponse{Error: err}
}
images, err := client.ListImages(docker.ListImagesOptions{
images, err := client.ImageList(ctx, types.ImageListOptions{
All: false,
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions agent/dockerclient/dockerapi/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,8 @@ func TestListImages(t *testing.T) {
mockDocker, client, _, _, _, done := dockerClientSetup(t)
defer done()

images := []docker.APIImages{{ID: "id"}}
mockDocker.EXPECT().ListImages(gomock.Any()).Return(images, nil)
images := []types.ImageSummary{{ID: "id"}}
mockDocker.EXPECT().ImageList(gomock.Any(), gomock.Any()).Return(images, nil)
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
response := client.ListImages(ctx, dockerclient.ListImagesTimeout)
Expand All @@ -841,7 +841,7 @@ func TestListImagesTimeout(t *testing.T) {

wait := &sync.WaitGroup{}
wait.Add(1)
mockDocker.EXPECT().ListImages(gomock.Any()).Do(func(x interface{}) {
mockDocker.EXPECT().ImageList(gomock.Any(), gomock.Any()).Do(func(x, y interface{}) {
wait.Wait()
// Don't return, verify timeout happens
}).MaxTimes(1).Return(nil, errors.New("test error"))
Expand Down
3 changes: 2 additions & 1 deletion agent/dockerclient/sdkclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/volume"
)

Expand All @@ -45,6 +45,7 @@ type Client interface {
options types.ImageImportOptions) (io.ReadCloser, error)
ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error)
ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)
ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error)
ImagePull(ctx context.Context, refStr string, options types.ImagePullOptions) (io.ReadCloser, error)
ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem,
error)
Expand Down
15 changes: 14 additions & 1 deletion agent/dockerclient/sdkclient/mocks/sdkclient_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion agent/engine/docker_image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ func (imageManager *dockerImageManager) removeNonECSContainers(ctx context.Conte
var nonECSContainerRemoveAvailableIDs []string
for _, id := range nonECSContainersIDs {
response, _ := imageManager.client.InspectContainer(ctx, id, dockerclient.InspectContainerTimeout)
if response.State.Status == "exited" && time.Now().Sub(response.State.FinishedAt) > imageManager.nonECSContainerCleanupWaitDuration {

finishedTime, _ := time.Parse(time.Now().String(), response.State.FinishedAt)

if response.State.Status == "exited" && time.Now().Sub(finishedTime) > imageManager.nonECSContainerCleanupWaitDuration {
nonECSContainerRemoveAvailableIDs = append(nonECSContainerRemoveAvailableIDs, id)
}
}
Expand Down
14 changes: 9 additions & 5 deletions agent/engine/docker_image_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,13 +996,17 @@ func TestNonECSImageAndContainersCleanupRemoveImage(t *testing.T) {
listContainersResponse := dockerapi.ListContainersResponse{
DockerIDs: []string{"1"},
}
inspectContainerResponse := &docker.Container{
ID: "1",
State: docker.State{
Status: "exited",
FinishedAt: time.Now().AddDate(0, -2, 0),

inspectContainerResponse := &types.ContainerJSON{
ContainerJSONBase: &types.ContainerJSONBase{
ID: "1",
State: &types.ContainerState{
Status: "exited",
FinishedAt: time.Now().AddDate(0, -2, 0).String(),
},
},
}

listImagesResponse := dockerapi.ListImagesResponse{
ImageIDs: []string{"sha256:qwerty1"},
}
Expand Down

0 comments on commit 5b910bd

Please sign in to comment.