@@ -23,9 +23,13 @@ import (
23
23
24
24
const (
25
25
// minAPIVersionKey is the docker.Env key for min API version
26
+ // This is supported in Docker API versions >=1.25
27
+ // https://docs.docker.com/engine/api/version-history/#v125-api-changes
26
28
minAPIVersionKey = "MinAPIVersion"
27
29
// apiVersionKey is the docker.Env key for API version
28
30
apiVersionKey = "ApiVersion"
31
+ // zeroPatch is a string to append patch number zero if the major minor version lacks it
32
+ zeroPatch = ".0"
29
33
)
30
34
// Factory provides a collection of docker remote clients that include a
31
35
// recommended client version as well as a set of alternative supported
@@ -116,11 +120,11 @@ func (f *factory) getClient(version DockerVersion) (dockeriface.Client, error) {
116
120
// findDockerVersions loops over all known API versions and finds which ones
117
121
// are supported by the docker daemon on the host
118
122
func findDockerVersions (endpoint string ) map [DockerVersion ]dockeriface.Client {
119
- // if the client version returns a min version and api version , then use it to return
120
- // Docker versions
123
+ // if the client version returns a MinAPIVersion and APIVersion , then use it to return
124
+ // all the Docker clients between MinAPIVersion and APIVersion
121
125
clients , err := findDockerVersionsfromMinMaxVersions (endpoint )
122
126
if err != nil {
123
- log .Debugf ("Unable to get Docker clients from min API version: %v" , err )
127
+ log .Infof ("Unable to get Docker clients from min API version: %v" , err )
124
128
} else {
125
129
return clients
126
130
}
@@ -156,36 +160,40 @@ func findDockerVersionsfromMinMaxVersions(endpoint string) (map[DockerVersion]do
156
160
157
161
clients := make (map [DockerVersion ]dockeriface.Client )
158
162
// check if the docker.Env obj has MinAPIVersion key
159
- if clientVersion .Exists (minAPIVersionKey ) {
160
- minAPIVersion := clientVersion . Get ( minAPIVersionKey )
161
- apiVersion := clientVersion . Get ( apiVersionKey )
162
- for _ , version := range getKnownAPIVersions () {
163
- dockerClient , err := getDockerClientForVersion ( endpoint , string ( version ), minAPIVersion , apiVersion )
164
- if err != nil {
165
- log . Debugf ( "Unable to get Docker client for version %s: %v" , version , err )
166
- continue
167
- }
168
- clients [ version ] = dockerClient
163
+ if ! clientVersion .Exists (minAPIVersionKey ) {
164
+ return nil , errors . New ( "min API version not found in client version" )
165
+ }
166
+ minAPIVersion := clientVersion . Get ( minAPIVersionKey )
167
+ apiVersion := clientVersion . Get ( apiVersionKey )
168
+ for _ , version := range getKnownAPIVersions () {
169
+ dockerClient , err := getDockerClientForVersion ( endpoint , string ( version ), minAPIVersion , apiVersion )
170
+ if err != nil {
171
+ log . Infof ( "Unable to get Docker client for version %s: %v" , version , err )
172
+ continue
169
173
}
170
- return clients , nil
174
+ clients [ version ] = dockerClient
171
175
}
172
- return nil , errors . New ( "min API version not found in client version" )
176
+ return clients , nil
173
177
}
174
178
175
179
func getDockerClientForVersion (
176
180
endpoint string ,
177
181
version string ,
178
182
minAPIVersion string ,
179
183
apiVersion string ) (dockeriface.Client , error ) {
180
- lessThanMinCheck := "<" + minAPIVersion
181
- moreThanMaxCheck := ">" + apiVersion
182
- minVersionCheck , minErr := utils .Version (version ).Matches (lessThanMinCheck )
183
- maxVersionCheck , maxErr := utils .Version (version ).Matches (moreThanMaxCheck )
184
- if minErr != nil {
185
- return nil , errors .Wrapf (minErr , "error while comparing version %s with minAPIVersion %s" , version , minAPIVersion )
184
+ // Adding patch number zero to Docker versions to reuse the existing semver
185
+ // comparator
186
+ // TODO: remove this logic later when non-semver comparator is implemented
187
+ version += zeroPatch
188
+ lessThanMinCheck := "<" + minAPIVersion + zeroPatch
189
+ moreThanMaxCheck := ">" + apiVersion + zeroPatch
190
+ minVersionCheck , err := utils .Version (version ).Matches (lessThanMinCheck )
191
+ if err != nil {
192
+ return nil , errors .Wrapf (err , "error while comparing version %s with minAPIVersion %s" , version , minAPIVersion )
186
193
}
187
- if maxErr != nil {
188
- return nil , errors .Wrapf (minErr , "error while comparing version %s with apiVersion %s" , version , apiVersion )
194
+ maxVersionCheck , err := utils .Version (version ).Matches (moreThanMaxCheck )
195
+ if err != nil {
196
+ return nil , errors .Wrapf (err , "error while comparing version %s with apiVersion %s" , version , apiVersion )
189
197
}
190
198
// do not add the version when it is less than min api version or greater
191
199
// than api version
0 commit comments