Skip to content

Commit

Permalink
fix(emissary): strip trailing slash from artifact src before creating… (
Browse files Browse the repository at this point in the history
#6696)

Signed-off-by: Elliot Maincourt <[email protected]>
  • Loading branch information
emaincourt authored Sep 9, 2021
1 parent 28c8dc7 commit 4b5d7ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/argoexec/commands/emissary.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/signal"
"path/filepath"
"strconv"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -192,7 +193,7 @@ func saveArtifact(srcPath string) error {
logger.WithError(err).Errorf("cannot save artifact %s", srcPath)
return nil
}
dstPath := varRunArgo + "/outputs/artifacts/" + srcPath + ".tgz"
dstPath := filepath.Join(varRunArgo, "/outputs/artifacts/", strings.TrimSuffix(srcPath, "/")+".tgz")
logger.Infof("%s -> %s", srcPath, dstPath)
z := filepath.Dir(dstPath)
if err := os.MkdirAll(z, 0o755); err != nil { // chmod rwxr-xr-x
Expand Down
17 changes: 17 additions & 0 deletions cmd/argoexec/commands/emissary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ func TestEmissary(t *testing.T) {
]
}
}
`), 0o600)
assert.NoError(t, err)
err := run(x, []string{"echo", "hello", "/tmp/artifact"})
assert.NoError(t, err)
data, err := ioutil.ReadFile(varRunArgo + "/outputs/artifacts/tmp/artifact.tgz")
assert.NoError(t, err)
assert.NotEmpty(t, string(data)) // data is tgz format
})
t.Run("ArtifactWithTrailingAndLeadingSlash", func(t *testing.T) {
err = ioutil.WriteFile(varRunArgo+"/template", []byte(`
{
"outputs": {
"artifacts": [
{"path": "/tmp/artifact/"}
]
}
}
`), 0o600)
assert.NoError(t, err)
err := run(x, []string{"echo", "hello", "/tmp/artifact"})
Expand Down
3 changes: 2 additions & 1 deletion workflow/executor/emissary/emissary.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -78,7 +79,7 @@ func (e emissary) CopyFile(_ string, sourcePath string, destPath string, _ int)
// this implementation is very different, because we expect the emissary binary has already compressed the file
// so no compression can or needs to be implemented here
// TODO - warn the user we ignored compression?
sourceFile := filepath.Join("/var/run/argo/outputs/artifacts", sourcePath+".tgz")
sourceFile := filepath.Join("/var/run/argo/outputs/artifacts", strings.TrimSuffix(sourcePath, "/")+".tgz")
log.Infof("%s -> %s", sourceFile, destPath)
src, err := os.Open(filepath.Clean(sourceFile))
if err != nil {
Expand Down

0 comments on commit 4b5d7ec

Please sign in to comment.