Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.28.0 stage #2032

Merged
merged 69 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
e63f93a
ecs and acs model changes for instance eni attachment confirmation
fenxiong Feb 14, 2019
e0b6a1b
Add functionality in Agent to confirm Trunk ENI attachment.
fenxiong Jan 22, 2019
96c473e
Merge branch 'dev' into eni-trunking
fenxiong Mar 4, 2019
5f65e9c
Merge pull request #1915 from fenxiong/eni-trunking
fenxiong Mar 4, 2019
b70e1c8
Capability and plugin verification for eni trunking.
fenxiong Jan 31, 2019
6ff6d78
Pass GOARCH in vpc plugin build target to support multi-arch build
fenxiong Mar 11, 2019
9eadb13
Model changes for ACS and CNI plugin, cni plugin invoke based on ENI
shubham2892 Feb 11, 2019
976fa56
Rename APIENI to InterfaceAssociationProtocol
shubham2892 Mar 14, 2019
bd7c3c3
Set interface in CNI config
shubham2892 Mar 16, 2019
28c5340
Update submodule
shubham2892 Mar 18, 2019
87bf96c
Fix test
shubham2892 Mar 18, 2019
5498add
Refactoring
shubham2892 Mar 18, 2019
627523e
add noiseDelta to telemetry test
fierlion Mar 20, 2019
46a36cd
Use Go 1.12 everywhere
petderek Mar 31, 2019
e8c3c8b
Enable windows integ/functional test to pass in image name as a param…
suneyz Mar 29, 2019
cc2dcc6
Merge pull request #1970 from petderek/upgrade-golang
petderek Apr 1, 2019
0d5358d
Merge pull request #1955 from fierlion/idleDelta
fierlion Apr 2, 2019
1887d82
engine: update container metadata when container status stays RUNNING
yumex93 Apr 1, 2019
f021f7d
integ_test: increase wait time for data in linking test
sharanyad Apr 2, 2019
fa3668e
Increase timeout for linux functional tests
sharanyad Apr 3, 2019
23202e5
Increase timeout for integ tests
ubhattacharjya Mar 28, 2019
9faa3c3
Merge pull request #1964 from ubhattacharjya/IncreaseTimeout
ubhattacharjya Apr 4, 2019
44d2926
Revise telemetry tests to use average across normalized datapoints
fierlion Apr 5, 2019
85ded35
Reduce the lower limit of ticks expected
shubham2892 Apr 3, 2019
0a698dc
Use constants for limits
shubham2892 Apr 3, 2019
f786fb3
Move rand.seed() to init
shubham2892 Apr 4, 2019
71a3b38
Fix inactivity timeout unit tests.
fenxiong Apr 4, 2019
aadc401
Merge pull request #1978 from fierlion/telemetryOutliers
fierlion Apr 8, 2019
a50f819
Merge branch 'dev' into eni-trunking
fenxiong Apr 10, 2019
4a899cd
Fix failing capability unit tests after merging.
fenxiong Apr 10, 2019
eb2d3be
Merge pull request #1982 from fenxiong/eni-trunking-merge
fenxiong Apr 10, 2019
5089fa7
Fix broken make target.
fenxiong Apr 14, 2019
c95c24d
Merge pull request #1972 from yumex93/fix-health-status
yumex93 Apr 17, 2019
d8b5fc7
Fix broken default make target 'docker'.
fenxiong Apr 16, 2019
800ac16
Avoid race condition in acs handler tests
shubham2892 Apr 12, 2019
bd661d0
Add more logs
shubham2892 Apr 15, 2019
088829c
Export image shas docker hub
shubham2892 Mar 21, 2019
e62bf9b
Parse SHA from docker push output
shubham2892 Mar 22, 2019
3d6f03a
Fix the path discovery
shubham2892 Mar 26, 2019
d756ee7
Replace export with global variable
shubham2892 Mar 27, 2019
b30a15a
Export image digest to a file
shubham2892 Mar 29, 2019
3e5df80
Add all the digests to a single file
shubham2892 Apr 2, 2019
9baa770
Bump windows ftest timeout.
fenxiong Apr 24, 2019
5666a7a
Merge branch 'dev' into eni-trunking
fenxiong Apr 25, 2019
9c32ba7
Merge pull request #1999 from fenxiong/eni-trunking-merge
fenxiong Apr 25, 2019
7c68b8f
eni/watcher: skip logging eni status sent error.
fenxiong Apr 24, 2019
0bc7c1e
Increasing verbosity of some of our logs
petderek Nov 9, 2018
ea24e81
Updating to go 1.12
yhlee-aws Apr 18, 2019
a278a02
Make CGroups CPU period configurable
boynux Oct 18, 2018
42b883e
taskresources: set terminal reason msg for all errors (#2004)
sparrc Apr 29, 2019
4d7b645
Fix telemetry test for ws2019
suneyz Apr 26, 2019
fcdfa2d
Merge branch 'master' into dev
fenxiong Apr 30, 2019
df83ed3
Merge pull request #2009 from fenxiong/merge-master
fenxiong May 1, 2019
b40c4cb
Fix TestShutdownOrder and turn on debug log for integ test.
fenxiong May 2, 2019
49d653b
Wait status active/inactive when task networking is enabled.
fenxiong Apr 30, 2019
a8d963b
Functional test checking if end points are reachable with ENI trunkin…
shubham2892 Mar 19, 2019
f474906
Add required instance check, enable trunking at account level, wait t…
shubham2892 Apr 22, 2019
d5eff20
Add func test for trunk eni attach/detach workflow.
fenxiong Apr 30, 2019
218fd22
Update require agent version to >=1.27.1 for trunking tests
fenxiong May 3, 2019
9fb3226
image manager: cleanup 'dead' and 'created' containers (#2015)
sparrc May 3, 2019
3d55475
Fix supported instance types for trunking tests.
fenxiong May 7, 2019
205983c
Merge branch 'eni-trunking' into dev.
fenxiong May 8, 2019
d7c94b3
Add Private Host IPv4 address to container metadata
Apr 23, 2019
1d49065
Merge branch 'dev' into merge-eni
fenxiong May 8, 2019
b5b86a4
Merge pull request #2026 from fenxiong/merge-eni
fenxiong May 8, 2019
231438c
Add changelog for agent 1.28.0.
fenxiong May 8, 2019
df9850f
Update required agent version to >1.27.0 for metadata test (#2028)
suneyz May 9, 2019
9fb7a0a
Add option to delay pause container teardown
petderek May 4, 2019
d2456be
update to 1.28.0
fenxiong May 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: go
go_import_path: github.com/aws/amazon-ecs-agent
sudo: false
go:
- 1.11
- 1.12

matrix:
include:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Changelog
## 1.28.0
* Feature - Introduce high density awsvpc tasks support
* Enhancement - Introduce `ECS_CGROUP_CPU_PERIOD` to make cgroup cpu period configurable [@boynux](https://github.com/boynux) [#1941](https://github.com/aws/amazon-ecs-agent/pull/1941)
* Enhancement - Add Private Host IPv4 address to container metadata [@bencord0](https://github.com/bencord0) [#2000](https://github.com/aws/amazon-ecs-agent/pull/2000)
* Enhancement - Set terminal reason for volume task resource [#2004](https://github.com/aws/amazon-ecs-agent/pull/2004)
* Bug - Fixed a bug where container health status is not updated when container status isn't changed [#1972](https://github.com/aws/amazon-ecs-agent/pull/1972)
* Bug - Fixed a bug where containers in 'dead' or 'created' status are not cleaned up by the agent [#2015](https://github.com/aws/amazon-ecs-agent/pull/2015)

## 1.27.0
* Feature - Add secret support for log drivers

Expand Down
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ test-artifacts-linux: $(LINUX_ARTIFACTS_TARGETS)
test-artifacts: test-artifacts-windows test-artifacts-linux

# Run our 'test' registry needed for integ and functional tests
test-registry: netkitten volumes-test namespace-tests pause-container squid awscli image-cleanup-test-images fluentd agent-introspection-validator taskmetadata-validator v3-task-endpoint-validator container-metadata-file-validator elastic-inference-validator appmesh-plugin-validator
test-registry: netkitten volumes-test namespace-tests pause-container squid awscli image-cleanup-test-images fluentd agent-introspection-validator taskmetadata-validator v3-task-endpoint-validator container-metadata-file-validator elastic-inference-validator
test-registry: netkitten volumes-test namespace-tests pause-container squid awscli image-cleanup-test-images fluentd \
agent-introspection-validator taskmetadata-validator v3-task-endpoint-validator \
container-metadata-file-validator elastic-inference-validator appmesh-plugin-validator \
eni-trunking-validator
@./scripts/setup-test-registry

test-in-docker:
Expand All @@ -205,11 +209,12 @@ test-in-docker:
docker run --net=none -v "$(PWD):/go/src/github.com/aws/amazon-ecs-agent" --privileged "amazon/amazon-ecs-agent-test:make"

run-functional-tests: testnnp test-registry ecr-execution-role-image telemetry-test-image
. ./scripts/shared_env && go test -tags functional -timeout=40m -v ./agent/functional_tests/...
. ./scripts/shared_env && go test -tags functional -timeout=60m -v ./agent/functional_tests/...

.PHONY: build-image-for-ecr ecr-execution-role-image-for-upload upload-images replicate-images

build-image-for-ecr: netkitten volumes-test squid awscli image-cleanup-test-images fluentd taskmetadata-validator testnnp container-health-check-image telemetry-test-image ecr-execution-role-image-for-upload
build-image-for-ecr: netkitten volumes-test squid awscli image-cleanup-test-images fluentd taskmetadata-validator \
testnnp container-health-check-image telemetry-test-image ecr-execution-role-image-for-upload

ecr-execution-role-image-for-upload:
$(MAKE) -C misc/ecr-execution-role-upload $(MFLAGS)
Expand Down Expand Up @@ -276,10 +281,10 @@ cni-plugins: get-cni-sources .out-stamp build-ecs-cni-plugins build-vpc-cni-plug

ifeq (${BUILD_PLATFORM},aarch64)
run-integ-tests: test-registry gremlin container-health-check-image run-sudo-tests
. ./scripts/shared_env && go test -tags integration -timeout=20m -v ./agent/engine/... ./agent/stats/... ./agent/app/...
. ./scripts/shared_env && ECS_LOGLEVEL=debug go test -tags integration -timeout=25m -v ./agent/engine/... ./agent/stats/... ./agent/app/...
else
run-integ-tests: test-registry gremlin container-health-check-image run-sudo-tests
. ./scripts/shared_env && go test -race -tags integration -timeout=20m -v ./agent/engine/... ./agent/stats/... ./agent/app/...
. ./scripts/shared_env && ECS_LOGLEVEL=debug go test -race -tags integration -timeout=25m -v ./agent/engine/... ./agent/stats/... ./agent/app/...
endif

ifeq (${BUILD_PLATFORM},aarch64)
Expand Down Expand Up @@ -344,6 +349,9 @@ taskmetadata-validator:
v3-task-endpoint-validator:
$(MAKE) -C misc/v3-task-endpoint-validator $(MFLAGS)

eni-trunking-validator:
$(MAKE) -C misc/eni-trunking-validator $(MFLAGS)

container-metadata-file-validator:
$(MAKE) -C misc/container-metadata-file-validator $(MFLAGS)

Expand Down Expand Up @@ -431,6 +439,7 @@ clean:
-$(MAKE) -C misc/container-health $(MFLAGS) clean
-$(MAKE) -C misc/telemetry $(MFLAGS) clean
-$(MAKE) -C misc/appmesh-plugin-validator $(MFLAGS) clean
-$(MAKE) -C misc/eni-trunking-validator $(MFLAGS) clean
-rm -f .get-deps-stamp
-rm -f .builder-image-stamp
-rm -f .out-stamp
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,15 @@ additional details on each available environment variable.
| `ECS_IMAGE_PULL_INACTIVITY_TIMEOUT` | 1m | The time to wait after docker pulls complete waiting for extraction of a container. Useful for tuning large Windows containers. | 1m | 3m |
| `ECS_INSTANCE_ATTRIBUTES` | `{"stack": "prod"}` | These attributes take effect only during initial registration. After the agent has joined an ECS cluster, use the PutAttributes API action to add additional attributes. For more information, see [Amazon ECS Container Agent Configuration](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-config.html) in the Amazon ECS Developer Guide.| `{}` | `{}` |
| `ECS_ENABLE_TASK_ENI` | `false` | Whether to enable task networking for task to be launched with its own network interface | `false` | Not applicable |
| `ECS_ENABLE_HIGH_DENSITY_ENI` | `false` | Whether to enable high density eni feature when using task networking | `true` | Not applicable |
| `ECS_CNI_PLUGINS_PATH` | `/ecs/cni` | The path where the cni binary file is located | `/amazon-ecs-cni-plugins` | Not applicable |
| `ECS_AWSVPC_BLOCK_IMDS` | `true` | Whether to block access to [Instance Metadata](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html) for Tasks started with `awsvpc` network mode | `false` | Not applicable |
| `ECS_AWSVPC_ADDITIONAL_LOCAL_ROUTES` | `["10.0.15.0/24"]` | In `awsvpc` network mode, traffic to these prefixes will be routed via the host bridge instead of the task ENI | `[]` | Not applicable |
| `ECS_ENABLE_CONTAINER_METADATA` | `true` | When `true`, the agent will create a file describing the container's metadata and the file can be located and consumed by using the container enviornment variable `$ECS_CONTAINER_METADATA_FILE` | `false` | `false` |
| `ECS_HOST_DATA_DIR` | `/var/lib/ecs` | The source directory on the host from which ECS_DATADIR is mounted. We use this to determine the source mount path for container metadata files in the case the ECS Agent is running as a container. We do not use this value in Windows because the ECS Agent is not running as container in Windows. | `/var/lib/ecs` | `Not used` |
| `ECS_ENABLE_TASK_CPU_MEM_LIMIT` | `true` | Whether to enable task-level cpu and memory limits | `true` | `false` |
| `ECS_CGROUP_PATH` | `/sys/fs/cgroup` | The root cgroup path that is expected by the ECS agent. This is the path that accessible from the agent mount. | `/sys/fs/cgroup` | Not applicable |
| `ECS_CGROUP_CPU_PERIOD` | `10ms` | CGroups CPU period for task level limits. This value should be between 8ms to 100ms | `100ms` | Not applicable |
| `ECS_ENABLE_CPU_UNBOUNDED_WINDOWS_WORKAROUND` | `true` | When `true`, ECS will allow CPU unbounded(CPU=`0`) tasks to run along with CPU bounded tasks in Windows. | Not applicable | `false` |
| `ECS_TASK_METADATA_RPS_LIMIT` | `100,150` | Comma separated integer values for steady state and burst throttle limits for task metadata endpoint | `40,60` | `40,60` |
| `ECS_SHARED_VOLUME_MATCH_FULL_CONFIG` | `true` | When `true`, ECS Agent will compare name, driver options, and labels to make sure volumes are identical. When `false`, Agent will short circuit shared volume comparison if the names match. This is the default Docker behavior. If a volume is shared across instances, this should be set to `false`. | `false` | `false`|
Expand Down
25 changes: 24 additions & 1 deletion THIRD-PARTY
Original file line number Diff line number Diff line change
Expand Up @@ -712,4 +712,27 @@ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-----

** github.com/sparrc/go-ping; version v0.0.0-20181106165434-ef3ab45e41b0 -- https://github.com/sparrc/go-ping
Copyright (c) 2016 Cameron Sparr

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.27.0
1.28.0
1 change: 0 additions & 1 deletion agent/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 72 additions & 1 deletion agent/acs/client/acs_client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build unit

// Copyright 2014-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 2014-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
Expand Down Expand Up @@ -75,6 +75,27 @@ const (
}]
}
}
`
sampleAttachInstanceENIMessage = `
{
"type": "AttachInstanceNetworkInterfacesMessage",
"message": {
"messageId": "123",
"clusterArn": "default",
"elasticNetworkInterfaces":[{
"attachmentArn": "attach_arn",
"ec2Id": "eni_id",
"ipv4Addresses":[{
"primary": true,
"privateAddress": "ipv4"
}],
"ipv6Addresses":[{
"address": "ipv6"
}],
"macAddress": "mac"
}]
}
}
`
)

Expand Down Expand Up @@ -410,3 +431,53 @@ func TestAttachENIHandlerCalled(t *testing.T) {

assert.Equal(t, <-messageChannel, expectedMessage)
}

func TestAttachInstanceENIHandlerCalled(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

conn := mock_wsconn.NewMockWebsocketConn(ctrl)
cs := testCS(conn)
defer cs.Close()

// Messages should be read from the connection at least once
conn.EXPECT().SetReadDeadline(gomock.Any()).Return(nil).MinTimes(1)
conn.EXPECT().ReadMessage().Return(websocket.TextMessage,
[]byte(sampleAttachInstanceENIMessage), nil).MinTimes(1)
// Invoked when closing the connection
conn.EXPECT().SetWriteDeadline(gomock.Any()).Return(nil)
conn.EXPECT().Close()

messageChannel := make(chan *ecsacs.AttachInstanceNetworkInterfacesMessage)
reqHandler := func(message *ecsacs.AttachInstanceNetworkInterfacesMessage) {
messageChannel <- message
}

cs.AddRequestHandler(reqHandler)

go cs.Serve()

expectedMessage := &ecsacs.AttachInstanceNetworkInterfacesMessage{
MessageId: aws.String("123"),
ClusterArn: aws.String("default"),
ElasticNetworkInterfaces: []*ecsacs.ElasticNetworkInterface{
{AttachmentArn: aws.String("attach_arn"),
Ec2Id: aws.String("eni_id"),
Ipv4Addresses: []*ecsacs.IPv4AddressAssignment{
{
Primary: aws.Bool(true),
PrivateAddress: aws.String("ipv4"),
},
},
Ipv6Addresses: []*ecsacs.IPv6AddressAssignment{
{
Address: aws.String("ipv6"),
},
},
MacAddress: aws.String("mac"),
},
},
}

assert.Equal(t, <-messageChannel, expectedMessage)
}
3 changes: 2 additions & 1 deletion agent/acs/client/acs_client_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 2014-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
Expand Down Expand Up @@ -46,6 +46,7 @@ func init() {
ecsacs.InactiveInstanceException{},
ecsacs.ErrorMessage{},
ecsacs.AttachTaskNetworkInterfacesMessage{},
ecsacs.AttachInstanceNetworkInterfacesMessage{},
}
}

Expand Down
8 changes: 4 additions & 4 deletions agent/acs/client/acs_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ func TestServerException(t *testing.T) {
func TestGenericErrorConversion(t *testing.T) {
err := acsErr.NewError(errors.New("generic error"))

require.True(t, err.Retry(),"Should default to retriable")
require.EqualError(t, err, "ACSError: generic error")
require.True(t, err.Retry(), "Should default to retriable")
require.EqualError(t, err, "ACSError: generic error")
}

func TestSomeRandomTypeConversion(t *testing.T) {
// This is really just an 'it doesn't panic' check.
err := acsErr.NewError(t)
require.True(t, err.Retry(),"Should default to retriable")
require.True(t, err.Retry(), "Should default to retriable")
require.True(t, strings.HasPrefix(err.Error(), "ACSError: Unknown error"))
}

func TestBadlyTypedMessage(t *testing.T) {
// Another 'does not panic' check
err := acsErr.NewError(struct{ Message int }{1})
require.True(t, err.Retry(),"Should default to retriable")
require.True(t, err.Retry(), "Should default to retriable")
require.NotNil(t, err.Error())
}
24 changes: 21 additions & 3 deletions agent/acs/handler/acs_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (acsSession *session) Start() error {
if shouldReconnectWithoutBackoff(acsError) {
// If ACS closed the connection, there's no need to backoff,
// reconnect immediately
seelog.Info("ACS Websocket connection closed for a valid reason")
seelog.Infof("ACS Websocket connection closed for a valid reason: %v", acsError)
acsSession.backoff.Reset()
sendEmptyMessageOnChannel(connectToACS)
} else {
Expand All @@ -219,6 +219,7 @@ func (acsSession *session) Start() error {
// If the context was not cancelled and we've waited for the
// wait duration without any errors, send the message to the channel
// to reconnect to ACS
seelog.Info("Done waiting; reconnecting to ACS")
sendEmptyMessageOnChannel(connectToACS)
} else {
// Wait was interrupted. We expect the session to close as canceling
Expand Down Expand Up @@ -265,8 +266,8 @@ func (acsSession *session) startACSSession(client wsclient.ClientServer) error {

client.AddRequestHandler(refreshCredsHandler.handlerFunc())

// Add handler to ack ENI attach message
eniAttachHandler := newAttachENIHandler(
// Add handler to ack task ENI attach message
eniAttachHandler := newAttachTaskENIHandler(
acsSession.ctx,
cfg.Cluster,
acsSession.containerInstanceARN,
Expand All @@ -279,6 +280,20 @@ func (acsSession *session) startACSSession(client wsclient.ClientServer) error {

client.AddRequestHandler(eniAttachHandler.handlerFunc())

// Add handler to ack instance ENI attach message
instanceENIAttachHandler := newAttachInstanceENIHandler(
acsSession.ctx,
cfg.Cluster,
acsSession.containerInstanceARN,
client,
acsSession.state,
acsSession.stateManager,
)
instanceENIAttachHandler.start()
defer instanceENIAttachHandler.stop()

client.AddRequestHandler(instanceENIAttachHandler.handlerFunc())

// Add request handler for handling payload messages from ACS
payloadHandler := newPayloadRequestHandler(
acsSession.ctx,
Expand Down Expand Up @@ -308,6 +323,7 @@ func (acsSession *session) startACSSession(client wsclient.ClientServer) error {
seelog.Errorf("Error connecting to ACS: %v", err)
return err
}

seelog.Info("Connected to ACS endpoint")
// Start inactivity timer for closing the connection
timer := newDisconnectionTimer(client, acsSession.heartbeatTimeout(), acsSession.heartbeatJitter())
Expand Down Expand Up @@ -337,11 +353,13 @@ func (acsSession *session) startACSSession(client wsclient.ClientServer) error {
case <-acsSession.ctx.Done():
// Stop receiving and sending messages from and to ACS when
// the context received from the main function is canceled
seelog.Infof("ACS session context cancelled.")
return acsSession.ctx.Err()
case err := <-serveErr:
// Stop receiving and sending messages from and to ACS when
// client.Serve returns an error. This can happen when the
// the connection is closed by ACS or the agent
seelog.Errorf("Error serving to ACS Webserver: %v", err)
return err
}
}
Expand Down
12 changes: 6 additions & 6 deletions agent/acs/handler/acs_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func TestHandlerReconnectsOnConnectErrors(t *testing.T) {
mockWsClient := mock_wsclient.NewMockClientServer(ctrl)
mockWsClient.EXPECT().SetAnyRequestHandler(gomock.Any()).AnyTimes()
mockWsClient.EXPECT().AddRequestHandler(gomock.Any()).AnyTimes()
mockWsClient.EXPECT().Serve().AnyTimes()
mockWsClient.EXPECT().Close().Return(nil).AnyTimes()
gomock.InOrder(
// Connect fails 10 times
Expand All @@ -224,7 +225,7 @@ func TestHandlerReconnectsOnConnectErrors(t *testing.T) {
// test to time out as the context is never cancelled
mockWsClient.EXPECT().Connect().Do(func() {
cancel()
}).Return(io.EOF).MinTimes(1),
}).Return(nil).MinTimes(1),
)
acsSession := session{
containerInstanceARN: "myArn",
Expand Down Expand Up @@ -616,7 +617,7 @@ func TestHandlerReconnectsOnServeErrors(t *testing.T) {
// test to time out as the context is never cancelled
mockWsClient.EXPECT().Serve().Do(func() {
cancel()
}).Return(io.EOF),
}),
)

acsSession := session{
Expand Down Expand Up @@ -711,12 +712,12 @@ func TestHandlerReconnectsOnDiscoverPollEndpointError(t *testing.T) {
mockWsClient := mock_wsclient.NewMockClientServer(ctrl)
mockWsClient.EXPECT().SetAnyRequestHandler(gomock.Any()).AnyTimes()
mockWsClient.EXPECT().AddRequestHandler(gomock.Any()).AnyTimes()
mockWsClient.EXPECT().Connect().Return(nil).AnyTimes()
mockWsClient.EXPECT().Serve().AnyTimes()
mockWsClient.EXPECT().Close().Return(nil).AnyTimes()
mockWsClient.EXPECT().Serve().Do(func() {
mockWsClient.EXPECT().Connect().Do(func() {
// Serve() cancels the context
cancel()
}).Return(io.EOF).MinTimes(1)
}).Return(nil).MinTimes(1)

gomock.InOrder(
// DiscoverPollEndpoint returns an error on its first invocation
Expand Down Expand Up @@ -761,7 +762,6 @@ func TestHandlerReconnectsOnDiscoverPollEndpointError(t *testing.T) {
if timeSinceStart > 2*connectionBackoffMin {
t.Errorf("Duration since start is greater than maximum anticipated wait time: %v", timeSinceStart.String())
}

}

// TestConnectionIsClosedOnIdle tests if the connection to ACS is closed
Expand Down
Loading