Skip to content

Commit

Permalink
feat: support archive logs in resource template. Fixes:#9900 (#13933)
Browse files Browse the repository at this point in the history
Signed-off-by: shuangkun <[email protected]>
  • Loading branch information
shuangkun authored Dec 30, 2024
1 parent 1add49e commit 2e0f2f7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cmd/argoexec/commands/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ func execResource(ctx context.Context, action string) error {

wfExecutor.InitializeOutput(bgCtx)
defer wfExecutor.HandleError(bgCtx)
defer wfExecutor.FinalizeOutput(bgCtx) //Ensures the LabelKeyReportOutputsCompleted is set to true.
if !wfExecutor.Template.SaveLogsAsArtifact() {
defer wfExecutor.FinalizeOutput(bgCtx) //Ensures the LabelKeyReportOutputsCompleted is set to true.
}
err := wfExecutor.StageFiles()
if err != nil {
wfExecutor.AddError(err)
Expand Down
9 changes: 9 additions & 0 deletions cmd/argoexec/commands/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ func waitContainer(ctx context.Context) error {
wfExecutor.AddError(err)
}

if wfExecutor.Template.Resource != nil {
// Save log artifacts for resource template
err = wfExecutor.ReportOutputsLogs(bgCtx)
if err != nil {
wfExecutor.AddError(err)
}
return wfExecutor.HasError()
}

// Capture output script result
err = wfExecutor.CaptureScriptResult(bgCtx)
if err != nil {
Expand Down
42 changes: 42 additions & 0 deletions test/e2e/artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,48 @@ func (s *ArtifactsSuite) TestMainLog() {
})
}

func (s *ArtifactsSuite) TestResourceLog() {
s.Run("Basic", func() {
s.Given().
Workflow(`
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: resource-tmpl-wf-
spec:
entrypoint: main
templates:
- name: main
resource:
action: create
successCondition: status.phase == Succeeded
setOwnerReference: true
manifest: |
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
labels:
workflows.argoproj.io/test: "true"
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: argoproj/argosay:v2
command: [sh, -c]
args: [echo, ":) Hello Argo!"]
`).
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeSucceeded).
Then().
ExpectArtifact("-", "main-logs", "my-bucket", func(t *testing.T, object minio.ObjectInfo, err error) {
require.NoError(t, err)
})
})
}

func (s *ArtifactsSuite) TestContainersetLogs() {
s.Run("Basic", func() {
s.Given().
Expand Down
5 changes: 3 additions & 2 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin
return nil, err
}

if tmpl.GetType() != wfv1.TemplateTypeResource && tmpl.GetType() != wfv1.TemplateTypeData {
// we do not need the wait container for resource templates because
if (tmpl.GetType() != wfv1.TemplateTypeResource && tmpl.GetType() != wfv1.TemplateTypeData) || (tmpl.GetType() == wfv1.TemplateTypeResource && tmpl.SaveLogsAsArtifact()) {
// we do not need the wait container for data templates because
// argoexec runs as the main container and will perform the job of
// annotating the outputs or errors, making the wait container redundant.
// for resource template, add a wait container to collect logs.
waitCtr := woc.newWaitContainer(tmpl)
pod.Spec.Containers = append(pod.Spec.Containers, *waitCtr)
}
Expand Down
10 changes: 10 additions & 0 deletions workflow/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,16 @@ func (we *WorkflowExecutor) ReportOutputs(ctx context.Context, artifacts []wfv1.
return we.reportResult(ctx, wfv1.NodeResult{Outputs: outputs})
}

// ReportOutputsLogs updates the WorkflowTaskResult log fields
func (we *WorkflowExecutor) ReportOutputsLogs(ctx context.Context) error {
var outputs wfv1.Outputs
artifacts := wfv1.Artifacts{}
logArtifacts := we.SaveLogs(ctx)
artifacts = append(artifacts, logArtifacts...)
outputs.Artifacts = artifacts
return we.reportResult(ctx, wfv1.NodeResult{Outputs: &outputs})
}

func (we *WorkflowExecutor) reportResult(ctx context.Context, result wfv1.NodeResult) error {
return retryutil.OnError(wait.Backoff{
Duration: time.Second,
Expand Down

0 comments on commit 2e0f2f7

Please sign in to comment.