Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libpod API: fix two pod remote error messages #23080

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions pkg/api/handlers/libpod/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func PodStart(w http.ResponseWriter, r *http.Request) {
}
status, err := pod.GetPodStatus()
if err != nil {
utils.Error(w, http.StatusInternalServerError, err)
utils.InternalServerError(w, err)
return
}
if status == define.PodStateRunning {
Expand All @@ -212,13 +212,13 @@ func PodStart(w http.ResponseWriter, r *http.Request) {

responses, err := pod.Start(r.Context())
if err != nil && !errors.Is(err, define.ErrPodPartialFail) {
utils.Error(w, http.StatusConflict, err)
utils.InternalServerError(w, err)
return
}

cfg, err := pod.Config()
if err != nil {
utils.Error(w, http.StatusConflict, err)
utils.InternalServerError(w, err)
return
}
report := entities.PodStartReport{
Expand Down Expand Up @@ -411,12 +411,8 @@ func PodTop(w http.ResponseWriter, r *http.Request) {
return
}

// We are committed now - all errors logged but not reported to client, ship has sailed
w.WriteHeader(http.StatusOK)
wroteContent := false
w.Header().Set("Content-Type", "application/json")
if f, ok := w.(http.Flusher); ok {
f.Flush()
}

encoder := json.NewEncoder(w)

Expand All @@ -428,11 +424,22 @@ loop: // break out of for/select infinite` loop
default:
output, err := pod.GetPodPidInformation([]string{query.PsArgs})
if err != nil {
logrus.Infof("Error from %s %q : %v", r.Method, r.URL, err)
break loop
if !wroteContent {
utils.InternalServerError(w, err)
} else {
// ship has sailed, client already got a 200 response and expects valid
// PodTopOKBody json format so we no longer can send the error.
logrus.Infof("Error from %s %q : %v", r.Method, r.URL, err)
}
return
}

if len(output) > 0 {
if !wroteContent {
// Write header only first time around
w.WriteHeader(http.StatusOK)
wroteContent = true
}
body := handlers.PodTopOKBody{}
body.Titles = utils.PSTitles(output[0])
for i := range body.Titles {
Expand Down
7 changes: 1 addition & 6 deletions test/e2e/pod_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ var _ = Describe("Podman pod start", func() {

session := podmanTest.Podman([]string{"pod", "start", podid})
session.WaitWithDefaultTimeout()
expect := fmt.Sprintf("no containers in pod %s have no dependencies, cannot start pod: no such container", podid)
if IsRemote() {
// FIXME: #22989 no error message
expect = "Error:"
}
Expect(session).Should(ExitWithError(125, expect))
Expect(session).Should(ExitWithError(125, fmt.Sprintf("no containers in pod %s have no dependencies, cannot start pod: no such container", podid)))
})

It("podman pod start single pod by name", func() {
Expand Down
7 changes: 1 addition & 6 deletions test/e2e/pod_top_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ var _ = Describe("Podman top", func() {
// the wrong input and still print the -ef output instead.
result := podmanTest.Podman([]string{"pod", "top", podid, "-eo", "invalid"})
result.WaitWithDefaultTimeout()
if IsRemote() {
// FIXME: #22986
Expect(result).Should(ExitWithError(125, "unmarshalling into &handlers.PodTopOKBody{ContainerTopOKBody:container.ContainerTopOKBody"))
} else {
Expect(result).Should(ExitWithError(125, "Error: '-eo': unknown descriptor"))
}
Expect(result).Should(ExitWithError(125, "Error: '-eo': unknown descriptor"))
})

It("podman pod top on pod with containers in same pid namespace", func() {
Expand Down