From 63dd200e7e47261454c7e55fed2ad972144e147f Mon Sep 17 00:00:00 2001 From: haircommander Date: Wed, 22 Aug 2018 13:13:07 -0400 Subject: Changed GetContainerStats to return ErrCtrStateInvalid This results in some functionality changes: If a ErrCtrStateInvalid is returned to GetPodStats, the container is ommitted from the stats. As such, if an empty slice of Container stats are returned to GetPodStats in varlink, an error will occur. GetContainerStats will return the ErrCtrStateInvalid as well. Finally, if ErrCtrStateInvalid is returned to the podman stats call, the container will be ommitted from the stats. Signed-off-by: haircommander Closes: #1319 Approved by: baude --- pkg/varlinkapi/containers.go | 3 +++ pkg/varlinkapi/pods.go | 3 +++ 2 files changed, 6 insertions(+) (limited to 'pkg/varlinkapi') diff --git a/pkg/varlinkapi/containers.go b/pkg/varlinkapi/containers.go index 58452716a..f517e9b6e 100644 --- a/pkg/varlinkapi/containers.go +++ b/pkg/varlinkapi/containers.go @@ -207,6 +207,9 @@ func (i *LibpodAPI) GetContainerStats(call iopodman.VarlinkCall, name string) er } containerStats, err := ctr.GetContainerStats(&libpod.ContainerStats{}) if err != nil { + if errors.Cause(err) == libpod.ErrCtrStateInvalid { + return call.ReplyNoContainerRunning() + } return call.ReplyErrorOccurred(err.Error()) } cs := iopodman.ContainerStats{ diff --git a/pkg/varlinkapi/pods.go b/pkg/varlinkapi/pods.go index 75733db11..9e49ab687 100644 --- a/pkg/varlinkapi/pods.go +++ b/pkg/varlinkapi/pods.go @@ -199,6 +199,9 @@ func (i *LibpodAPI) GetPodStats(call iopodman.VarlinkCall, name string) error { if err != nil { return call.ReplyErrorOccurred(err.Error()) } + if len(podStats) == 0 { + return call.ReplyNoContainerRunning() + } containersStats := make([]iopodman.ContainerStats, 0) for ctrID, containerStats := range podStats { cs := iopodman.ContainerStats{ -- cgit v1.2.3-54-g00ecf