From 6ae643a3bf29faf54d9e3ee9769569b5cd7cd632 Mon Sep 17 00:00:00 2001 From: hc-github-team-nomad-core <82989552+hc-github-team-nomad-core@users.noreply.github.com> Date: Wed, 13 Sep 2023 09:16:07 -0500 Subject: [PATCH] backport of commit 12580c345a89312542c18878680dd581da3d44eb (#18479) Co-authored-by: Shantanu Gadgil --- .changelog/18444.txt | 3 +++ client/allocrunner/taskrunner/getter/util.go | 5 +++-- helper/subproc/subproc.go | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changelog/18444.txt diff --git a/.changelog/18444.txt b/.changelog/18444.txt new file mode 100644 index 000000000..f52f630c0 --- /dev/null +++ b/.changelog/18444.txt @@ -0,0 +1,3 @@ +```release-note:improvement +status: go-getter failure reason now shown in `alloc status` +``` diff --git a/client/allocrunner/taskrunner/getter/util.go b/client/allocrunner/taskrunner/getter/util.go index f5b24ac15..b259fb079 100644 --- a/client/allocrunner/taskrunner/getter/util.go +++ b/client/allocrunner/taskrunner/getter/util.go @@ -143,10 +143,11 @@ func (s *Sandbox) runCmd(env *parameters) error { // start & wait for the subprocess to terminate if err := cmd.Run(); err != nil { - subproc.Log(output, s.logger.Error) + msg := subproc.Log(output, s.logger.Error) + return &Error{ URL: env.Source, - Err: fmt.Errorf("getter subprocess failed: %v", err), + Err: fmt.Errorf("getter subprocess failed: %v: %v", err, msg), Recoverable: true, } } diff --git a/helper/subproc/subproc.go b/helper/subproc/subproc.go index 2b69f236e..c534e0f06 100644 --- a/helper/subproc/subproc.go +++ b/helper/subproc/subproc.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "os" + "strings" "time" ) @@ -45,12 +46,15 @@ func Print(format string, args ...any) { // // r should be a buffer containing output (typically combined stdin + stdout) // f should be an HCLogger Print method (e.g. log.Debug) -func Log(r io.Reader, f func(msg string, args ...any)) { +func Log(r io.Reader, f func(msg string, args ...any)) string { scanner := bufio.NewScanner(r) + lines := "" for scanner.Scan() { line := scanner.Text() + lines += line + "\n" f("sub-process", "OUTPUT", line) } + return strings.TrimSpace(lines) } // Context creates a context setup with the given timeout.