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
argoproj#11271) (argoproj#11276)

Signed-off-by: Christoph Buchli <christoph@helio.exchange>
Signed-off-by: Dillen Padhiar <dillen_padhiar@intuit.com>
  • Loading branch information
cbuchli authored and dpadhiar committed May 9, 2024
1 parent 8e17671 commit 07dd2cc
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !windows

package commands

import (
Expand Down Expand Up @@ -45,7 +47,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 := ioutil.ReadFile(varRunArgo + "/ctr/main/combined")
Expand Down
48 changes: 48 additions & 0 deletions cmd/argoexec/commands/emissary_windows_test.go
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 07dd2cc

Please sign in to comment.