summaryrefslogtreecommitdiff
path: root/cmd/podman/pod_ps.go
diff options
context:
space:
mode:
authorhaircommander <pehunt@redhat.com>2018-07-27 13:58:50 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-23 18:16:28 +0000
commitd5e690914dc78eca8664442e7677eb5004522bfd (patch)
tree3f7ed30e4302c871c16126a0032b8a3d51c46f98 /cmd/podman/pod_ps.go
parent63dd200e7e47261454c7e55fed2ad972144e147f (diff)
downloadpodman-d5e690914dc78eca8664442e7677eb5004522bfd.tar.gz
podman-d5e690914dc78eca8664442e7677eb5004522bfd.tar.bz2
podman-d5e690914dc78eca8664442e7677eb5004522bfd.zip
Added option to share kernel namespaces in libpod and podman
A pause container is added to the pod if the user opts in. The default pause image and command can be overridden. Pause containers are ignored in ps unless the -a option is present. Pod inspect and pod ps show shared namespaces and pause container. A pause container can't be removed with podman rm, and a pod can be removed if it only has a pause container. Signed-off-by: haircommander <pehunt@redhat.com> Closes: #1187 Approved by: mheon
Diffstat (limited to 'cmd/podman/pod_ps.go')
-rw-r--r--cmd/podman/pod_ps.go57
1 files changed, 47 insertions, 10 deletions
diff --git a/cmd/podman/pod_ps.go b/cmd/podman/pod_ps.go
index 20beae53a..20cda1276 100644
--- a/cmd/podman/pod_ps.go
+++ b/cmd/podman/pod_ps.go
@@ -56,8 +56,9 @@ type podPsTemplateParams struct {
NumberOfContainers int
Status string
Cgroup string
- UsePodCgroup bool
ContainerInfo string
+ PauseContainerID string
+ SharedNamespaces string
}
// podPsJSONParams is used as a base structure for the psParams
@@ -73,7 +74,8 @@ type podPsJSONParams struct {
Status string `json:"status"`
CtrsInfo []podPsCtrInfo `json:"containerinfo,omitempty"`
Cgroup string `json:"cgroup,omitempty"`
- UsePodCgroup bool `json:"podcgroup,omitempty"`
+ PauseContainerID string `json:"pausecontainerid,omitempty"`
+ SharedNamespaces []string `json:"sharednamespaces,omitempty"`
}
// Type declaration and functions for sorting the pod PS output
@@ -111,10 +113,6 @@ func (a podPsSortedStatus) Less(i, j int) bool {
var (
podPsFlags = []cli.Flag{
cli.BoolFlag{
- Name: "cgroup",
- Usage: "Print the Cgroup information of the pod",
- },
- cli.BoolFlag{
Name: "ctr-names",
Usage: "Display the container names",
},
@@ -139,6 +137,10 @@ var (
Usage: "Show the latest pod created",
},
cli.BoolFlag{
+ Name: "namespace, ns",
+ Usage: "Display namespace information of the pod",
+ },
+ cli.BoolFlag{
Name: "no-trunc",
Usage: "Do not truncate pod and container IDs",
},
@@ -348,14 +350,15 @@ func genPodPsFormat(c *cli.Context) string {
format = formats.IDString
} else {
format = "table {{.ID}}\t{{.Name}}\t{{.Status}}\t{{.Created}}"
- if c.Bool("cgroup") {
- format += "\t{{.Cgroup}}\t{{.UsePodCgroup}}"
+ if c.Bool("namespace") {
+ format += "\t{{.Cgroup}}\t{{.SharedNamespaces}}"
}
if c.Bool("ctr-names") || c.Bool("ctr-ids") || c.Bool("ctr-status") {
format += "\t{{.ContainerInfo}}"
} else {
format += "\t{{.NumberOfContainers}}"
}
+ format += "\t{{.PauseContainerID}}"
}
return format
}
@@ -415,6 +418,7 @@ func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podP
for _, psParam := range psParams {
podID := psParam.ID
+ pauseID := psParam.PauseContainerID
var ctrStr string
truncated := ""
@@ -424,6 +428,7 @@ func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podP
psParam.CtrsInfo = psParam.CtrsInfo[:NUM_CTR_INFO]
truncated = "..."
}
+ pauseID = shortID(pauseID)
}
for _, ctrInfo := range psParam.CtrsInfo {
ctrStr += "[ "
@@ -449,9 +454,10 @@ func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podP
Name: psParam.Name,
Status: psParam.Status,
NumberOfContainers: psParam.NumberOfContainers,
- UsePodCgroup: psParam.UsePodCgroup,
Cgroup: psParam.Cgroup,
ContainerInfo: ctrStr,
+ PauseContainerID: pauseID,
+ SharedNamespaces: strings.Join(psParam.SharedNamespaces, ","),
}
psOutput = append(psOutput, params)
@@ -460,6 +466,32 @@ func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podP
return psOutput, nil
}
+func getSharedNamespaces(pod *libpod.Pod) []string {
+ var shared []string
+ if pod.SharesPID() {
+ shared = append(shared, "pid")
+ }
+ if pod.SharesNet() {
+ shared = append(shared, "net")
+ }
+ if pod.SharesMNT() {
+ shared = append(shared, "mnt")
+ }
+ if pod.SharesIPC() {
+ shared = append(shared, "ipc")
+ }
+ if pod.SharesUser() {
+ shared = append(shared, "user")
+ }
+ if pod.SharesCgroup() {
+ shared = append(shared, "cgroup")
+ }
+ if pod.SharesUTS() {
+ shared = append(shared, "uts")
+ }
+ return shared
+}
+
// getAndSortPodJSONOutput returns the container info in its raw, sorted form
func getAndSortPodJSONParams(pods []*libpod.Pod, opts podPsOptions, runtime *libpod.Runtime) ([]podPsJSONParams, error) {
var (
@@ -478,6 +510,10 @@ func getAndSortPodJSONParams(pods []*libpod.Pod, opts podPsOptions, runtime *lib
return nil, err
}
+ pauseContainerID, err := pod.PauseContainerID()
+ if err != nil {
+ return nil, err
+ }
for _, ctr := range ctrs {
batchInfo, err := shared.BatchContainerOp(ctr, bc_opts)
if err != nil {
@@ -508,9 +544,10 @@ func getAndSortPodJSONParams(pods []*libpod.Pod, opts podPsOptions, runtime *lib
Name: pod.Name(),
Status: status,
Cgroup: pod.CgroupParent(),
- UsePodCgroup: pod.UsePodCgroup(),
NumberOfContainers: ctrNum,
CtrsInfo: ctrsInfo,
+ SharedNamespaces: getSharedNamespaces(pod),
+ PauseContainerID: pauseContainerID,
}
psOutput = append(psOutput, params)