From 022e16c7fd02723e19d254a82e0cebdd5949d8b0 Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Mon, 19 Oct 2020 22:27:01 +0300 Subject: [PATCH 1/3] Fix log group not created when name is prefix of another longer name --- pkg/operator/resources/batchapi/logging.go | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pkg/operator/resources/batchapi/logging.go b/pkg/operator/resources/batchapi/logging.go index f18f4e6e2e..dd8701d564 100644 --- a/pkg/operator/resources/batchapi/logging.go +++ b/pkg/operator/resources/batchapi/logging.go @@ -43,17 +43,31 @@ func operatorLogStream(jobKey spec.JobKey) string { // Checks if log group exists before creating it func ensureLogGroupForAPI(apiName string) error { - output, err := config.AWS.CloudWatchLogs().DescribeLogGroups(&cloudwatchlogs.DescribeLogGroupsInput{ - Limit: aws.Int64(1), - LogGroupNamePrefix: aws.String(logGroupNameForAPI(apiName)), - }) + apiNameLogGroup := logGroupNameForAPI(apiName) + logGroupExists := false + + err := config.AWS.CloudWatchLogs().DescribeLogGroupsPages( + &cloudwatchlogs.DescribeLogGroupsInput{ + LogGroupNamePrefix: aws.String(apiNameLogGroup), + }, + func(page *cloudwatchlogs.DescribeLogGroupsOutput, lastPage bool) bool { + for _, output := range page.LogGroups { + if *output.LogGroupName == apiNameLogGroup { + logGroupExists = true + return false + } + } + return true + }, + ) + if err != nil { return errors.WithStack(err) } - if len(output.LogGroups) == 0 { + if !logGroupExists { input := &cloudwatchlogs.CreateLogGroupInput{ - LogGroupName: aws.String(logGroupNameForAPI(apiName)), + LogGroupName: aws.String(apiNameLogGroup), } // There should always be a default tag. Tags are only empty when running local operator without the tags field specified in a cluster.yaml. From 3653f7ea3a88e7a300ab316c7e8207849ce8e3f7 Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Mon, 19 Oct 2020 23:48:18 +0300 Subject: [PATCH 2/3] Use DoesLogGroupExist function instead --- pkg/operator/resources/batchapi/logging.go | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/pkg/operator/resources/batchapi/logging.go b/pkg/operator/resources/batchapi/logging.go index dd8701d564..eedf9fef17 100644 --- a/pkg/operator/resources/batchapi/logging.go +++ b/pkg/operator/resources/batchapi/logging.go @@ -44,23 +44,8 @@ func operatorLogStream(jobKey spec.JobKey) string { // Checks if log group exists before creating it func ensureLogGroupForAPI(apiName string) error { apiNameLogGroup := logGroupNameForAPI(apiName) - logGroupExists := false - - err := config.AWS.CloudWatchLogs().DescribeLogGroupsPages( - &cloudwatchlogs.DescribeLogGroupsInput{ - LogGroupNamePrefix: aws.String(apiNameLogGroup), - }, - func(page *cloudwatchlogs.DescribeLogGroupsOutput, lastPage bool) bool { - for _, output := range page.LogGroups { - if *output.LogGroupName == apiNameLogGroup { - logGroupExists = true - return false - } - } - return true - }, - ) + logGroupExists, err := config.AWS.DoesLogGroupExist(apiNameLogGroup) if err != nil { return errors.WithStack(err) } From 178ae77e555dba3bbf6233e58a3554e8029173b2 Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Tue, 20 Oct 2020 00:17:41 +0300 Subject: [PATCH 3/3] Removing unnecessary WithStack function --- pkg/operator/resources/batchapi/logging.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/operator/resources/batchapi/logging.go b/pkg/operator/resources/batchapi/logging.go index eedf9fef17..8f07a1a20b 100644 --- a/pkg/operator/resources/batchapi/logging.go +++ b/pkg/operator/resources/batchapi/logging.go @@ -47,7 +47,7 @@ func ensureLogGroupForAPI(apiName string) error { logGroupExists, err := config.AWS.DoesLogGroupExist(apiNameLogGroup) if err != nil { - return errors.WithStack(err) + return err } if !logGroupExists {