Skip to content

Commit

Permalink
eventhandler: fix the bug where container state change was not submitted
Browse files Browse the repository at this point in the history
  • Loading branch information
Peng Yin authored and Noah Meyerhans committed Nov 10, 2017
1 parent 03fb033 commit d683254
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Changelog

## 1.15.1
* Bug - Fixed a bug where container state information wasn't reported. [#1067](https://github.com/aws/amazon-ecs-agent/pull/1067)
* Bug - Fixed a bug where a task can be blocked in creating state. [#1048](https://github.com/aws/amazon-ecs-agent/pull/1048)
* Bug - Fixed dynamic HostPort in container metadata. [#1052](https://github.com/aws/amazon-ecs-agent/pull/1052)

Expand Down
4 changes: 2 additions & 2 deletions agent/api/ecsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ func (client *APIECSClient) SubmitTaskStateChange(change api.TaskStateChange) er
return errors.New("ecs api client: SubmitTaskStateChange called with an invalid change")
}

if change.Status != api.TaskRunning && change.Status != api.TaskStopped {
if change.Status != api.TaskRunning && change.Status != api.TaskStopped && len(change.Containers) == 0 {
seelog.Debugf("Not submitting unsupported upstream task state: %s", change.Status.String())
// Not really an error
return nil
}

status := change.Status.String()
status := change.Status.BackendStatus()

req := ecs.SubmitTaskStateChangeInput{
Cluster: aws.String(client.config.Cluster),
Expand Down
40 changes: 39 additions & 1 deletion agent/api/ecsclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ func TestSubmitTaskStateChangeWithAttachments(t *testing.T) {
assert.NoError(t, err, "Unable to submit task state change with attachments")
}

//
func TestSubmitTaskStateChangeWithoutAttachments(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
Expand All @@ -696,3 +695,42 @@ func TestSubmitTaskStateChangeWithoutAttachments(t *testing.T) {
})
assert.NoError(t, err, "Unable to submit task state change with no attachments")
}

// TestSubmitContainerStateChangeWhileTaskInPending tests the container state change was submitted
// when the task is still in pending state
func TestSubmitContainerStateChangeWhileTaskInPending(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

client, _, mockSubmitStateClient := NewMockClient(mockCtrl, ec2.NewBlackholeEC2MetadataClient(), nil)
mockSubmitStateClient.EXPECT().SubmitTaskStateChange(&taskSubmitInputMatcher{
ecs.SubmitTaskStateChangeInput{
Cluster: strptr(configuredCluster),
Task: strptr("arn"),
Status: strptr("PENDING"),
Reason: strptr(""),
Containers: []*ecs.ContainerStateChange{
{
ContainerName: strptr("container"),
Status: strptr("RUNNING"),
NetworkBindings: []*ecs.NetworkBinding{},
},
},
},
})

taskStateChangePending := api.TaskStateChange{
Status: api.TaskCreated,
TaskARN: "arn",
Containers: []api.ContainerStateChange{
{
TaskArn: "arn",
ContainerName: "container",
Status: api.ContainerRunning,
},
},
}

err := client.SubmitTaskStateChange(taskStateChangePending)
assert.NoError(t, err)
}

0 comments on commit d683254

Please sign in to comment.