diff options
-rw-r--r-- | cmd/podman/common/completion.go | 4 | ||||
-rw-r--r-- | cmd/podman/root.go | 6 | ||||
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | go.sum | 4 | ||||
-rw-r--r-- | pkg/api/handlers/compat/images_build.go | 10 | ||||
-rw-r--r-- | pkg/bindings/images/build.go | 16 | ||||
-rw-r--r-- | pkg/errorhandling/errorhandling.go | 3 | ||||
-rwxr-xr-x | test/compose/test-compose | 31 | ||||
-rw-r--r-- | test/system/001-basic.bats | 13 | ||||
-rw-r--r-- | vendor/modules.txt | 2 |
10 files changed, 65 insertions, 26 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go index d110fb1b5..6086df297 100644 --- a/cmd/podman/common/completion.go +++ b/cmd/podman/common/completion.go @@ -21,7 +21,7 @@ var ( // ChangeCmds is the list of valid Change commands to passed to the Commit call ChangeCmds = []string{"CMD", "ENTRYPOINT", "ENV", "EXPOSE", "LABEL", "ONBUILD", "STOPSIGNAL", "USER", "VOLUME", "WORKDIR"} // LogLevels supported by podman - LogLevels = []string{"debug", "info", "warn", "warning", "error", "fatal", "panic"} + LogLevels = []string{"trace", "debug", "info", "warn", "warning", "error", "fatal", "panic"} ) type completeType int @@ -1009,7 +1009,7 @@ func AutocompleteEventBackend(cmd *cobra.Command, args []string, toComplete stri } // AutocompleteLogLevel - Autocomplete log level options. -// -> "debug", "info", "warn", "error", "fatal", "panic" +// -> "trace", "debug", "info", "warn", "error", "fatal", "panic" func AutocompleteLogLevel(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return LogLevels, cobra.ShellCompDirectiveNoFileComp } diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 4527c2646..9e5d2a236 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -416,7 +416,11 @@ func formatError(err error) string { strings.TrimSuffix(err.Error(), ": "+define.ErrOCIRuntime.Error()), ) } else { - message = "Error: " + err.Error() + if logrus.IsLevelEnabled(logrus.TraceLevel) { + message = fmt.Sprintf("Error: %+v", err) + } else { + message = fmt.Sprintf("Error: %v", err) + } } return message } @@ -51,7 +51,7 @@ require ( github.com/opencontainers/selinux v1.8.0 github.com/pkg/errors v0.9.1 github.com/pmezard/go-difflib v1.0.0 - github.com/rootless-containers/rootlesskit v0.14.1 + github.com/rootless-containers/rootlesskit v0.14.2 github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.1.3 github.com/spf13/pflag v1.0.5 @@ -713,8 +713,8 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rootless-containers/rootlesskit v0.14.1 h1:lvyG8XLYOiHPoSjWekgqY4MkNZJ+218KBOLfw9kB3Hk= -github.com/rootless-containers/rootlesskit v0.14.1/go.mod h1:nV3TpRISvwhZQSwo0nmQQnxjCxXr3mvrMi0oASLvzcg= +github.com/rootless-containers/rootlesskit v0.14.2 h1:jmsSyNyRG0QdWc3usppt5jEy5qOheeUsIINcymPrOFg= +github.com/rootless-containers/rootlesskit v0.14.2/go.mod h1:nV3TpRISvwhZQSwo0nmQQnxjCxXr3mvrMi0oASLvzcg= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index e0c79e5a7..ec40fdd2d 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -464,15 +464,16 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { var ( imageID string - failed bool + success bool ) runCtx, cancel := context.WithCancel(context.Background()) go func() { defer cancel() imageID, _, err = runtime.Build(r.Context(), buildOptions, query.Dockerfile) - if err != nil { - failed = true + if err == nil { + success = true + } else { stderr.Write([]byte(err.Error() + "\n")) } }() @@ -534,7 +535,8 @@ loop: } flush() case <-runCtx.Done(): - if !failed { + flush() + if success { if !utils.IsLibpodRequest(r) { m.Stream = fmt.Sprintf("Successfully built %12.12s\n", imageID) if err := enc.Encode(m); err != nil { diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index 34d6cee05..c0e5706a5 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -340,6 +340,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO re := regexp.MustCompile(`[0-9a-f]{12}`) var id string + var mErr error for { var s struct { Stream string `json:"stream,omitempty"` @@ -347,11 +348,21 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO } if err := dec.Decode(&s); err != nil { if errors.Is(err, io.EOF) { - return &entities.BuildReport{ID: id}, nil + if mErr == nil && id == "" { + mErr = errors.New("stream dropped, unexpected failure") + } + break } s.Error = err.Error() + "\n" } + select { + case <-response.Request.Context().Done(): + return &entities.BuildReport{ID: id}, mErr + default: + // non-blocking select + } + switch { case s.Stream != "": stdout.Write([]byte(s.Stream)) @@ -359,11 +370,12 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO id = strings.TrimSuffix(s.Stream, "\n") } case s.Error != "": - return nil, errors.New(s.Error) + mErr = errors.New(s.Error) default: return &entities.BuildReport{ID: id}, errors.New("failed to parse build results stream, unexpected input") } } + return &entities.BuildReport{ID: id}, mErr } func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { diff --git a/pkg/errorhandling/errorhandling.go b/pkg/errorhandling/errorhandling.go index b1923be98..9dc545ebb 100644 --- a/pkg/errorhandling/errorhandling.go +++ b/pkg/errorhandling/errorhandling.go @@ -24,6 +24,9 @@ func JoinErrors(errs []error) error { if finalErr == nil { return finalErr } + if len(multiE.WrappedErrors()) == 1 && logrus.IsLevelEnabled(logrus.TraceLevel) { + return multiE.WrappedErrors()[0] + } return errors.New(strings.TrimSpace(finalErr.Error())) } diff --git a/test/compose/test-compose b/test/compose/test-compose index abb957b43..c4c484190 100755 --- a/test/compose/test-compose +++ b/test/compose/test-compose @@ -136,8 +136,11 @@ function _show_ok() { local expect=$3 local actual=$4 printf "${red}not ok $count $testname${reset}\n" - printf "${red}# expected: %s${reset}\n" "$expect" - printf "${red}# actual: ${bold}%s${reset}\n" "$actual" + # Not all errors include actual/expect + if [[ -n "$expect" || -n "$actual" ]]; then + printf "${red}# expected: %s${reset}\n" "$expect" + printf "${red}# actual: ${bold}%s${reset}\n" "$actual" + fi echo "not ok $count $testname" >>$LOG echo " expected: $expect" >>$LOG @@ -164,20 +167,22 @@ function test_port() { local expect="$3" # what to expect from curl output # -s -S means "silent, but show errors" - local actual=$(curl --retry 3 --retry-all-errors -s -S http://127.0.0.1:$port/) + local actual + actual=$(curl --retry 3 --retry-all-errors -s -S http://127.0.0.1:$port/) local curl_rc=$? - # FIXME 2021-04-13: test is flaking, curl succeeds but returns empty result. - # Could it be that the container is not actually ready? Wait, and retry. - if [[ $curl_rc -eq 0 && -z "$actual" ]]; then - sleep 1 - echo "# Retrying curl:" - actual=$(curl --retry 3 --retry-all-errors -s -S http://127.0.0.1:$port/) - curl_rc=$? - fi - if [ $curl_rc -ne 0 ]; then - _show_ok 0 "$testname - curl failed with status $curl_rc" + _show_ok 0 "$testname - curl (port $port) failed with status $curl_rc" + # FIXME: is this useful? What else can we do to diagnose? + echo "# docker-compose logs:" + docker-compose logs + echo "# podman ps -a:" + $PODMAN_BIN --root $WORKDIR/root --runroot $WORKDIR/runroot ps -a + if type -p ss; then + echo "# ss -tulpn:" + ss -tulpn + fi + return fi case "$op" in diff --git a/test/system/001-basic.bats b/test/system/001-basic.bats index 081bb1171..35107f0a0 100644 --- a/test/system/001-basic.bats +++ b/test/system/001-basic.bats @@ -111,4 +111,17 @@ function setup() { is "$output" "you found me" "sample invocation of 'jq'" } +@test "podman --log-level recognizes log levels" { + run_podman 1 --log-level=telepathic info + is "$output" 'Log Level "telepathic" is not supported.*' + run_podman --log-level=trace info + run_podman --log-level=debug info + run_podman --log-level=info info + run_podman --log-level=warn info + run_podman --log-level=warning info + run_podman --log-level=error info + run_podman --log-level=fatal info + run_podman --log-level=panic info +} + # vim: filetype=sh diff --git a/vendor/modules.txt b/vendor/modules.txt index 1bf189b86..431a21c8a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -542,7 +542,7 @@ github.com/prometheus/procfs/internal/fs github.com/prometheus/procfs/internal/util # github.com/rivo/uniseg v0.2.0 github.com/rivo/uniseg -# github.com/rootless-containers/rootlesskit v0.14.1 +# github.com/rootless-containers/rootlesskit v0.14.2 github.com/rootless-containers/rootlesskit/pkg/api github.com/rootless-containers/rootlesskit/pkg/msgutil github.com/rootless-containers/rootlesskit/pkg/port |