Fail early when an unsupported docker API version is found #4141
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
DockerClient
'sWithVersion
method andsdkclientfactory
'sNewFactory
function both deal with versioned docker clients. This PR improves the handling of unsupported API versions by detecting and reporting unsupported API versions sooner than later.WithVersion
method now checks if the requested API version is unsupported and returns an error to signal that to the consumer. Before this change the consumer would get back a versioned client even if the version is unsupported and any subsequent API calls on the returned client will fail later. Existing consumers of this method are*DockerTaskEngine.createContainer
and*DockerTaskEngine.startContainer
methods. Both are updated to ignore the returned error like they already do. The error is then dealt with later.sdkclientfactory.NewFactory
function already takes care of partitioning supported and unsupported API versions. It does so by checking for any errors during versioned client initialization. This is not enough for older Docker engine versions such as 17.03 as those versions do not fail client initialization when the engine's API version is lower than the client's API version. This PR updates the client initialization logic to ensure that the server's API version is not lower than client's API version.For example, with Docker engine 17.12 (which has API version 1.35),
sdkclientfactory.NewFactory
is able to detect that clients with API version >1.35 are not supported and prints the log below.However, this does not happen with Docker engine 17.03 and
sdkclientfactory.NewFactory
does not detect newer client versions as unsupported. With the change in this PR, unsupported client versions are detected and the following log is printed.Testing
In addition to new and updated unit tests, I performed the following manual test.
Added the following temporary test to initialize an
sdkclientfactory.Factory
and print the number of supported and known API versions.Without the changes in this PR, in an environment with Docker engine 17.03, the test prints the following output.
As can be seen from the test output, no unsupported API versions were detected and the count of known and supported API versions is the same at 28.
The behavior is different on an environment with Docker engine 17.12 as unsupported versions are detected.
With the changes in this PR, in an environment with Docker engine 17.03, the test prints the following output.
As is seen in the logs above, unsupported API versions are now detected.
There is no difference in behavior in environment with Docker engine 17.12.
New tests cover the changes: yes
Description for the changelog
Bugfix: Fail early when an unsupported docker API version is detected
Does this PR include breaking model changes? If so, Have you added transformation functions?
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.