Skip to content

Commit

Permalink
Adjust ContainerStats for Podmod 4.6.0 responses (#278)
Browse files Browse the repository at this point in the history
* Adjust `ContainerStats` for Podmod 4.6.0 responses

* Update container_stats.go

* Update api/container_stats.go

Co-authored-by: Luiz Aoqui <[email protected]>

* Fix `_`

---------

Co-authored-by: Luiz Aoqui <[email protected]>
  • Loading branch information
sushain97 and lgfa29 authored Aug 14, 2023
1 parent 2f2353c commit 8bd8d26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/container_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ = json.Unmarshal(body, &errResponse); errResponse.Cause == "container is stopped" {
return stats, ContainerNotFound
}

err = json.Unmarshal(body, &stats)
if err != nil {
return stats, err
Expand Down
6 changes: 6 additions & 0 deletions api/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit 8bd8d26

Please sign in to comment.