diff --git a/agent/app/agent.go b/agent/app/agent.go index f385a53b7fe..39c4e5c5176 100644 --- a/agent/app/agent.go +++ b/agent/app/agent.go @@ -1101,7 +1101,7 @@ func (agent *ecsAgent) startACSSession( // Minimum docker version supported is 1.9.0, maps to api version 1.21 // see https://docs.docker.com/develop/sdk/#api-version-matrix func (agent *ecsAgent) verifyRequiredDockerVersion() (int, bool) { - supportedVersions := dockerapi.SupportedVersionsExtended(agent.dockerClient) + supportedVersions := dockerclient.SupportedVersionsExtended(agent.dockerClient.SupportedVersions) if len(supportedVersions) == 0 { seelog.Critical("Could not get supported docker versions.") return exitcodes.ExitError, false diff --git a/agent/app/agent_capability.go b/agent/app/agent_capability.go index 15958a88203..aef94844aad 100644 --- a/agent/app/agent_capability.go +++ b/agent/app/agent_capability.go @@ -22,7 +22,6 @@ import ( "github.com/aws/amazon-ecs-agent/agent/config" "github.com/aws/amazon-ecs-agent/agent/dockerclient" - "github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi" dm "github.com/aws/amazon-ecs-agent/agent/engine/daemonmanager" "github.com/aws/amazon-ecs-agent/ecs-agent/api/ecs/model/ecs" "github.com/aws/amazon-ecs-agent/ecs-agent/logger" @@ -208,13 +207,8 @@ func (agent *ecsAgent) capabilities() ([]*ecs.Attribute, error) { supportedVersions := make(map[dockerclient.DockerVersion]bool) // Determine API versions to report as supported via com.amazonaws.ecs.capability.docker-remote-api.X.XX capabilities - // We advertise all known versions here rather than "supported" versions. The reason for this is that ECS backend - // adds required capabilities to some features at the minimum supported version. If this is less than our Minimum - // supported version (currently 1.24), then the capability will not match. - // In other words, here we advertise supporting docker api versions that this agent may not actually support, for the - // sake of task definition required attributes. - // TODO edit this comment ^ - for _, version := range dockerapi.SupportedVersionsExtended(agent.dockerClient) { + // and for determining which features we support that depend on specific docker API versions + for _, version := range dockerclient.SupportedVersionsExtended(agent.dockerClient.SupportedVersions) { capabilities = appendNameOnlyAttribute(capabilities, capabilityPrefix+"docker-remote-api."+string(version)) supportedVersions[version] = true } diff --git a/agent/dockerclient/dockerapi/docker_versions.go b/agent/dockerclient/dockerapi/docker_versions.go deleted file mode 100644 index 8b856ef5850..00000000000 --- a/agent/dockerclient/dockerapi/docker_versions.go +++ /dev/null @@ -1,34 +0,0 @@ -package dockerapi - -import ( - "fmt" - - "github.com/aws/amazon-ecs-agent/agent/dockerclient" - "github.com/aws/amazon-ecs-agent/ecs-agent/logger" -) - -// SupportedVersionsExtended TODO doc -func SupportedVersionsExtended(dg DockerClient) []dockerclient.DockerVersion { - supportedAPIVersions := dg.SupportedVersions() - cmp := dockerclient.MinDockerAPIVersion.Compare(dockerclient.Version_1_24) - - if cmp == 1 || cmp == 0 { - extendedAPIVersions := []dockerclient.DockerVersion{} - knownAPIVersions := dockerclient.GetKnownAPIVersions() - for _, knownAPIVersion := range knownAPIVersions { - lessThanMinAPIVersion, err := dockerclient.DockerAPIVersion(knownAPIVersion).Matches(fmt.Sprintf("<%s", dockerclient.MinDockerAPIVersion)) - if err != nil { - continue - } - if lessThanMinAPIVersion { - extendedAPIVersions = append(extendedAPIVersions, knownAPIVersion) - } - } - supportedAPIVersions = append(extendedAPIVersions, supportedAPIVersions...) - } - - logger.Debug("Extended supported versions", logger.Fields{ - "supportedVersions": supportedAPIVersions, - }) - return supportedAPIVersions -} diff --git a/agent/dockerclient/versions.go b/agent/dockerclient/versions.go index 4a4c04f31ff..2e543313672 100644 --- a/agent/dockerclient/versions.go +++ b/agent/dockerclient/versions.go @@ -81,6 +81,29 @@ func (d DockerVersion) Compare(rhs DockerVersion) int { return 1 } +// SupportedVersionsExtended +func SupportedVersionsExtended(supportedVersionsFn func() []DockerVersion) []DockerVersion { + supportedAPIVersions := supportedVersionsFn() + cmp := MinDockerAPIVersion.Compare(Version_1_24) + + if cmp == 1 || cmp == 0 { + extendedAPIVersions := []DockerVersion{} + knownAPIVersions := GetKnownAPIVersions() + for _, knownAPIVersion := range knownAPIVersions { + if knownAPIVersion.Compare(MinDockerAPIVersion) < 0 { + extendedAPIVersions = append(extendedAPIVersions, knownAPIVersion) + } + } + supportedAPIVersions = append(extendedAPIVersions, supportedAPIVersions...) + } + + logger.Debug("Extended supported versions", logger.Fields{ + "supportedVersions": supportedAPIVersions, + }) + return supportedAPIVersions +} + +// SetMinDockerAPIVersion func SetMinDockerAPIVersion(v DockerVersion) { MinDockerAPIVersionMu.Lock() defer MinDockerAPIVersionMu.Unlock()