Skip to content

Commit

Permalink
feat: use container name as artifact-log`s name/key
Browse files Browse the repository at this point in the history
Signed-off-by: joey <zchengjoey@gmail.com>
  • Loading branch information
chengjoey committed Sep 17, 2024
1 parent 818fd90 commit fe051f4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
15 changes: 15 additions & 0 deletions test/e2e/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package e2e

import (
"context"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -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").
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/testdata/archive-container-type-tmpl-logs.yaml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 13 additions & 2 deletions workflow/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fe051f4

Please sign in to comment.