diff --git a/test/e2e/functional_test.go b/test/e2e/functional_test.go index 906eeac31770..1e31492298d3 100644 --- a/test/e2e/functional_test.go +++ b/test/e2e/functional_test.go @@ -4,6 +4,7 @@ package e2e import ( "context" + "fmt" "testing" "time" @@ -914,6 +915,20 @@ func (s *FunctionalSuite) TestOutputArtifactS3BucketCreationEnabled() { WaitForWorkflow(fixtures.ToBeSucceeded) } +func (s *FunctionalSuite) TestArchiveContainerTypeTmplLogs() { + s.Given(). + Workflow("@testdata/archive-container-type-tmpl-logs.yaml"). + When(). + SubmitWorkflow(). + WaitForWorkflow(fixtures.ToBeSucceeded). + Then(). + ExpectWorkflow(func(t *testing.T, meta *metav1.ObjectMeta, status *wfv1.WorkflowStatus) { + assert.Equal(t, wfv1.WorkflowSucceeded, status.Phase) + assert.Equal(t, "hello-world-logs", status.Nodes[meta.Name].Outputs.Artifacts[0].Name) + assert.Equal(t, fmt.Sprintf("%s/%s/hello-world.log", meta.Name, meta.Name), status.Nodes[meta.Name].Outputs.Artifacts[0].S3.Key) + }) +} + func (s *FunctionalSuite) TestDataTransformation() { s.Given(). Workflow("@testdata/data-transformation.yaml"). diff --git a/test/e2e/testdata/archive-container-type-tmpl-logs.yaml b/test/e2e/testdata/archive-container-type-tmpl-logs.yaml new file mode 100644 index 000000000000..5103d4165a3a --- /dev/null +++ b/test/e2e/testdata/archive-container-type-tmpl-logs.yaml @@ -0,0 +1,15 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Workflow +metadata: + generateName: archive-container-type-tmpl-logs- +spec: + entrypoint: hello-world + templates: + - name: hello-world + container: + name: hello-world + image: busybox + command: [echo] + args: ["hello world"] + archiveLocation: + archiveLogs: true diff --git a/workflow/executor/executor.go b/workflow/executor/executor.go index 82648858126a..aa792fcb0717 100644 --- a/workflow/executor/executor.go +++ b/workflow/executor/executor.go @@ -49,6 +49,10 @@ import ( const ( // This directory temporarily stores the tarballs of the artifacts before uploading tempOutArtDir = "/tmp/argo/outputs/artifacts" + // The suffix of container log file + containerLogFileSuffix = ".log" + // The suffix of container log artifact name + containerLogArtifactSuffix = "-logs" ) // WorkflowExecutor is program which runs as the init/wait container @@ -626,14 +630,21 @@ func (we *WorkflowExecutor) SaveLogs(ctx context.Context) []wfv1.Artifact { // saveContainerLogs saves a single container's log into a file func (we *WorkflowExecutor) saveContainerLogs(ctx context.Context, tempLogsDir, containerName string) (*wfv1.Artifact, error) { - fileName := containerName + ".log" + fileName := containerName + containerLogFileSuffix + artName := containerName + containerLogArtifactSuffix + // if it is main container, use the container name as the file/artifact name + if containerName == common.MainContainerName && we.Template.GetType() == wfv1.TemplateTypeContainer && + len(we.Template.Container.Name) > 0 { + fileName = we.Template.Container.Name + containerLogFileSuffix + artName = we.Template.Container.Name + containerLogArtifactSuffix + } filePath := path.Join(tempLogsDir, fileName) err := we.saveLogToFile(ctx, containerName, filePath) if err != nil { return nil, err } - art := &wfv1.Artifact{Name: containerName + "-logs"} + art := &wfv1.Artifact{Name: artName} err = we.saveArtifactFromFile(ctx, art, fileName, filePath) if err != nil { return nil, err