Skip to content

Commit 787fab2

Browse files
author
Peng Yin
committed
eventhandler: fix the bug where container state change was not submitted
1 parent 7de1fc9 commit 787fab2

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

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

agent/api/ecsclient/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,13 @@ func (client *APIECSClient) SubmitTaskStateChange(change api.TaskStateChange) er
318318
return errors.New("ecs api client: SubmitTaskStateChange called with an invalid change")
319319
}
320320

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

327-
status := change.Status.String()
327+
status := change.Status.BackendStatus()
328328

329329
req := ecs.SubmitTaskStateChangeInput{
330330
Cluster: aws.String(client.config.Cluster),

agent/api/ecsclient/client_test.go

+39-1
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ func TestSubmitTaskStateChangeWithAttachments(t *testing.T) {
675675
assert.NoError(t, err, "Unable to submit task state change with attachments")
676676
}
677677

678-
//
679678
func TestSubmitTaskStateChangeWithoutAttachments(t *testing.T) {
680679
mockCtrl := gomock.NewController(t)
681680
defer mockCtrl.Finish()
@@ -696,3 +695,42 @@ func TestSubmitTaskStateChangeWithoutAttachments(t *testing.T) {
696695
})
697696
assert.NoError(t, err, "Unable to submit task state change with no attachments")
698697
}
698+
699+
// TestSubmitContainerStateChangeWhileTaskInPending tests the container state chagne was submitted
700+
// when the task is still in pending state
701+
func TestSubmitContainerStateChangeWhileTaskInPending(t *testing.T) {
702+
mockCtrl := gomock.NewController(t)
703+
defer mockCtrl.Finish()
704+
705+
client, _, mockSubmitStateClient := NewMockClient(mockCtrl, ec2.NewBlackholeEC2MetadataClient(), nil)
706+
mockSubmitStateClient.EXPECT().SubmitTaskStateChange(&taskSubmitInputMatcher{
707+
ecs.SubmitTaskStateChangeInput{
708+
Cluster: strptr(configuredCluster),
709+
Task: strptr("arn"),
710+
Status: strptr("PENDING"),
711+
Reason: strptr(""),
712+
Containers: []*ecs.ContainerStateChange{
713+
{
714+
ContainerName: strptr("container"),
715+
Status: strptr("RUNNING"),
716+
NetworkBindings: []*ecs.NetworkBinding{},
717+
},
718+
},
719+
},
720+
})
721+
722+
taskStateChangePending := api.TaskStateChange{
723+
Status: api.TaskCreated,
724+
TaskARN: "arn",
725+
Containers: []api.ContainerStateChange{
726+
{
727+
TaskArn: "arn",
728+
ContainerName: "container",
729+
Status: api.ContainerRunning,
730+
},
731+
},
732+
}
733+
734+
err := client.SubmitTaskStateChange(taskStateChangePending)
735+
assert.NoError(t, err)
736+
}

0 commit comments

Comments
 (0)