-
Notifications
You must be signed in to change notification settings - Fork 301
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
Teardowns the local network on "local stop" #775
Conversation
Manual Tests1.
|
|
||
if len(resp.Containers) > 1 { | ||
// Has other containers running in the network | ||
return true |
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'd suggest adding a log statement here so that users have more visibility in the case where teardown is being skipped because they had launched other containers in the network
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.
Done! Added "%d other task(s) running locally, skipping network removal."
// | ||
// If the user stops the last running task in the local network then also remove the network. | ||
func Stop(c *cli.Context) { | ||
docker, err := client.NewEnvClient() // Temporary client created to test network.Teardown() |
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 might want to consider doing something like I did here: https://github.com/awslabs/amazon-ecs-local-container-endpoints/blob/master/local-container-endpoints/clients/docker/client.go#L49
I once or twice ran into weird problems where the client API version was too new for my local docker. If you lock it to the min version that is needed, then customers are safe.
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.
👍 sorry it wasn't clear, the comment meant to denote that this Docker client initialization is temporary. I'll implement the suggestion in a later PR once we actually start working on the Stop
and Up
commands.
I updated the comment with a TODO and with the link you shared to make this more obvious :)
|
||
err := d.ContainerStop(ctx, localEndpointsContainerName, nil) | ||
if err != nil { | ||
if strings.Contains(strings.ToLower(err.Error()), "no such container") { |
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.
Why is this needed?
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.
Great question, looks like the comment below wasn't precise enough :P
This error happens if the user stopped all their task containers with docker stop
instead of ecs-cli local stop
. In that situation, hasRunningTasksInNetwork()
will return false
and we will try to stop the endpoints container again. But since it was already stopped this error is returned.
We don't want to log.Fatal
while trying to stop an already stopped container, it should be a no-op hence this if-statement.
I updated the comment to // The containers in the network were already stopped by the user using "docker stop", do nothing.
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.
An alternative is to not invoke stopEndpointsContainer()
or removeEndpointsContainer()
if there are 0 containers in the local network.
However, I think that approach pushes complexity upwards instead of downwards (into the function) so I don't prefer it as much. Also if you run ecs-cli local stop
on the same task concurrently (two terminals for example) then one of those could trigger this error and fail with fatal instead of continuing cleanly by not doing any work.
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.
Got it... my only concern is that this is yet another place where we are using string matching on errors returned by Docker :/
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.
Yeah, I agree but I think Docker locked themselves and can't change their error messages otherwise they'll break everyone's code :P
Here is a similar example from the agent: https://github.com/aws/amazon-ecs-agent/blob/24c71162368b3a9090689532e5c035fe2bccf133/agent/dockerclient/dockerapi/docker_client.go#L693
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.
This is my least favorite thing in Go...
@@ -77,7 +77,7 @@ const ( | |||
) | |||
|
|||
// Setup creates a user-defined bridge network with a running Local Container Endpoints container. If the network | |||
// already exists or the container is already running then the operation is a no-op. | |||
// already exists or the container is already running then this function does nothing. |
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.
Very minor nit: this change and the other one in teardown.go probably shouldn't be in the "generate mocks" commit.
If you plan to squash all changes to one commit prior to merge, then don't worry about it
|
Description of changes: Remove the local endpoints container and the local network if the user doesn't need them anymore. Freeing up resources on their machine.
Enter
[N/A]
in the box, if an item is not applicable to your change.Testing
Documentation
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.