aws / amazon-ecs-init

Amazon Elastic Container Service RPM
http://aws.amazon.com/ecs
Apache License 2.0
199 stars 118 forks source link

Initialize docker client lazily #453

Closed angelcar closed 2 years ago

angelcar commented 2 years ago

Summary

Initialize docker client lazily. This will help mitigate the issues observed in https://github.com/aws/amazon-ecs-init/issues/448

Implementation details

Initializing docker client lazily when docker.Client is invoked.

In order to mock docker client in UTs, docker.Client is aliased by means of package-level variable. This variable is overridden in UTs with a function that returns a mocked docker client.

No drastic changes in logic are introduced with this change, but merely the way in which the docker client is wired.

Testing

UTs passing, built ecs-init binary and verified it is still able to start and stop the ecs-agent.

New tests cover the changes: yes

Description for the changelog

Licensing

This contribution is under the terms of the Apache 2.0 License: