From 105982d4b0a0c2452011cb60c18b87e5e51f09a8 Mon Sep 17 00:00:00 2001 From: Sushain Cherivirala Date: Mon, 7 Aug 2023 00:54:05 -0700 Subject: [PATCH 1/4] Adjust `ContainerStats` for Podmod 4.6.0 responses --- api/container_stats.go | 6 ++++++ api/structs.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/api/container_stats.go b/api/container_stats.go index cde379bf..8aa2a90a 100644 --- a/api/container_stats.go +++ b/api/container_stats.go @@ -47,6 +47,12 @@ func (c *API) ContainerStats(ctx context.Context, name string) (Stats, error) { return stats, ContainerNotFound } + // Since podman 4.6.0, a 200 response with `container is stopped` is returned for stopped containers. + var errResponse Error + if err := json.Unmarshal(body, &errResponse); err == nil && errResponse.Cause == "container is stopped" { + return stats, ContainerNotFound + } + err = json.Unmarshal(body, &stats) if err != nil { return stats, err diff --git a/api/structs.go b/api/structs.go index a58d7185..3a614e9d 100644 --- a/api/structs.go +++ b/api/structs.go @@ -1543,3 +1543,9 @@ type Version struct { Built int64 OsArch string } + +type Error struct { + Cause string `json:"cause"` + Message string `json:"message"` + Response int `json:"response"` +} From 1c93a28a909ffd8bff1d623fce5be10f128924bd Mon Sep 17 00:00:00 2001 From: Sushain Cherivirala Date: Mon, 7 Aug 2023 11:34:51 -0700 Subject: [PATCH 2/4] Update container_stats.go --- api/container_stats.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/container_stats.go b/api/container_stats.go index 8aa2a90a..63aa9a83 100644 --- a/api/container_stats.go +++ b/api/container_stats.go @@ -49,7 +49,7 @@ func (c *API) ContainerStats(ctx context.Context, name string) (Stats, error) { // Since podman 4.6.0, a 200 response with `container is stopped` is returned for stopped containers. var errResponse Error - if err := json.Unmarshal(body, &errResponse); err == nil && errResponse.Cause == "container is stopped" { + if unmarshalErr := json.Unmarshal(body, &errResponse); unmarshalErr == nil && errResponse.Cause == "container is stopped" { return stats, ContainerNotFound } From 36291cf003f1e72f9b04cce215aae7bc749e9481 Mon Sep 17 00:00:00 2001 From: Sushain Cherivirala Date: Tue, 8 Aug 2023 09:31:31 -0700 Subject: [PATCH 3/4] Update api/container_stats.go Co-authored-by: Luiz Aoqui --- api/container_stats.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/container_stats.go b/api/container_stats.go index 63aa9a83..2fa476be 100644 --- a/api/container_stats.go +++ b/api/container_stats.go @@ -49,7 +49,7 @@ func (c *API) ContainerStats(ctx context.Context, name string) (Stats, error) { // Since podman 4.6.0, a 200 response with `container is stopped` is returned for stopped containers. var errResponse Error - if unmarshalErr := json.Unmarshal(body, &errResponse); unmarshalErr == nil && errResponse.Cause == "container is stopped" { + if _ := json.Unmarshal(body, &errResponse); errResponse.Cause == "container is stopped" { return stats, ContainerNotFound } From 86196fe3dcd645e09cdd5d381825d5ae017a5b68 Mon Sep 17 00:00:00 2001 From: Sushain Cherivirala Date: Mon, 14 Aug 2023 06:08:25 -0700 Subject: [PATCH 4/4] Fix `_` --- api/container_stats.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/container_stats.go b/api/container_stats.go index 2fa476be..e6a4a0f7 100644 --- a/api/container_stats.go +++ b/api/container_stats.go @@ -49,7 +49,7 @@ func (c *API) ContainerStats(ctx context.Context, name string) (Stats, error) { // Since podman 4.6.0, a 200 response with `container is stopped` is returned for stopped containers. var errResponse Error - if _ := json.Unmarshal(body, &errResponse); errResponse.Cause == "container is stopped" { + if _ = json.Unmarshal(body, &errResponse); errResponse.Cause == "container is stopped" { return stats, ContainerNotFound }