diff --git a/agent/acs/handler/payload_handler.go b/agent/acs/handler/payload_handler.go index e4f81aee9ae..126466e5427 100644 --- a/agent/acs/handler/payload_handler.go +++ b/agent/acs/handler/payload_handler.go @@ -277,8 +277,7 @@ func (payloadHandler *payloadRequestHandler) addPayloadTasks(payload *ecsacs.Pay } // Construct a slice with credentials acks from all tasks - var credentialsAcks []*ecsacs.IAMRoleCredentialsAckRequest - credentialsAcks = append(stoppedTasksCredentialsAcks, newTasksCredentialsAcks...) + credentialsAcks := append(stoppedTasksCredentialsAcks, newTasksCredentialsAcks...) return credentialsAcks, allTasksOK } diff --git a/agent/api/container/container.go b/agent/api/container/container.go index eda464063b5..01e610c019b 100644 --- a/agent/api/container/container.go +++ b/agent/api/container/container.go @@ -497,11 +497,7 @@ func (c *Container) GetNextKnownStateProgression() apicontainerstatus.ContainerS // IsInternal returns true if the container type is `ContainerCNIPause` // or `ContainerNamespacePause`. It returns false otherwise func (c *Container) IsInternal() bool { - if c.Type == ContainerNormal { - return false - } - - return true + return c.Type != ContainerNormal } // IsRunning returns true if the container's known status is either RUNNING diff --git a/agent/api/task/task.go b/agent/api/task/task.go index e72bd4c3705..74b8772a53e 100644 --- a/agent/api/task/task.go +++ b/agent/api/task/task.go @@ -2586,15 +2586,6 @@ func (task *Task) GetContainerIndex(containerName string) int { return -1 } -func (task *Task) requireEnvfiles() bool { - for _, container := range task.Containers { - if container.ShouldCreateWithEnvFiles() { - return true - } - } - return false -} - func (task *Task) initializeEnvfilesResource(config *config.Config, credentialsManager credentials.Manager) error { for _, container := range task.Containers { diff --git a/agent/api/task/task_test.go b/agent/api/task/task_test.go index 0183d0b3228..0ea7cc1f0f8 100644 --- a/agent/api/task/task_test.go +++ b/agent/api/task/task_test.go @@ -3434,5 +3434,14 @@ func TestRequiresEnvfiles(t *testing.T) { Containers: []*apicontainer.Container{container}, } - assert.Equal(t, true, task.requireEnvfiles()) + assert.Equal(t, true, requireEnvfiles(task)) +} + +func requireEnvfiles(task *Task) bool { + for _, container := range task.Containers { + if container.ShouldCreateWithEnvFiles() { + return true + } + } + return false } diff --git a/agent/api/task/task_unsupported.go b/agent/api/task/task_unsupported.go index 25c75543c15..81904459337 100644 --- a/agent/api/task/task_unsupported.go +++ b/agent/api/task/task_unsupported.go @@ -27,15 +27,7 @@ import ( ) const ( - defaultCPUPeriod = 100 * time.Millisecond // 100ms - - // With a 100ms CPU period, we can express 0.01 vCPU to 10 vCPUs - maxTaskVCPULimit = 10 - // Reference: http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html - minimumCPUShare = 2 - minimumCPUPercent = 0 - bytesPerMegabyte = 1024 * 1024 ) // PlatformFields consists of fields specific to Linux for a task @@ -80,11 +72,6 @@ func (task *Task) initializeCredentialSpecResource(config *config.Config, creden return errors.New("task credentialspec is only supported on windows") } -// getAllCredentialSpecRequirements is used to build all the credential spec requirements for the task -func (task *Task) getAllCredentialSpecRequirements() []string { - return nil -} - // GetCredentialSpecResource retrieves credentialspec resource from resource map func (task *Task) GetCredentialSpecResource() ([]taskresource.TaskResource, bool) { return []taskresource.TaskResource{}, false diff --git a/agent/api/task/taskvolume.go b/agent/api/task/taskvolume.go index fcda021ec4d..05e696a88a8 100644 --- a/agent/api/task/taskvolume.go +++ b/agent/api/task/taskvolume.go @@ -29,8 +29,6 @@ const ( HostVolumeType = "host" DockerVolumeType = "docker" EFSVolumeType = "efs" - - efsVolumePluginCapability = "efsAuth" ) // TaskVolume is a definition of all the volumes available for containers to diff --git a/agent/app/agent_test.go b/agent/app/agent_test.go index 7de8d03f755..1a7f1aae8b6 100644 --- a/agent/app/agent_test.go +++ b/agent/app/agent_test.go @@ -579,7 +579,7 @@ func TestNewTaskEngineRestoreFromCheckpointClusterIDMismatch(t *testing.T) { _, _, err := agent.newTaskEngine(eventstream.NewEventStream("events", ctx), credentialsManager, state, imageManager) assert.Error(t, err) - assert.True(t, isClusterMismatch(err)) + assert.IsType(t, clusterMismatchError{}, err) } func TestNewTaskEngineRestoreFromCheckpointNewStateManagerError(t *testing.T) { diff --git a/agent/app/errors.go b/agent/app/errors.go index fae7c28bc35..06b02349b84 100644 --- a/agent/app/errors.go +++ b/agent/app/errors.go @@ -29,8 +29,3 @@ func isTransient(err error) bool { type clusterMismatchError struct { error } - -func isClusterMismatch(err error) bool { - _, ok := err.(clusterMismatchError) - return ok -} diff --git a/agent/dockerclient/dockerapi/docker_client.go b/agent/dockerclient/dockerapi/docker_client.go index eba65880b45..9d66d3205db 100644 --- a/agent/dockerclient/dockerapi/docker_client.go +++ b/agent/dockerclient/dockerapi/docker_client.go @@ -54,10 +54,6 @@ import ( const ( dockerDefaultTag = "latest" - // imageNameFormat is the name of a image may look like: repo:tag - imageNameFormat = "%s:%s" - // the buffer size will ensure agent doesn't miss any event from docker - dockerEventBufferSize = 100 // healthCheckStarting is the initial status returned from docker container health check healthCheckStarting = "starting" // healthCheckHealthy is the healthy status returned from docker container health check @@ -243,9 +239,6 @@ func (dg *dockerGoClient) WithVersion(version dockerclient.DockerVersion) Docker } } -// scratchCreateLock guards against multiple 'scratch' image creations at once -var scratchCreateLock sync.Mutex - // NewDockerGoClient creates a new DockerGoClient // TODO Remove clientfactory parameter once migration to Docker SDK is complete. func NewDockerGoClient(sdkclientFactory sdkclientfactory.Factory, @@ -1035,15 +1028,13 @@ func (dg *dockerGoClient) listImages(ctx context.Context) ListImagesResponse { if err != nil { return ListImagesResponse{Error: err} } - var imagesRepoTag []string + var imageRepoTags []string imageIDs := make([]string, len(images)) for i, image := range images { imageIDs[i] = image.ID - for _, imageRepoTag := range image.RepoTags { - imagesRepoTag = append(imagesRepoTag, imageRepoTag) - } + imageRepoTags = append(imageRepoTags, image.RepoTags...) } - return ListImagesResponse{ImageIDs: imageIDs, RepoTags: imagesRepoTag, Error: nil} + return ListImagesResponse{ImageIDs: imageIDs, RepoTags: imageRepoTags, Error: nil} } func (dg *dockerGoClient) SupportedVersions() []dockerclient.DockerVersion { diff --git a/agent/dockerclient/dockerapi/docker_client_test.go b/agent/dockerclient/dockerapi/docker_client_test.go index 81aaf2fe132..685ea1f772c 100644 --- a/agent/dockerclient/dockerapi/docker_client_test.go +++ b/agent/dockerclient/dockerapi/docker_client_test.go @@ -74,6 +74,7 @@ const ( xMaximumPullRetryDelay = 100 * time.Microsecond xPullRetryDelayMultiplier = 2 xPullRetryJitterMultiplier = 0.2 + dockerEventBufferSize = 100 ) func defaultTestConfig() *config.Config { diff --git a/agent/dockerclient/dockerapi/docker_events_buffer.go b/agent/dockerclient/dockerapi/docker_events_buffer.go index 27669bdc9f0..8e9667427e0 100644 --- a/agent/dockerclient/dockerapi/docker_events_buffer.go +++ b/agent/dockerclient/dockerapi/docker_events_buffer.go @@ -42,7 +42,6 @@ type InfiniteBuffer struct { events []*events.Message empty bool waitForEvent sync.WaitGroup - count int lock sync.RWMutex } diff --git a/agent/dockerclient/sdkclientfactory/sdkclientfactory.go b/agent/dockerclient/sdkclientfactory/sdkclientfactory.go index e57dfade64e..dc9f099404a 100644 --- a/agent/dockerclient/sdkclientfactory/sdkclientfactory.go +++ b/agent/dockerclient/sdkclientfactory/sdkclientfactory.go @@ -23,15 +23,6 @@ import ( "github.com/pkg/errors" ) -const ( - // minAPIVersionKey is the docker.Env key for min API version - // This is supported in Docker API versions >=1.25 - // https://docs.docker.com/engine/api/version-history/#v125-api-changes - minAPIVersionKey = "MinAPIVersion" - // apiVersionKey is the docker.Env key for API version - apiVersionKey = "ApiVersion" -) - // Factory provides a collection of docker remote clients that include a // recommended client version as well as a set of alternative supported // docker clients. diff --git a/agent/ecscni/plugin.go b/agent/ecscni/plugin.go index 4a7534f47b2..19595318603 100644 --- a/agent/ecscni/plugin.go +++ b/agent/ecscni/plugin.go @@ -90,11 +90,6 @@ func (client *cniClient) SetupNS( timeout time.Duration) (*current.Result, error) { ctx, cancel := context.WithTimeout(ctx, timeout) defer cancel() - - type output struct { - result *current.Result - err error - } return client.setupNS(ctx, cfg) } diff --git a/agent/stats/common_test.go b/agent/stats/common_test.go index ba607de466f..1dabada3c64 100644 --- a/agent/stats/common_test.go +++ b/agent/stats/common_test.go @@ -68,6 +68,12 @@ func init() { cfg.ImagePullBehavior = config.ImagePullPreferCachedBehavior } +// parseNanoTime returns the time object from a string formatted with RFC3339Nano layout. +func parseNanoTime(value string) time.Time { + ts, _ := time.Parse(time.RFC3339Nano, value) + return ts +} + // eventStream returns the event stream used to receive container change events func eventStream(name string) *eventstream.EventStream { eventStream := eventstream.NewEventStream(name, context.Background()) diff --git a/agent/stats/engine.go b/agent/stats/engine.go index 00481923896..6f9fb951aba 100644 --- a/agent/stats/engine.go +++ b/agent/stats/engine.go @@ -205,13 +205,10 @@ func (engine *DockerStatsEngine) Disable() { // waitToStop waits for the container change event stream close ans stop collection metrics func (engine *DockerStatsEngine) waitToStop() { // Waiting for the event stream to close - ctx := engine.containerChangeEventStream.Context() - select { - case <-ctx.Done(): - seelog.Debug("Event stream closed, stop listening to the event stream") - engine.containerChangeEventStream.Unsubscribe(containerChangeHandler) - engine.removeAll() - } + <-engine.containerChangeEventStream.Context().Done() + seelog.Debug("Event stream closed, stop listening to the event stream") + engine.containerChangeEventStream.Unsubscribe(containerChangeHandler) + engine.removeAll() } // removeAll stops the periodic usage data collection for all containers @@ -686,11 +683,3 @@ func (engine *DockerStatsEngine) ContainerDockerStats(taskARN string, containerI } return container.statsQueue.GetLastStat(), nil } - -// newMetricsMetadata creates the singleton metadata object. -func newMetricsMetadata(cluster *string, containerInstance *string) *ecstcs.MetricsMetadata { - return &ecstcs.MetricsMetadata{ - Cluster: cluster, - ContainerInstance: containerInstance, - } -} diff --git a/agent/stats/utils.go b/agent/stats/utils.go index 38dd4396f98..9ef0902a3a6 100644 --- a/agent/stats/utils.go +++ b/agent/stats/utils.go @@ -15,11 +15,8 @@ package stats import ( "math" - "regexp" "runtime" - "time" - "github.com/cihub/seelog" "github.com/docker/docker/api/types" ) @@ -34,24 +31,6 @@ func nan32() float32 { return (float32)(math.NaN()) } -// parseNanoTime returns the time object from a string formatted with RFC3339Nano layout. -func parseNanoTime(value string) time.Time { - ts, _ := time.Parse(time.RFC3339Nano, value) - return ts -} - -// isNetworkStatsError returns if the error indicates that files in /sys/class/net -// could not be opened. -func isNetworkStatsError(err error) bool { - matched, mErr := regexp.MatchString(networkStatsErrorPattern, err.Error()) - if mErr != nil { - seelog.Debugf("Error matching string: %v", mErr) - return false - } - - return matched -} - func getNetworkStats(dockerStats *types.StatsJSON) *NetworkStats { if dockerStats.Networks == nil { return nil diff --git a/agent/stats/utils_test.go b/agent/stats/utils_test.go index b5ae1f57049..75de6dc16ae 100644 --- a/agent/stats/utils_test.go +++ b/agent/stats/utils_test.go @@ -36,20 +36,6 @@ const ( expectedTxErrors = uint64(0) ) -func TestIsNetworkStatsError(t *testing.T) { - isNetStatsErr := isNetworkStatsError(fmt.Errorf("no such file or directory")) - if isNetStatsErr { - // Expect it to not be a net stats error - t.Error("Error incorrectly reported as network stats error") - } - - isNetStatsErr = isNetworkStatsError(fmt.Errorf("open /sys/class/net/veth2f5f3e4/statistics/tx_bytes: no such file or directory")) - if !isNetStatsErr { - // Expect this to be a net stats error - t.Error("Error incorrectly reported as non network stats error") - } -} - func TestDockerStatsToContainerStatsMemUsage(t *testing.T) { jsonStat := fmt.Sprintf(` {