Skip to content

Commit

Permalink
Issue#1165 fake outputs don't notify and task completes successfully (#…
Browse files Browse the repository at this point in the history
…1247)

* Issue#1165 fake outputs don't notify and task completes successfully

This PR is addressing the Issue#1165 reported by @alexfrieden.

Issue/Bug: Argo is finishing the task successfully even artifact /file does exist.

Fix: Validate the created gzip contains artifact or file. if file/artifact doesn't exist, Current step/stage/task will be failed with log message .

Sample Log:
'''
INFO[0029] Updating node artifact-passing-lkvj8[0].generate-artifact (artifact-passing-lkvj8-1949982165) status Running -> Error
INFO[0029] Updating node artifact-passing-lkvj8[0].generate-artifact (artifact-passing-lkvj8-1949982165) message: failed to save outputs: File or Artifact does not exist. /tmp/hello_world.txt
INFO[0029] Step group node artifact-passing-lkvj8[0] (artifact-passing-lkvj8-1067333159) deemed failed: child 'artifact-passing-lkvj8-1949982165' failed  namespace=default workflow=artifact-passing-lkvj8
INFO[0029] node artifact-passing-lkvj8[0] (artifact-passing-lkvj8-1067333159) phase Running -> Failed  namespace=default workflow=artifact-passing-lkvj8
'''

* fixed gometalinter errcheck issue
  • Loading branch information
sarabala1979 committed Mar 6, 2019
1 parent fa042aa commit 3f06385
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
7 changes: 7 additions & 0 deletions workflow/executor/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strings"
"time"

"github.com/argoproj/argo/workflow/util/file"

"github.com/argoproj/argo/util"

"github.com/argoproj/argo/errors"
Expand Down Expand Up @@ -51,6 +53,11 @@ func (d *DockerExecutor) CopyFile(containerID string, sourcePath string, destPat
if err != nil {
return err
}
if !file.IsFileOrDirExistInGZip(sourcePath, destPath) {
errMsg := fmt.Sprintf("File or Artifact does not exist. %s", sourcePath)
log.Warn(errMsg)
return errors.InternalError(errMsg)
}
log.Infof("Archiving completed")
return nil
}
Expand Down
52 changes: 52 additions & 0 deletions workflow/util/file/fileutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package file

import (
"archive/tar"
"compress/gzip"
"io"
"os"
"strings"

log "github.com/sirupsen/logrus"
)

//IsFileOrDirExistInGZip return true if file or directory exists in GZip file
func IsFileOrDirExistInGZip(sourcePath string, gzipFilePath string) bool {

fi, err := os.Open(gzipFilePath)

if os.IsNotExist(err) {
return false
}
defer closeFile(fi)

fz, err := gzip.NewReader(fi)
if err != nil {
return false
}
tr := tar.NewReader(fz)
for {
hdr, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {

return false
}
if hdr.FileInfo().IsDir() && strings.Contains(strings.Trim(hdr.Name, "/"), strings.Trim(sourcePath, "/")) {
return true
}
if strings.Contains(sourcePath, hdr.Name) && hdr.Size > 0 {
return true
}
}
return false
}

func closeFile(f *os.File) {
err := f.Close()
if err != nil {
log.Warn("Failed to close the file. v%", err)
}
}

0 comments on commit 3f06385

Please sign in to comment.