Skip to content

Commit b841c6c

Browse files
committed
Allow --create-log-groups when only some containers use awslogs
1 parent 6109999 commit b841c6c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

ecs-cli/modules/cli/logs/logs_app.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ func logConfigMisMatchError(taskDef *ecs.TaskDefinition, fieldName string) error
309309
// CreateLogGroups creates any needed log groups for the task definition to use CloudWatch Logs
310310
func CreateLogGroups(taskDef *ecs.TaskDefinition, logClientFactory cwlogsclient.LogClientFactory) error {
311311
for _, container := range taskDef.ContainerDefinitions {
312+
if container.LogConfiguration == nil || container.LogConfiguration.LogDriver == nil || aws.StringValue(container.LogConfiguration.LogDriver) != "awslogs" {
313+
continue
314+
}
312315
logConfig, err := getContainerLogConfig(container)
313316
if err != nil {
314317
return err

ecs-cli/modules/cli/logs/logs_app_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,17 +438,24 @@ func TestCreateLogGroupsTwoContainers(t *testing.T) {
438438
assert.NoError(t, err, "Unexpected error in call to CreateLogGroups()")
439439
}
440440

441-
func TestCreateLogGroupsWrongDriver(t *testing.T) {
441+
func TestCreateLogGroupsOneContainerWrongDriver(t *testing.T) {
442442
taskDef := dummyTaskDef([]*ecs.ContainerDefinition{
443-
dummyContainerDef(logRegion1, logGroup1, logPrefix1, "catsanddogslogger", containerName, containerImage),
443+
dummyContainerDef(logRegion1, logGroup1, logPrefix1, "awslogs", containerName, containerImage),
444+
dummyContainerDef(logRegion2, logGroup2, logPrefix1, "catsanddogslogger", containerName, containerImage),
444445
})
445446

446447
ctrl := gomock.NewController(t)
447448
defer ctrl.Finish()
448449
mockLogFactory := mock_cloudwatchlogs.NewMockLogClientFactory(ctrl)
450+
mockLogClient := mock_cloudwatchlogs.NewMockClient(ctrl)
451+
452+
gomock.InOrder(
453+
mockLogFactory.EXPECT().Get(logRegion1).Return(mockLogClient),
454+
mockLogClient.EXPECT().CreateLogGroup(gomock.Any()),
455+
)
449456

450457
err := CreateLogGroups(taskDef, mockLogFactory)
451-
assert.Error(t, err, "Expected error in call to CreateLogGroups()")
458+
assert.NoError(t, err, "Unexpected error in call to CreateLogGroups()")
452459
}
453460

454461
func TestCreateLogGroupsLogGroupAlreadyExists(t *testing.T) {

0 commit comments

Comments
 (0)