Skip to content

Commit

Permalink
fix(windows): Propagate correct numerical exitCode under Windows (Fixes
Browse files Browse the repository at this point in the history
#11271) (#11276)

Signed-off-by: Christoph Buchli <christoph@helio.exchange>
  • Loading branch information
cbuchli committed Jul 4, 2023
1 parent e5dd864 commit 6f1cb48
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
4 changes: 3 additions & 1 deletion cmd/argoexec/commands/emissary_test.go
@@ -1,3 +1,5 @@
//go:build !windows

package commands

import (
Expand Down Expand Up @@ -44,7 +46,7 @@ func TestEmissary(t *testing.T) {
assert.NoError(t, err)
assert.Contains(t, string(data), "hello")
})
t.Run("Comined", func(t *testing.T) {
t.Run("Combined", func(t *testing.T) {
err := run("echo hello > /dev/stderr")
assert.NoError(t, err)
data, err := os.ReadFile(varRunArgo + "/ctr/main/combined")
Expand Down
48 changes: 48 additions & 0 deletions cmd/argoexec/commands/emissary_windows_test.go
@@ -0,0 +1,48 @@
//go:build windows

package commands

import (
"os"
"testing"

"github.com/argoproj/argo-workflows/v3/util/errors"
"github.com/stretchr/testify/assert"
)

func TestEmissary(t *testing.T) {
tmp := t.TempDir()

varRunArgo = tmp
includeScriptOutput = true

err := os.WriteFile(varRunArgo+"/template", []byte(`{}`), 0o600)
assert.NoError(t, err)

t.Run("Exit0", func(t *testing.T) {
err := run("exit")
assert.NoError(t, err)
data, err := os.ReadFile(varRunArgo + "/ctr/main/exitcode")
assert.NoError(t, err)
assert.Equal(t, "0", string(data))
})

t.Run("Exit1", func(t *testing.T) {
err := run("exit 1")
assert.Equal(t, 1, err.(errors.Exited).ExitCode())
data, err := os.ReadFile(varRunArgo + "/ctr/main/exitcode")
assert.NoError(t, err)
assert.Equal(t, "1", string(data))
})
t.Run("Exit13", func(t *testing.T) {
err := run("exit 13")
assert.Equal(t, 13, err.(errors.Exited).ExitCode())
assert.EqualError(t, err, "exit status 13")
})
}

func run(script string) error {
cmd := NewEmissaryCommand()
containerName = "main"
return cmd.RunE(cmd, append([]string{"powershell", "-c"}, script))
}
12 changes: 3 additions & 9 deletions workflow/executor/os-specific/signal_windows.go
@@ -1,9 +1,10 @@
package os_specific

import (
"fmt"
"os"
"syscall"

"github.com/argoproj/argo-workflows/v3/util/errors"
)

func CanIgnoreSignal(s os.Signal) bool {
Expand All @@ -28,14 +29,7 @@ func Setpgid(a *syscall.SysProcAttr) {
func Wait(process *os.Process) error {
stat, err := process.Wait()
if stat.ExitCode() != 0 {
var errStr string
if err != nil {
errStr = err.Error()
} else {
errStr = "<nil>"
}

return fmt.Errorf("exit with non-zero code. exit-code: %d, error:%s", stat.ExitCode(), errStr)
return errors.NewExitErr(stat.ExitCode())
}
return err
}

0 comments on commit 6f1cb48

Please sign in to comment.