Skip to content

Commit

Permalink
rearrange some code
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Jan 25, 2024
1 parent 90fbc0b commit 763e5ab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 43 deletions.
2 changes: 1 addition & 1 deletion agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions agent/app/agent_capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
34 changes: 0 additions & 34 deletions agent/dockerclient/dockerapi/docker_versions.go

This file was deleted.

23 changes: 23 additions & 0 deletions agent/dockerclient/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 763e5ab

Please sign in to comment.