Skip to content

Commit 63c013e

Browse files
committed
engine/dockerclient: fixup error messages format
1 parent 331a171 commit 63c013e

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

agent/engine/dockerclient/dockerclientfactory.go

+11-13
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ import (
2222
)
2323

2424
const (
25-
// minDockerAPILinux is the min Docker API version supported by agent
26-
minDockerAPILinux = Version_1_17
2725
// minAPIVersionKey is the docker.Env key for min API version
28-
minAPIVersionKey = "MinAPIVersion"
26+
minAPIVersionKey = "MinAPIVersion"
2927
// apiVersionKey is the docker.Env key for API version
30-
apiVersionKey = "ApiVersion"
28+
apiVersionKey = "ApiVersion"
3129
)
3230
// Factory provides a collection of docker remote clients that include a
3331
// recommended client version as well as a set of alternative supported
@@ -122,7 +120,7 @@ func findDockerVersions(endpoint string) map[DockerVersion]dockeriface.Client {
122120
// Docker versions
123121
clients, err := findDockerVersionsfromMinMaxVersions(endpoint)
124122
if err != nil {
125-
log.Infof("Error getting Docker clients from min API version: %v", err)
123+
log.Debugf("Unable to get Docker clients from min API version: %v", err)
126124
} else {
127125
return clients
128126
}
@@ -146,14 +144,14 @@ func findDockerVersions(endpoint string) map[DockerVersion]dockeriface.Client {
146144

147145
func findDockerVersionsfromMinMaxVersions(endpoint string) (map[DockerVersion]dockeriface.Client, error) {
148146
// get a Docker client with the default supported version
149-
client, err := newVersionedClient(endpoint, string(minDockerAPILinux))
147+
client, err := newVersionedClient(endpoint, string(minDockerAPIVersion))
150148
if err != nil {
151-
return nil, errors.Wrap(err, "Error while creating client")
149+
return nil, errors.Wrap(err, "min API version check: error while creating default Docker client")
152150
}
153151

154152
clientVersion, err := client.Version()
155153
if err != nil {
156-
return nil, errors.Wrap(err, "Error while getting client version")
154+
return nil, errors.Wrap(err, "min API version check: error while getting client version")
157155
}
158156

159157
clients := make(map[DockerVersion]dockeriface.Client)
@@ -164,7 +162,7 @@ func findDockerVersionsfromMinMaxVersions(endpoint string) (map[DockerVersion]do
164162
for _, version := range getKnownAPIVersions() {
165163
dockerClient, err := getDockerClientForVersion(endpoint, string(version), minAPIVersion, apiVersion)
166164
if err != nil {
167-
log.Infof("Error getting client version: %v", err)
165+
log.Debugf("Unable to get Docker client for version %s: %v", version, err)
168166
continue
169167
}
170168
clients[version] = dockerClient
@@ -184,19 +182,19 @@ func getDockerClientForVersion(
184182
minVersionCheck, minErr := utils.Version(version).Matches(lessThanMinCheck)
185183
maxVersionCheck, maxErr := utils.Version(version).Matches(moreThanMaxCheck)
186184
if minErr != nil {
187-
return nil, errors.Wrapf(minErr, "Error while comparing version %s with minAPIVersion %s", version, minAPIVersion)
185+
return nil, errors.Wrapf(minErr, "error while comparing version %s with minAPIVersion %s", version, minAPIVersion)
188186
}
189187
if maxErr != nil {
190-
return nil, errors.Wrapf(minErr, "Error while comparing version %s with apiVersion %s", version, apiVersion)
188+
return nil, errors.Wrapf(minErr, "error while comparing version %s with apiVersion %s", version, apiVersion)
191189
}
192190
// do not add the version when it is less than min api version or greater
193191
// than api version
194192
if minVersionCheck || maxVersionCheck {
195-
return nil, errors.Errorf("Min and API versions comparison check failed for version: %s", version)
193+
return nil, errors.Errorf("min and API versions comparison check failed for version: %s", version)
196194
}
197195
client, err := newVersionedClient(endpoint, string(version))
198196
if err != nil {
199-
return nil, errors.Wrap(err, "Error while creating client")
197+
return nil, errors.Wrapf(err, "unable to create Docker client for version: %s", version)
200198
}
201199
return client, nil
202200
}

agent/engine/dockerclient/dockerclientfactory_windows_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestGetClientMinimumVersion(t *testing.T) {
3232

3333
newVersionedClient = func(endpoint, version string) (dockeriface.Client, error) {
3434
mockClient := mock_dockeriface.NewMockClient(ctrl)
35-
if version == string(MinDockerAPIWindows) {
35+
if version == string(minDockerAPIVersion) {
3636
mockClient = expectedClient
3737
}
3838
mockClient.EXPECT().Version().Return(&docker.Env{}, nil).AnyTimes()

agent/engine/dockerclient/versionsupport_unix.go

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import (
1818
"github.com/aws/amazon-ecs-agent/agent/engine/dockeriface"
1919
)
2020

21+
const (
22+
// minDockerAPIVersion is the min Docker API version supported by agent
23+
minDockerAPIVersion = Version_1_17
24+
)
2125
// GetClient on linux will simply return the cached client from the map
2226
func (f *factory) GetClient(version DockerVersion) (dockeriface.Client, error) {
2327
return f.getClient(version)

agent/engine/dockerclient/versionsupport_windows.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import (
1818
"github.com/aws/amazon-ecs-agent/agent/engine/dockeriface"
1919
)
2020

21-
const MinDockerAPIWindows = Version_1_24
21+
const minDockerAPIVersion = Version_1_24
2222

2323
// GetClient will replace some versions of Docker on Windows. We need this because
2424
// agent assumes that it can always call older versions of the docker API.
2525
func (f *factory) GetClient(version DockerVersion) (dockeriface.Client, error) {
2626
for _, v := range getWindowsReplaceableVersions() {
2727
if v == version {
28-
version = MinDockerAPIWindows
28+
version = minDockerAPIVersion
2929
break
3030
}
3131
}
@@ -48,10 +48,10 @@ func getWindowsReplaceableVersions() []DockerVersion {
4848

4949
// getAgentVersions for Windows should return all of the replaceable versions plus additional versions
5050
func getAgentVersions() []DockerVersion {
51-
return append(getWindowsReplaceableVersions(), MinDockerAPIWindows)
51+
return append(getWindowsReplaceableVersions(), minDockerAPIVersion)
5252
}
5353

5454
// getDefaultVersion returns agent's default version of the Docker API
5555
func getDefaultVersion() DockerVersion {
56-
return MinDockerAPIWindows
56+
return minDockerAPIVersion
5757
}

agent/utils/compare_versions.go

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func parseSemver(version string) (semver, error) {
136136
return result, nil
137137
}
138138

139+
// TODO: remove this logic once non-semver comparator is implemented
139140
func appendIfNoPatch(version string) string {
140141
versionParts := strings.Split(version, ".")
141142
// Only major and minor versions are present

0 commit comments

Comments
 (0)