summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cirrus.yml18
-rw-r--r--Dockerfile2
-rw-r--r--cmd/podman/commands.go2
-rw-r--r--cmd/podman/container.go1
-rw-r--r--cmd/podman/main.go1
-rw-r--r--cmd/podman/top.go28
-rw-r--r--cmd/podman/varlink/io.podman.varlink2
-rw-r--r--contrib/cirrus/packer/ubuntu_setup.sh3
-rw-r--r--libpod/container_top_linux.go14
-rw-r--r--pkg/adapter/containers.go20
-rw-r--r--pkg/adapter/containers_remote.go20
-rw-r--r--pkg/varlinkapi/containers.go13
-rw-r--r--vendor.conf2
-rw-r--r--vendor/github.com/containers/psgo/psgo.go11
14 files changed, 94 insertions, 43 deletions
diff --git a/.cirrus.yml b/.cirrus.yml
index 325176179..0102dcb1a 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -28,15 +28,15 @@ env:
#### Cache-image names to test with
###
ACTIVE_CACHE_IMAGE_NAMES: >-
- fedora-28-libpod-6318419153518592
- fedora-29-libpod-6318419153518592
- ubuntu-18-libpod-6318419153518592
- rhel-7-libpod-6318419153518592
+ fedora-29-libpod-548c1c05
+ fedora-28-libpod-548c1c05
+ ubuntu-18-libpod-548c1c05
+ rhel-7-libpod-548c1c05
image-builder-image-1541772081
- FEDORA_CACHE_IMAGE_NAME: "fedora-29-libpod-6318419153518592"
- PRIOR_FEDORA_CACHE_IMAGE_NAME: "fedora-28-libpod-6318419153518592"
- UBUNTU_CACHE_IMAGE_NAME: "ubuntu-18-libpod-6318419153518592"
- PRIOR_RHEL_CACHE_IMAGE_NAME: "rhel-7-libpod-6318419153518592"
+ FEDORA_CACHE_IMAGE_NAME: "fedora-29-libpod-548c1c05"
+ PRIOR_FEDORA_CACHE_IMAGE_NAME: "fedora-28-libpod-548c1c05"
+ UBUNTU_CACHE_IMAGE_NAME: "ubuntu-18-libpod-548c1c05"
+ PRIOR_RHEL_CACHE_IMAGE_NAME: "rhel-7-libpod-548c1c05"
# RHEL_CACHE_IMAGE_NAME: "rhel-8-notready"
# CENTOS_CACHE_IMAGE_NAME: "centos-7-notready"
@@ -49,7 +49,7 @@ env:
CNI_COMMIT: "7480240de9749f9a0a5c8614b17f1f03e0c06ab9"
CRIO_COMMIT: "7a283c391abb7bd25086a8ff91dbb36ebdd24466"
CRIU_COMMIT: "c74b83cd49c00589c0c0468ba5fe685b67fdbd0a"
- RUNC_COMMIT: "25f3f893c86d07426df93b7aa172f33fdf093fbd"
+ RUNC_COMMIT: "029124da7af7360afa781a0234d1b083550f797c"
# CSV of cache-image names to build (see $PACKER_BASE/libpod_images.json)
PACKER_BUILDS: "ubuntu-18,fedora-29,fedora-28,rhel-7" # TODO: rhel-8,centos-7
# Version of packer to use
diff --git a/Dockerfile b/Dockerfile
index 83cd3fccd..767e64570 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -44,7 +44,7 @@ RUN apt-get update && apt-get install -y \
&& apt-get clean
# Install runc
-ENV RUNC_COMMIT 96ec2177ae841256168fcf76954f7177af9446eb
+ENV RUNC_COMMIT 029124da7af7360afa781a0234d1b083550f797c
RUN set -x \
&& export GOPATH="$(mktemp -d)" \
&& git clone https://github.com/opencontainers/runc.git "$GOPATH/src/github.com/opencontainers/runc" \
diff --git a/cmd/podman/commands.go b/cmd/podman/commands.go
index 7680d6df2..c43ecec5c 100644
--- a/cmd/podman/commands.go
+++ b/cmd/podman/commands.go
@@ -21,7 +21,6 @@ func getMainCommands() []*cobra.Command {
_refreshCommand,
_searchCommand,
_statsCommand,
- _topCommand,
}
if len(_varlinkCommand.Use) > 0 {
@@ -53,7 +52,6 @@ func getContainerSubCommands() []*cobra.Command {
_runlabelCommand,
_statsCommand,
_stopCommand,
- _topCommand,
_umountCommand,
}
}
diff --git a/cmd/podman/container.go b/cmd/podman/container.go
index 28e0f0e4a..52152d50e 100644
--- a/cmd/podman/container.go
+++ b/cmd/podman/container.go
@@ -64,6 +64,7 @@ var (
_runCommand,
_rmCommand,
_startCommand,
+ _topCommand,
_unpauseCommand,
_waitCommand,
}
diff --git a/cmd/podman/main.go b/cmd/podman/main.go
index 392dfe542..a0f1cf401 100644
--- a/cmd/podman/main.go
+++ b/cmd/podman/main.go
@@ -57,6 +57,7 @@ var mainCommands = []*cobra.Command{
_saveCommand,
_stopCommand,
_tagCommand,
+ _topCommand,
_umountCommand,
_unpauseCommand,
_versionCommand,
diff --git a/cmd/podman/top.go b/cmd/podman/top.go
index 0b7da64a8..f1f594ebf 100644
--- a/cmd/podman/top.go
+++ b/cmd/podman/top.go
@@ -7,8 +7,8 @@ import (
"text/tabwriter"
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -60,7 +60,6 @@ func init() {
}
func topCmd(c *cliconfig.TopValues) error {
- var container *libpod.Container
var err error
args := c.InputArgs
@@ -77,37 +76,16 @@ func topCmd(c *cliconfig.TopValues) error {
return errors.Errorf("you must provide the name or id of a running container")
}
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.Shutdown(false)
- var descriptors []string
- if c.Latest {
- descriptors = args
- container, err = runtime.GetLatestContainer()
- } else {
- descriptors = args[1:]
- container, err = runtime.LookupContainer(args[0])
- }
-
- if err != nil {
- return errors.Wrapf(err, "unable to lookup requested container")
- }
-
- conStat, err := container.State()
- if err != nil {
- return errors.Wrapf(err, "unable to look up state for %s", args[0])
- }
- if conStat != libpod.ContainerStateRunning {
- return errors.Errorf("top can only be used on running containers")
- }
- psOutput, err := container.GetContainerPidInformation(descriptors)
+ psOutput, err := runtime.Top(c)
if err != nil {
return err
}
-
w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
for _, proc := range psOutput {
fmt.Fprintln(w, proc)
diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink
index 1fde72164..17179d665 100644
--- a/cmd/podman/varlink/io.podman.varlink
+++ b/cmd/podman/varlink/io.podman.varlink
@@ -524,6 +524,8 @@ method Ps(opts: PsOpts) -> (containers: []PsContainer)
method GetContainersByStatus(status: []string) -> (containerS: []Container)
+method Top (nameOrID: string, descriptors: []string) -> (top: []string)
+
# GetContainer returns information about a single container. If a container
# with the given id doesn't exist, a [ContainerNotFound](#ContainerNotFound)
# error will be returned. See also [ListContainers](ListContainers) and
diff --git a/contrib/cirrus/packer/ubuntu_setup.sh b/contrib/cirrus/packer/ubuntu_setup.sh
index 24f1cce21..e84566ce3 100644
--- a/contrib/cirrus/packer/ubuntu_setup.sh
+++ b/contrib/cirrus/packer/ubuntu_setup.sh
@@ -49,7 +49,7 @@ ooe.sh sudo -E apt-get -qq install \
gettext \
go-md2man \
golang \
- iproute \
+ iproute2 \
iptables \
libaio-dev \
libapparmor-dev \
@@ -68,6 +68,7 @@ ooe.sh sudo -E apt-get -qq install \
libprotobuf-dev \
libseccomp-dev \
libseccomp2 \
+ libsystemd-dev \
libtool \
libudev-dev \
lsof \
diff --git a/libpod/container_top_linux.go b/libpod/container_top_linux.go
index 9b0f156b5..b370495fe 100644
--- a/libpod/container_top_linux.go
+++ b/libpod/container_top_linux.go
@@ -7,8 +7,22 @@ import (
"strings"
"github.com/containers/psgo"
+ "github.com/pkg/errors"
)
+// Top gathers statistics about the running processes in a container. It returns a
+// []string for output
+func (c *Container) Top(descriptors []string) ([]string, error) {
+ conStat, err := c.State()
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to look up state for %s", c.ID())
+ }
+ if conStat != ContainerStateRunning {
+ return nil, errors.Errorf("top can only be used on running containers")
+ }
+ return c.GetContainerPidInformation(descriptors)
+}
+
// GetContainerPidInformation returns process-related data of all processes in
// the container. The output data can be controlled via the `descriptors`
// argument which expects format descriptors and supports all AIXformat
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go
index 8481a0cec..9f5fc7e65 100644
--- a/pkg/adapter/containers.go
+++ b/pkg/adapter/containers.go
@@ -766,3 +766,23 @@ func (r *LocalRuntime) Restart(ctx context.Context, c *cliconfig.RestartValues)
}
return pool.Run()
}
+
+// Top display the running processes of a container
+func (r *LocalRuntime) Top(cli *cliconfig.TopValues) ([]string, error) {
+ var (
+ descriptors []string
+ container *libpod.Container
+ err error
+ )
+ if cli.Latest {
+ descriptors = cli.InputArgs
+ container, err = r.Runtime.GetLatestContainer()
+ } else {
+ descriptors = cli.InputArgs[1:]
+ container, err = r.Runtime.LookupContainer(cli.InputArgs[0])
+ }
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to lookup requested container")
+ }
+ return container.Top(descriptors)
+}
diff --git a/pkg/adapter/containers_remote.go b/pkg/adapter/containers_remote.go
index e8f221eaf..ef6d0efe1 100644
--- a/pkg/adapter/containers_remote.go
+++ b/pkg/adapter/containers_remote.go
@@ -832,3 +832,23 @@ func (r *LocalRuntime) Restart(ctx context.Context, c *cliconfig.RestartValues)
}
return ok, failures, nil
}
+
+// Top display the running processes of a container
+func (r *LocalRuntime) Top(cli *cliconfig.TopValues) ([]string, error) {
+ var (
+ ctr *Container
+ err error
+ descriptors []string
+ )
+ if cli.Latest {
+ ctr, err = r.GetLatestContainer()
+ descriptors = cli.InputArgs
+ } else {
+ ctr, err = r.LookupContainer(cli.InputArgs[0])
+ descriptors = cli.InputArgs[1:]
+ }
+ if err != nil {
+ return nil, err
+ }
+ return iopodman.Top().Call(r.Conn, ctr.ID(), descriptors)
+}
diff --git a/pkg/varlinkapi/containers.go b/pkg/varlinkapi/containers.go
index 237407050..872c7bc26 100644
--- a/pkg/varlinkapi/containers.go
+++ b/pkg/varlinkapi/containers.go
@@ -733,3 +733,16 @@ func newPodmanLogLine(line *libpod.LogLine) iopodman.LogLine {
Cid: line.CID,
}
}
+
+// Top displays information about a container's running processes
+func (i *LibpodAPI) Top(call iopodman.VarlinkCall, nameOrID string, descriptors []string) error {
+ ctr, err := i.Runtime.LookupContainer(nameOrID)
+ if err != nil {
+ return call.ReplyContainerNotFound(ctr.ID(), err.Error())
+ }
+ topInfo, err := ctr.Top(descriptors)
+ if err != nil {
+ return call.ReplyErrorOccurred(err.Error())
+ }
+ return call.ReplyTop(topInfo)
+}
diff --git a/vendor.conf b/vendor.conf
index 3abb01114..572ae5fdb 100644
--- a/vendor.conf
+++ b/vendor.conf
@@ -20,7 +20,7 @@ github.com/vbauerster/mpb v3.3.4
github.com/mattn/go-isatty v0.0.4
github.com/VividCortex/ewma v1.1.1
github.com/containers/storage v1.12.3
-github.com/containers/psgo v1.2
+github.com/containers/psgo v1.2.1
github.com/coreos/go-systemd v14
github.com/coreos/pkg v4
github.com/cri-o/ocicni 0c180f981b27ef6036fa5be29bcb4dd666e406eb
diff --git a/vendor/github.com/containers/psgo/psgo.go b/vendor/github.com/containers/psgo/psgo.go
index e0f102735..f1936f917 100644
--- a/vendor/github.com/containers/psgo/psgo.go
+++ b/vendor/github.com/containers/psgo/psgo.go
@@ -93,7 +93,7 @@ func translateDescriptors(descriptors []string) ([]aixFormatDescriptor, error) {
}
}
if !found {
- return nil, errors.Wrapf(ErrUnkownDescriptor, "'%s'", d)
+ return nil, errors.Wrapf(ErrUnknownDescriptor, "'%s'", d)
}
}
@@ -104,8 +104,8 @@ var (
// DefaultDescriptors is the `ps -ef` compatible default format.
DefaultDescriptors = []string{"user", "pid", "ppid", "pcpu", "etime", "tty", "time", "args"}
- // ErrUnkownDescriptor is returned when an unknown descriptor is parsed.
- ErrUnkownDescriptor = errors.New("unknown descriptor")
+ // ErrUnknownDescriptor is returned when an unknown descriptor is parsed.
+ ErrUnknownDescriptor = errors.New("unknown descriptor")
aixFormatDescriptors = []aixFormatDescriptor{
{
@@ -327,7 +327,10 @@ func JoinNamespaceAndProcessInfo(pid string, descriptors []string) ([][]string,
dataErr = err
return
}
- unix.Setns(int(fd.Fd()), unix.CLONE_NEWNS)
+ if err := unix.Setns(int(fd.Fd()), unix.CLONE_NEWNS); err != nil {
+ dataErr = err
+ return
+ }
// extract all pids mentioned in pid's mount namespace
pids, err := proc.GetPIDs()