Skip to content

Commit

Permalink
Issue argoproj#1018 - Workflow controller should save information abo…
Browse files Browse the repository at this point in the history
…ut archived logs in step outputs (argoproj#1019)
  • Loading branch information
alexmt authored Sep 26, 2018
1 parent 15d006c commit ae7bf0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cmd/argoexec/commands/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func waitContainer() error {
wfExecutor.AddError(err)
// do not return here so we can still try to save outputs
}
err = wfExecutor.SaveLogs()
logArt, err := wfExecutor.SaveLogs()
if err != nil {
wfExecutor.AddError(err)
return err
Expand All @@ -57,7 +57,7 @@ func waitContainer() error {
wfExecutor.AddError(err)
return err
}
err = wfExecutor.AnnotateOutputs()
err = wfExecutor.AnnotateOutputs(logArt)
if err != nil {
wfExecutor.AddError(err)
return err
Expand Down
33 changes: 20 additions & 13 deletions workflow/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,27 +356,28 @@ func (we *WorkflowExecutor) SaveParameters() error {
}

// SaveLogs saves logs
func (we *WorkflowExecutor) SaveLogs() error {
func (we *WorkflowExecutor) SaveLogs() (*wfv1.Artifact, error) {
if we.Template.ArchiveLocation == nil || we.Template.ArchiveLocation.ArchiveLogs == nil || !*we.Template.ArchiveLocation.ArchiveLogs {
return nil
return nil, nil
}
log.Infof("Saving logs")
mainCtrID, err := we.GetMainContainerID()
if err != nil {
return err
return nil, err
}
tempLogsDir := "/argo/outputs/logs"
err = os.MkdirAll(tempLogsDir, os.ModePerm)
if err != nil {
return errors.InternalWrapError(err)
return nil, errors.InternalWrapError(err)
}
fileName := "main.log"
mainLog := path.Join(tempLogsDir, fileName)
err = we.RuntimeExecutor.Logs(mainCtrID, mainLog)
if err != nil {
return err
return nil, err
}
art := wfv1.Artifact{
Name: "main-logs",
ArtifactLocation: *we.Template.ArchiveLocation,
}
if we.Template.ArchiveLocation.S3 != nil {
Expand All @@ -388,22 +389,23 @@ func (we *WorkflowExecutor) SaveLogs() error {
art.Artifactory = &shallowCopy
artifactoryURL, urlParseErr := url.Parse(art.Artifactory.URL)
if urlParseErr != nil {
return urlParseErr
return nil, urlParseErr
}
artifactoryURL.Path = path.Join(artifactoryURL.Path, fileName)
art.Artifactory.URL = artifactoryURL.String()
} else {
return errors.Errorf(errors.CodeBadRequest, "Unable to determine path to store %s. Archive location provided no information", art.Name)
return nil, errors.Errorf(errors.CodeBadRequest, "Unable to determine path to store %s. Archive location provided no information", art.Name)
}
artDriver, err := we.InitDriver(art)
if err != nil {
return err
return nil, err
}
err = artDriver.Save(mainLog, &art)
if err != nil {
return err
return nil, err
}
return nil

return &art, nil
}

// InitDriver initializes an instance of an artifact driver
Expand Down Expand Up @@ -590,12 +592,17 @@ func (we *WorkflowExecutor) CaptureScriptResult() error {
}

// AnnotateOutputs annotation to the pod indicating all the outputs.
func (we *WorkflowExecutor) AnnotateOutputs() error {
if !we.Template.Outputs.HasOutputs() {
func (we *WorkflowExecutor) AnnotateOutputs(logArt *wfv1.Artifact) error {
outputs := we.Template.Outputs.DeepCopy()
if logArt != nil {
outputs.Artifacts = append(outputs.Artifacts, *logArt)
}

if !outputs.HasOutputs() {
return nil
}
log.Infof("Annotating pod with output")
outputBytes, err := json.Marshal(we.Template.Outputs)
outputBytes, err := json.Marshal(outputs)
if err != nil {
return errors.InternalWrapError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion workflow/executor/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (we *WorkflowExecutor) SaveResourceParameters(resourceName string) error {
we.Template.Outputs.Parameters[i].Value = &output
log.Infof("Saved output parameter: %s, value: %s", param.Name, output)
}
err := we.AnnotateOutputs()
err := we.AnnotateOutputs(nil)
if err != nil {
return err
}
Expand Down

0 comments on commit ae7bf0a

Please sign in to comment.