aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhaircommander <pehunt@redhat.com>2018-08-22 13:13:07 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-23 15:58:08 +0000
commit63dd200e7e47261454c7e55fed2ad972144e147f (patch)
tree3c18d6c844801a5ebaa01e6359c492fd325aef66
parent3df6332a65b203b8fab106e9856a263f24b956a0 (diff)
downloadpodman-63dd200e7e47261454c7e55fed2ad972144e147f.tar.gz
podman-63dd200e7e47261454c7e55fed2ad972144e147f.tar.bz2
podman-63dd200e7e47261454c7e55fed2ad972144e147f.zip
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 <pehunt@redhat.com> Closes: #1319 Approved by: baude
-rw-r--r--cmd/podman/stats.go2
-rw-r--r--cmd/podman/varlink/io.podman.varlink7
-rw-r--r--libpod/pod.go9
-rw-r--r--libpod/pod_ffjson.go2
-rw-r--r--libpod/stats.go2
-rw-r--r--pkg/varlinkapi/containers.go3
-rw-r--r--pkg/varlinkapi/pods.go3
7 files changed, 22 insertions, 6 deletions
diff --git a/cmd/podman/stats.go b/cmd/podman/stats.go
index 6d54147f6..45868e8d7 100644
--- a/cmd/podman/stats.go
+++ b/cmd/podman/stats.go
@@ -138,7 +138,7 @@ func statsCmd(c *cli.Context) error {
id := ctr.ID()
if _, ok := containerStats[ctr.ID()]; !ok {
initialStats, err := ctr.GetContainerStats(&libpod.ContainerStats{})
- if errors.Cause(err) == libpod.ErrCtrRemoved || errors.Cause(err) == libpod.ErrNoSuchCtr {
+ if errors.Cause(err) == libpod.ErrCtrRemoved || errors.Cause(err) == libpod.ErrNoSuchCtr || errors.Cause(err) == libpod.ErrCtrStateInvalid {
// skip dealing with a container that is gone
continue
}
diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink
index 2fc53b43e..cd75b3b5f 100644
--- a/cmd/podman/varlink/io.podman.varlink
+++ b/cmd/podman/varlink/io.podman.varlink
@@ -441,7 +441,8 @@ method ExportContainer(name: string, path: string) -> (tarfile: string)
# GetContainerStats takes the name or ID of a container and returns a single ContainerStats structure which
# contains attributes like memory and cpu usage. If the container cannot be found, a
-# [ContainerNotFound](#ContainerNotFound) error will be returned.
+# [ContainerNotFound](#ContainerNotFound) error will be returned. If the container is not running, a [NoContainerRunning](#NoContainerRunning)
+# error will be returned
# #### Example
# ~~~
# $ varlink call -m unix:/run/podman/io.podman/io.podman.GetContainerStats '{"name": "c33e4164f384"}'
@@ -759,6 +760,7 @@ method TopPod() -> (notimplemented: NotImplemented)
# GetPodStats takes the name or ID of a pod and returns a pod name and slice of ContainerStats structure which
# contains attributes like memory and cpu usage. If the pod cannot be found, a [PodNotFound](#PodNotFound)
+# error will be returned. If the pod has no running containers associated with it, a [NoContainerRunning](#NoContainerRunning)
# error will be returned.
# #### Example
# ~~~
@@ -792,6 +794,9 @@ error ImageNotFound (name: string)
# ContainerNotFound means the container could not be found by the provided name or ID in local storage.
error ContainerNotFound (name: string)
+# NoContainerRunning means none of the containers requested are running in a command that requires a running container.
+error NoContainerRunning ()
+
# PodNotFound means the pod could not be found by the provided name or ID in local storage.
error PodNotFound (name: string)
diff --git a/libpod/pod.go b/libpod/pod.go
index e5d491e52..666480aa8 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -4,6 +4,7 @@ import (
"time"
"github.com/containers/storage"
+ "github.com/pkg/errors"
)
// Pod represents a group of containers that are managed together.
@@ -192,10 +193,14 @@ func (p *Pod) GetPodStats(previousContainerStats map[string]*ContainerStats) (ma
prevStat = &ContainerStats{}
}
newStats, err := c.GetContainerStats(prevStat)
- if err != nil {
+ // If the container wasn't running, don't include it
+ // but also suppress the error
+ if err != nil && errors.Cause(err) != ErrCtrStateInvalid {
return nil, err
}
- newContainerStats[c.ID()] = newStats
+ if err == nil {
+ newContainerStats[c.ID()] = newStats
+ }
}
return newContainerStats, nil
}
diff --git a/libpod/pod_ffjson.go b/libpod/pod_ffjson.go
index a74c91ccc..36b1cf08f 100644
--- a/libpod/pod_ffjson.go
+++ b/libpod/pod_ffjson.go
@@ -1,5 +1,5 @@
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
-// source: libpod/pod.go
+// source: /home/pehunt/go/src/github.com/containers/libpod/libpod/pod.go
package libpod
diff --git a/libpod/stats.go b/libpod/stats.go
index 61e85ed5e..9d5efd993 100644
--- a/libpod/stats.go
+++ b/libpod/stats.go
@@ -26,7 +26,7 @@ func (c *Container) GetContainerStats(previousStats *ContainerStats) (*Container
}
if c.state.State != ContainerStateRunning {
- return stats, nil
+ return stats, ErrCtrStateInvalid
}
cgroupPath, err := c.CGroupPath()
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{