-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove non ecs containers and images changes with docker sdk client #1752
Conversation
f5b466b
to
e9c4be7
Compare
adding @haikuoliu, @yumex93 since reviewed #1736 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need integ and/or functional test coverage for this feature
agent/config/config_test.go
Outdated
@@ -373,8 +374,8 @@ func TestInvalidFormatParseEnvVariableDuration(t *testing.T) { | |||
|
|||
func TestValidForImagesCleanupExclusion(t *testing.T) { | |||
defer setTestRegion()() | |||
defer setTestEnv("ECS_IMAGE_CLEANUP_EXCLUDE", "amazonlinux:2,amazonlinux:3")() | |||
imagesNotDelete := parseImageCleanupExclusionList("ECS_IMAGE_CLEANUP_EXCLUDE") | |||
defer setTestEnv("ECS_NONECS_IMAGE_CLEANUP_EXCLUDE", "amazonlinux:2,amazonlinux:3")() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ECS_NONECS? I'm assuming first ECS is the prefix for internal/ECS env vars?
Howe about ECS_EXCLUDE_CLEANUP_NONECS_IMAGE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about ECS_EXCLUDE_UNTRACKED_IMAGE
? I'd like to get rid of "NONECS".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agent/engine/docker_image_manager.go
Outdated
} | ||
} | ||
|
||
func (imageManager *dockerImageManager) nonECSImagesNames(ctx context.Context) []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get*?
return ListImagesResponse{Error: err} | ||
} | ||
images, err := client.ImageList(ctx, types.ImageListOptions{ | ||
All: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add comment on what All flag signifies? with false, it's not clear what we are ignoring. From docker API:
"All: Show all images (default hides intermediate images)"
So I'm wondering if this is even required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you're right, seems like we can leave this out.
@@ -731,7 +736,7 @@ func TestContainerEventsStreamError(t *testing.T) { | |||
|
|||
eventsChan := make(chan events.Message, dockerEventBufferSize) | |||
errChan := make(chan error) | |||
mockDockerSDK.EXPECT().Events(gomock.Any(), gomock.Any()).Return(eventsChan, errChan).Times(2) | |||
mockDockerSDK.EXPECT().Events(gomock.Any(), gomock.Any()).Return(eventsChan, errChan).MinTimes(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for my curiosity, why did you loosen the required call count check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so looking at this test TestContainerEventsStreamError
we only pass up a single event to test this codepath. so we should we expecting at least one call to Events(...)
.
where as with the Times(2)
, we would sometimes hit the Events(...)
call on the first iteration through this loop and would get test failures for missing calls to the mock from time to time. for example running with -count=100
you'll likely see test failure every time.
let me know if you think i've missed something - i think we added this test as part of the moby migration yea?
agent/engine/docker_image_manager.go
Outdated
} | ||
} | ||
|
||
func (imageManager *dockerImageManager) nonECSContainersIDs(ctx context.Context) ([]string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get*?
ctx, cancel := context.WithCancel(context.TODO()) | ||
defer cancel() | ||
response := client.ListImages(ctx, dockerclient.ListImagesTimeout) | ||
if response.Error != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just use assert.NoError
and assert.Equal
, same for other tests
agent/engine/docker_image_manager.go
Outdated
} | ||
var nonECSContainerRemoveAvailableIDs []string | ||
for _, id := range nonECSContainersIDs { | ||
response, _ := imageManager.client.InspectContainer(ctx, id, dockerclient.InspectContainerTimeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to check the error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added checking and logging
agent/engine/docker_image_manager.go
Outdated
|
||
var imageWithSizeList []ImageWithSize | ||
for _, imageName := range nonECSImageNamesRemoveEligible { | ||
resp, _ := imageManager.client.InspectImage(imageName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added checking and logging
agent/engine/docker_image_manager.go
Outdated
}) | ||
|
||
// we will remove the remaining nonECSImages in each performPeriodicImageCleanup call() | ||
var numImagesAlreadyDelete = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: numImagesAlreadyDeleted
ftest logs showing:
agent logs showing:
tracking here: #1763 |
response, _ := imageManager.client.InspectContainer(ctx, id, dockerclient.InspectContainerTimeout) | ||
response, icErr := imageManager.client.InspectContainer(ctx, id, dockerclient.InspectContainerTimeout) | ||
if icErr != nil { | ||
seelog.Errorf("Error inspecting non-ECS container id: %s - %v", id, icErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to add a continue
in this case since response
will contain nothing? same below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're correct on both accounts, will update.
3a24c35
to
ad95b99
Compare
@@ -126,6 +126,10 @@ const ( | |||
|
|||
// DefaultTaskMetadataBurstRate is set to handle 60 burst requests at once | |||
DefaultTaskMetadataBurstRate = 60 | |||
|
|||
//Known cached image names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space
Summary
updating #1736 with docker sdk client and merging to dev
Implementation details
Testing
make release
)go build -out amazon-ecs-agent.exe ./agent
)make test
) passgo test -timeout=25s ./agent/...
) passmake run-integ-tests
) pass.\scripts\run-integ-tests.ps1
) passmake run-functional-tests
) pass.\scripts\run-functional-tests.ps1
) passNew tests cover the changes:
Description for the changelog
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.