backport of commit 12580c345a89312542c18878680dd581da3d44eb (#18479)

Co-authored-by: Shantanu Gadgil <shantanugadgil@users.noreply.github.com>
This commit is contained in:
hc-github-team-nomad-core 2023-09-13 09:16:07 -05:00 committed by GitHub
parent 171d14707b
commit 6ae643a3bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

3
.changelog/18444.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
status: go-getter failure reason now shown in `alloc status`
```

View File

@ -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,
}
}

View File

@ -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.