summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/common/create.go10
-rw-r--r--cmd/podman/common/create_opts.go2
-rw-r--r--cmd/podman/common/default.go2
-rw-r--r--cmd/podman/common/specgen.go46
-rw-r--r--cmd/podman/common/util.go57
-rw-r--r--cmd/podman/containers/attach.go4
-rw-r--r--cmd/podman/containers/container.go2
-rw-r--r--cmd/podman/containers/create.go17
-rw-r--r--cmd/podman/containers/diff.go2
-rw-r--r--cmd/podman/containers/exec.go8
-rw-r--r--cmd/podman/containers/mount.go4
-rw-r--r--cmd/podman/containers/ps.go11
-rw-r--r--cmd/podman/containers/rm.go16
-rw-r--r--cmd/podman/containers/run.go6
-rw-r--r--cmd/podman/containers/stats.go14
-rw-r--r--cmd/podman/containers/stop.go3
-rw-r--r--cmd/podman/containers/wait.go4
-rw-r--r--cmd/podman/diff.go2
-rw-r--r--cmd/podman/generate/systemd.go2
-rw-r--r--cmd/podman/images/history.go2
-rw-r--r--cmd/podman/images/image.go2
-rw-r--r--cmd/podman/images/list.go4
-rw-r--r--cmd/podman/inspect/inspect.go4
-rw-r--r--cmd/podman/networks/list.go17
-rw-r--r--cmd/podman/parse/common.go55
-rw-r--r--cmd/podman/play/kube.go34
-rw-r--r--cmd/podman/pods/create.go33
-rw-r--r--cmd/podman/pods/pod.go2
-rw-r--r--cmd/podman/pods/ps.go18
-rw-r--r--cmd/podman/pods/rm.go39
-rw-r--r--cmd/podman/pods/start.go22
-rw-r--r--cmd/podman/pods/stats.go4
-rw-r--r--cmd/podman/pods/stop.go35
-rw-r--r--cmd/podman/registry/json.go4
-rw-r--r--cmd/podman/report/report.go2
-rw-r--r--cmd/podman/root.go8
-rw-r--r--cmd/podman/system/df.go14
-rw-r--r--cmd/podman/system/events.go6
-rw-r--r--cmd/podman/system/service.go4
-rw-r--r--cmd/podman/system/system.go2
-rw-r--r--cmd/podman/validate/args.go4
-rw-r--r--cmd/podman/validate/choice.go16
-rw-r--r--cmd/podman/volumes/create.go2
-rw-r--r--cmd/podman/volumes/volume.go2
44 files changed, 392 insertions, 155 deletions
diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go
index 86cd51643..921cd5a71 100644
--- a/cmd/podman/common/create.go
+++ b/cmd/podman/common/create.go
@@ -338,6 +338,11 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
"pod", "",
"Run container in an existing pod",
)
+ createFlags.StringVar(
+ &cf.PodIDFile,
+ "pod-id-file", "",
+ "Read the pod ID from the file",
+ )
createFlags.BoolVar(
&cf.Privileged,
"privileged", false,
@@ -368,6 +373,11 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
"read-only-tmpfs", true,
"When running containers in read-only mode mount a read-write tmpfs on /run, /tmp and /var/tmp",
)
+ createFlags.BoolVar(
+ &cf.Replace,
+ "replace", false,
+ `If a container with the same name exists, replace it`,
+ )
createFlags.StringVar(
&cf.Restart,
"restart", "",
diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go
index 4cba5daf7..49052704e 100644
--- a/cmd/podman/common/create_opts.go
+++ b/cmd/podman/common/create_opts.go
@@ -68,6 +68,7 @@ type ContainerCLIOpts struct {
PID string
PIDsLimit int64
Pod string
+ PodIDFile string
Privileged bool
PublishAll bool
Pull string
@@ -75,6 +76,7 @@ type ContainerCLIOpts struct {
ReadOnly bool
ReadOnlyTmpFS bool
Restart string
+ Replace bool
Rm bool
RootFS bool
SecurityOpt []string
diff --git a/cmd/podman/common/default.go b/cmd/podman/common/default.go
index 7233b2091..6e5994b18 100644
--- a/cmd/podman/common/default.go
+++ b/cmd/podman/common/default.go
@@ -16,5 +16,5 @@ var (
// DefaultImageVolume default value
DefaultImageVolume = "bind"
// Pull in configured json library
- json = registry.JsonLibrary()
+ json = registry.JSONLibrary()
)
diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go
index 26003b40f..0b44ef544 100644
--- a/cmd/podman/common/specgen.go
+++ b/cmd/podman/common/specgen.go
@@ -23,7 +23,7 @@ import (
"github.com/pkg/errors"
)
-func getCPULimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string) (*specs.LinuxCPU, error) {
+func getCPULimits(c *ContainerCLIOpts) *specs.LinuxCPU {
cpu := &specs.LinuxCPU{}
hasLimits := false
@@ -67,12 +67,12 @@ func getCPULimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string)
}
if !hasLimits {
- return nil, nil
+ return nil
}
- return cpu, nil
+ return cpu
}
-func getIOLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string) (*specs.LinuxBlockIO, error) {
+func getIOLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts) (*specs.LinuxBlockIO, error) {
var err error
io := &specs.LinuxBlockIO{}
hasLimits := false
@@ -87,7 +87,7 @@ func getIOLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string) (
}
if len(c.BlkIOWeightDevice) > 0 {
- if err := parseWeightDevices(c.BlkIOWeightDevice, s); err != nil {
+ if err := parseWeightDevices(s, c.BlkIOWeightDevice); err != nil {
return nil, err
}
hasLimits = true
@@ -127,7 +127,7 @@ func getIOLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string) (
return io, nil
}
-func getPidsLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string) *specs.LinuxPids {
+func getPidsLimits(c *ContainerCLIOpts) *specs.LinuxPids {
pids := &specs.LinuxPids{}
if c.CGroupsMode == "disabled" && c.PIDsLimit != 0 {
return nil
@@ -146,7 +146,7 @@ func getPidsLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string)
return nil
}
-func getMemoryLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string) (*specs.LinuxMemory, error) {
+func getMemoryLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts) (*specs.LinuxMemory, error) {
var err error
memory := &specs.LinuxMemory{}
hasLimits := false
@@ -254,6 +254,17 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
s.PublishExposedPorts = c.PublishAll
s.Pod = c.Pod
+ if len(c.PodIDFile) > 0 {
+ if len(s.Pod) > 0 {
+ return errors.New("Cannot specify both --pod and --pod-id-file")
+ }
+ podID, err := ReadPodIDFile(c.PodIDFile)
+ if err != nil {
+ return err
+ }
+ s.Pod = podID
+ }
+
expose, err := createExpose(c.Expose)
if err != nil {
return err
@@ -374,11 +385,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
}
s.Annotations = annotations
- workDir := "/"
- if wd := c.Workdir; len(wd) > 0 {
- workDir = wd
- }
- s.WorkDir = workDir
+ s.WorkDir = c.Workdir
entrypoint := []string{}
userCommand := []string{}
if c.Entrypoint != nil {
@@ -439,19 +446,16 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
if s.ResourceLimits == nil {
s.ResourceLimits = &specs.LinuxResources{}
}
- s.ResourceLimits.Memory, err = getMemoryLimits(s, c, args)
- if err != nil {
- return err
- }
- s.ResourceLimits.BlockIO, err = getIOLimits(s, c, args)
+ s.ResourceLimits.Memory, err = getMemoryLimits(s, c)
if err != nil {
return err
}
- s.ResourceLimits.Pids = getPidsLimits(s, c, args)
- s.ResourceLimits.CPU, err = getCPULimits(s, c, args)
+ s.ResourceLimits.BlockIO, err = getIOLimits(s, c)
if err != nil {
return err
}
+ s.ResourceLimits.Pids = getPidsLimits(c)
+ s.ResourceLimits.CPU = getCPULimits(c)
if s.ResourceLimits.CPU == nil && s.ResourceLimits.Pids == nil && s.ResourceLimits.BlockIO == nil && s.ResourceLimits.Memory == nil {
s.ResourceLimits = nil
}
@@ -669,7 +673,7 @@ func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, start
hc.Interval = intervalDuration
if retries < 1 {
- return nil, errors.New("healthcheck-retries must be greater than 0.")
+ return nil, errors.New("healthcheck-retries must be greater than 0")
}
hc.Retries = int(retries)
timeoutDuration, err := time.ParseDuration(timeout)
@@ -693,7 +697,7 @@ func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, start
return &hc, nil
}
-func parseWeightDevices(weightDevs []string, s *specgen.SpecGenerator) error {
+func parseWeightDevices(s *specgen.SpecGenerator, weightDevs []string) error {
for _, val := range weightDevs {
split := strings.SplitN(val, ":", 2)
if len(split) != 2 {
diff --git a/cmd/podman/common/util.go b/cmd/podman/common/util.go
index a3626b4e4..ce323a4ba 100644
--- a/cmd/podman/common/util.go
+++ b/cmd/podman/common/util.go
@@ -1,6 +1,7 @@
package common
import (
+ "io/ioutil"
"net"
"strconv"
"strings"
@@ -10,6 +11,30 @@ import (
"github.com/sirupsen/logrus"
)
+// ReadPodIDFile reads the specified file and returns its content (i.e., first
+// line).
+func ReadPodIDFile(path string) (string, error) {
+ content, err := ioutil.ReadFile(path)
+ if err != nil {
+ return "", errors.Wrap(err, "error reading pod ID file")
+ }
+ return strings.Split(string(content), "\n")[0], nil
+}
+
+// ReadPodIDFiles reads the specified files and returns their content (i.e.,
+// first line).
+func ReadPodIDFiles(files []string) ([]string, error) {
+ ids := []string{}
+ for _, file := range files {
+ id, err := ReadPodIDFile(file)
+ if err != nil {
+ return nil, err
+ }
+ ids = append(ids, id)
+ }
+ return ids, nil
+}
+
// createExpose parses user-provided exposed port definitions and converts them
// into SpecGen format.
// TODO: The SpecGen format should really handle ranges more sanely - we could
@@ -71,14 +96,44 @@ func createPortBindings(ports []string) ([]specgen.PortMapping, error) {
return nil, errors.Errorf("invalid port format - protocol can only be specified once")
}
- splitPort := strings.Split(splitProto[0], ":")
+ remainder := splitProto[0]
+ haveV6 := false
+
+ // Check for an IPv6 address in brackets
+ splitV6 := strings.Split(remainder, "]")
+ switch len(splitV6) {
+ case 1:
+ // Do nothing, proceed as before
+ case 2:
+ // We potentially have an IPv6 address
+ haveV6 = true
+ if !strings.HasPrefix(splitV6[0], "[") {
+ return nil, errors.Errorf("invalid port format - IPv6 addresses must be enclosed by []")
+ }
+ if !strings.HasPrefix(splitV6[1], ":") {
+ return nil, errors.Errorf("invalid port format - IPv6 address must be followed by a colon (':')")
+ }
+ ipNoPrefix := strings.TrimPrefix(splitV6[0], "[")
+ hostIP = &ipNoPrefix
+ remainder = strings.TrimPrefix(splitV6[1], ":")
+ default:
+ return nil, errors.Errorf("invalid port format - at most one IPv6 address can be specified in a --publish")
+ }
+
+ splitPort := strings.Split(remainder, ":")
switch len(splitPort) {
case 1:
+ if haveV6 {
+ return nil, errors.Errorf("invalid port format - must provide host and destination port if specifying an IP")
+ }
ctrPort = splitPort[0]
case 2:
hostPort = &(splitPort[0])
ctrPort = splitPort[1]
case 3:
+ if haveV6 {
+ return nil, errors.Errorf("invalid port format - when v6 address specified, must be [ipv6]:hostPort:ctrPort")
+ }
hostIP = &(splitPort[0])
hostPort = &(splitPort[1])
ctrPort = splitPort[2]
diff --git a/cmd/podman/containers/attach.go b/cmd/podman/containers/attach.go
index 9f29d1664..9ef9d79f0 100644
--- a/cmd/podman/containers/attach.go
+++ b/cmd/podman/containers/attach.go
@@ -18,7 +18,7 @@ var (
Short: "Attach to a running container",
Long: attachDescription,
RunE: attach,
- Args: validate.IdOrLatestArgs,
+ Args: validate.IDOrLatestArgs,
Example: `podman attach ctrID
podman attach 1234
podman attach --no-stdin foobar`,
@@ -29,7 +29,7 @@ var (
Short: attachCommand.Short,
Long: attachCommand.Long,
RunE: attachCommand.RunE,
- Args: validate.IdOrLatestArgs,
+ Args: validate.IDOrLatestArgs,
Example: `podman container attach ctrID
podman container attach 1234
podman container attach --no-stdin foobar`,
diff --git a/cmd/podman/containers/container.go b/cmd/podman/containers/container.go
index a102318fb..3ff341dcd 100644
--- a/cmd/podman/containers/container.go
+++ b/cmd/podman/containers/container.go
@@ -10,7 +10,7 @@ import (
var (
// Pull in configured json library
- json = registry.JsonLibrary()
+ json = registry.JSONLibrary()
// Command: podman _container_
containerCmd = &cobra.Command{
diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go
index ed09585ba..6269ec781 100644
--- a/cmd/podman/containers/create.go
+++ b/cmd/podman/containers/create.go
@@ -122,6 +122,12 @@ func create(cmd *cobra.Command, args []string) error {
return err
}
+ if cliVals.Replace {
+ if err := replaceContainer(cliVals.Name); err != nil {
+ return err
+ }
+ }
+
report, err := registry.ContainerEngine().ContainerCreate(registry.GetContext(), s)
if err != nil {
return err
@@ -138,6 +144,17 @@ func create(cmd *cobra.Command, args []string) error {
return nil
}
+func replaceContainer(name string) error {
+ if len(name) == 0 {
+ return errors.New("cannot replace container without --name being set")
+ }
+ rmOptions := entities.RmOptions{
+ Force: true, // force stop & removal
+ Ignore: true, // ignore errors when a container doesn't exit
+ }
+ return removeContainers([]string{name}, rmOptions, false)
+}
+
func createInit(c *cobra.Command) error {
if c.Flag("privileged").Changed && c.Flag("security-opt").Changed {
logrus.Warn("setting security options with --privileged has no effect")
diff --git a/cmd/podman/containers/diff.go b/cmd/podman/containers/diff.go
index 59b788010..33b1c1126 100644
--- a/cmd/podman/containers/diff.go
+++ b/cmd/podman/containers/diff.go
@@ -13,7 +13,7 @@ var (
// podman container _diff_
diffCmd = &cobra.Command{
Use: "diff [flags] CONTAINER",
- Args: validate.IdOrLatestArgs,
+ Args: validate.IDOrLatestArgs,
Short: "Inspect changes on container's file systems",
Long: `Displays changes on a container filesystem. The container will be compared to its parent layer.`,
RunE: diff,
diff --git a/cmd/podman/containers/exec.go b/cmd/podman/containers/exec.go
index 41f100768..ce48af618 100644
--- a/cmd/podman/containers/exec.go
+++ b/cmd/podman/containers/exec.go
@@ -84,7 +84,7 @@ func init() {
}
func exec(cmd *cobra.Command, args []string) error {
- var nameOrId string
+ var nameOrID string
if len(args) == 0 && !execOpts.Latest {
return errors.New("exec requires the name or ID of a container or the --latest flag")
@@ -92,7 +92,7 @@ func exec(cmd *cobra.Command, args []string) error {
execOpts.Cmd = args
if !execOpts.Latest {
execOpts.Cmd = args[1:]
- nameOrId = args[0]
+ nameOrID = args[0]
}
// Validate given environment variables
execOpts.Envs = make(map[string]string)
@@ -122,12 +122,12 @@ func exec(cmd *cobra.Command, args []string) error {
streams.AttachOutput = true
streams.AttachError = true
- exitCode, err := registry.ContainerEngine().ContainerExec(registry.GetContext(), nameOrId, execOpts, streams)
+ exitCode, err := registry.ContainerEngine().ContainerExec(registry.GetContext(), nameOrID, execOpts, streams)
registry.SetExitCode(exitCode)
return err
}
- id, err := registry.ContainerEngine().ContainerExecDetached(registry.GetContext(), nameOrId, execOpts)
+ id, err := registry.ContainerEngine().ContainerExecDetached(registry.GetContext(), nameOrID, execOpts)
if err != nil {
return err
}
diff --git a/cmd/podman/containers/mount.go b/cmd/podman/containers/mount.go
index af4d52caa..7f15616de 100644
--- a/cmd/podman/containers/mount.go
+++ b/cmd/podman/containers/mount.go
@@ -71,7 +71,6 @@ func init() {
func mount(cmd *cobra.Command, args []string) error {
var (
errs utils.OutputErrors
- mrs []mountReporter
)
reports, err := registry.ContainerEngine().ContainerMount(registry.GetContext(), args, mountOpts)
if err != nil {
@@ -90,6 +89,7 @@ func mount(cmd *cobra.Command, args []string) error {
if mountOpts.Format == "json" {
return printJSON(reports)
}
+ mrs := make([]mountReporter, 0, len(reports))
for _, r := range reports {
mrs = append(mrs, mountReporter{r})
}
@@ -110,7 +110,7 @@ func printJSON(reports []*entities.ContainerMountReport) error {
Names []string
Mountpoint string `json:"mountpoint"`
}
- var jreports []jreport
+ jreports := make([]jreport, 0, len(reports))
for _, r := range reports {
jreports = append(jreports, jreport{
diff --git a/cmd/podman/containers/ps.go b/cmd/podman/containers/ps.go
index 4d12d2534..ffd2054a6 100644
--- a/cmd/podman/containers/ps.go
+++ b/cmd/podman/containers/ps.go
@@ -67,14 +67,14 @@ func listFlagSet(flags *pflag.FlagSet) {
flags.BoolVar(&listOpts.Sync, "sync", false, "Sync container state with OCI runtime")
flags.UintVarP(&listOpts.Watch, "watch", "w", 0, "Watch the ps output on an interval in seconds")
- sort := validate.ChoiceValue(&listOpts.Sort, "command", "created", "id", "image", "names", "runningfor", "size", "status")
+ sort := validate.Value(&listOpts.Sort, "command", "created", "id", "image", "names", "runningfor", "size", "status")
flags.Var(sort, "sort", "Sort output by: "+sort.Choices())
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
}
-func checkFlags(c *cobra.Command, args []string) error {
+func checkFlags(c *cobra.Command) error {
// latest, and last are mutually exclusive.
if listOpts.Last >= 0 && listOpts.Latest {
return errors.Errorf("last and latest are mutually exclusive")
@@ -144,8 +144,7 @@ func getResponses() ([]entities.ListContainer, error) {
}
func ps(cmd *cobra.Command, args []string) error {
- var responses []psReporter
- if err := checkFlags(cmd, args); err != nil {
+ if err := checkFlags(cmd); err != nil {
return err
}
for _, f := range filters {
@@ -172,6 +171,7 @@ func ps(cmd *cobra.Command, args []string) error {
return quietOut(listContainers)
}
+ responses := make([]psReporter, 0, len(listContainers))
for _, r := range listContainers {
responses = append(responses, psReporter{r})
}
@@ -351,7 +351,8 @@ func portsToString(ports []ocicni.PortMapping) string {
first int32
last int32
}
- var portDisplay []string
+ portDisplay := []string{}
+
if len(ports) == 0 {
return ""
}
diff --git a/cmd/podman/containers/rm.go b/cmd/podman/containers/rm.go
index b25473a8d..22d6d59b4 100644
--- a/cmd/podman/containers/rm.go
+++ b/cmd/podman/containers/rm.go
@@ -87,6 +87,14 @@ func init() {
}
func rm(cmd *cobra.Command, args []string) error {
+ return removeContainers(args, rmOptions, true)
+}
+
+// removeContainers will remove the specified containers (names or IDs).
+// Allows for sharing removal logic across commands. If setExit is set,
+// removeContainers will set the exit code according to the `podman-rm` man
+// page.
+func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit bool) error {
var (
errs utils.OutputErrors
)
@@ -96,9 +104,9 @@ func rm(cmd *cobra.Command, args []string) error {
return errors.Errorf("--storage conflicts with --volumes, --all, --latest, --ignore and --cidfile")
}
}
- responses, err := registry.ContainerEngine().ContainerRm(context.Background(), args, rmOptions)
+ responses, err := registry.ContainerEngine().ContainerRm(context.Background(), namesOrIDs, rmOptions)
if err != nil {
- if len(args) < 2 {
+ if setExit && len(namesOrIDs) < 2 {
setExitCode(err)
}
return err
@@ -109,7 +117,9 @@ func rm(cmd *cobra.Command, args []string) error {
if errors.Cause(err) == define.ErrWillDeadlock {
logrus.Errorf("Potential deadlock detected - please run 'podman system renumber' to resolve")
}
- setExitCode(r.Err)
+ if setExit {
+ setExitCode(r.Err)
+ }
errs = append(errs, r.Err)
} else {
fmt.Println(r.Id)
diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go
index 8a02c63c0..b9c196b64 100644
--- a/cmd/podman/containers/run.go
+++ b/cmd/podman/containers/run.go
@@ -129,6 +129,12 @@ func run(cmd *cobra.Command, args []string) error {
}
}
+ if cliVals.Replace {
+ if err := replaceContainer(cliVals.Name); err != nil {
+ return err
+ }
+ }
+
// If -i is not set, clear stdin
if !cliVals.Interactive {
runOpts.InputStream = nil
diff --git a/cmd/podman/containers/stats.go b/cmd/podman/containers/stats.go
index c61b161e4..260cbd25d 100644
--- a/cmd/podman/containers/stats.go
+++ b/cmd/podman/containers/stats.go
@@ -87,13 +87,13 @@ func init() {
func checkStatOptions(cmd *cobra.Command, args []string) error {
opts := 0
if statsOptions.All {
- opts += 1
+ opts++
}
if statsOptions.Latest {
- opts += 1
+ opts++
}
if len(args) > 0 {
- opts += 1
+ opts++
}
if opts > 1 {
return errors.Errorf("--all, --latest and containers cannot be used together")
@@ -134,7 +134,7 @@ func outputStats(reports []*define.ContainerStats) error {
tm.MoveCursor(1, 1)
tm.Flush()
}
- var stats []*containerStats
+ stats := make([]*containerStats, 0, len(reports))
for _, r := range reports {
stats = append(stats, &containerStats{r})
}
@@ -219,16 +219,16 @@ func combineHumanValues(a, b uint64) string {
func outputJSON(stats []*containerStats) error {
type jstat struct {
- Id string `json:"id"`
+ Id string `json:"id"` //nolint
Name string `json:"name"`
- CpuPercent string `json:"cpu_percent"`
+ CpuPercent string `json:"cpu_percent"` //nolint
MemUsage string `json:"mem_usage"`
MemPerc string `json:"mem_percent"`
NetIO string `json:"net_io"`
BlockIO string `json:"block_io"`
Pids string `json:"pids"`
}
- var jstats []jstat
+ jstats := make([]jstat, 0, len(stats))
for _, j := range stats {
jstats = append(jstats, jstat{
Id: j.ID(),
diff --git a/cmd/podman/containers/stop.go b/cmd/podman/containers/stop.go
index 22c487961..0f2a91af0 100644
--- a/cmd/podman/containers/stop.go
+++ b/cmd/podman/containers/stop.go
@@ -85,9 +85,8 @@ func stop(cmd *cobra.Command, args []string) error {
var (
errs utils.OutputErrors
)
- stopOptions.Timeout = containerConfig.Engine.StopTimeout
if cmd.Flag("time").Changed {
- stopOptions.Timeout = stopTimeout
+ stopOptions.Timeout = &stopTimeout
}
responses, err := registry.ContainerEngine().ContainerStop(context.Background(), args, stopOptions)
diff --git a/cmd/podman/containers/wait.go b/cmd/podman/containers/wait.go
index ca3883091..115bb3eea 100644
--- a/cmd/podman/containers/wait.go
+++ b/cmd/podman/containers/wait.go
@@ -23,7 +23,7 @@ var (
Short: "Block on one or more containers",
Long: waitDescription,
RunE: wait,
- Args: validate.IdOrLatestArgs,
+ Args: validate.IDOrLatestArgs,
Example: `podman wait --interval 5000 ctrID
podman wait ctrID1 ctrID2`,
}
@@ -33,7 +33,7 @@ var (
Short: waitCommand.Short,
Long: waitCommand.Long,
RunE: waitCommand.RunE,
- Args: validate.IdOrLatestArgs,
+ Args: validate.IDOrLatestArgs,
Example: `podman container wait --interval 5000 ctrID
podman container wait ctrID1 ctrID2`,
}
diff --git a/cmd/podman/diff.go b/cmd/podman/diff.go
index 1ff2fce40..d635ea57a 100644
--- a/cmd/podman/diff.go
+++ b/cmd/podman/diff.go
@@ -18,7 +18,7 @@ var (
diffDescription = `Displays changes on a container or image's filesystem. The container or image will be compared to its parent layer.`
diffCmd = &cobra.Command{
Use: "diff [flags] {CONTAINER_ID | IMAGE_ID}",
- Args: validate.IdOrLatestArgs,
+ Args: validate.IDOrLatestArgs,
Short: "Display the changes of object's file system",
Long: diffDescription,
TraverseChildren: true,
diff --git a/cmd/podman/generate/systemd.go b/cmd/podman/generate/systemd.go
index 75031e070..e4fdd8690 100644
--- a/cmd/podman/generate/systemd.go
+++ b/cmd/podman/generate/systemd.go
@@ -41,7 +41,7 @@ func init() {
flags.BoolVarP(&systemdOptions.New, "new", "", false, "Create a new container instead of starting an existing one")
flags.StringVar(&systemdOptions.ContainerPrefix, "container-prefix", "container", "Systemd unit name prefix for containers")
flags.StringVar(&systemdOptions.PodPrefix, "pod-prefix", "pod", "Systemd unit name prefix for pods")
- flags.StringVar(&systemdOptions.Separator, "separator", "-", "Systemd unit name seperator between name/id and prefix")
+ flags.StringVar(&systemdOptions.Separator, "separator", "-", "Systemd unit name separator between name/id and prefix")
flags.SetNormalizeFunc(utils.AliasFlags)
}
diff --git a/cmd/podman/images/history.go b/cmd/podman/images/history.go
index 17a80557e..ea4b9983f 100644
--- a/cmd/podman/images/history.go
+++ b/cmd/podman/images/history.go
@@ -100,7 +100,7 @@ func history(cmd *cobra.Command, args []string) error {
}
return err
}
- var hr []historyreporter
+ hr := make([]historyreporter, 0, len(results.Layers))
for _, l := range results.Layers {
hr = append(hr, historyreporter{l})
}
diff --git a/cmd/podman/images/image.go b/cmd/podman/images/image.go
index 790c16c05..ebef126c0 100644
--- a/cmd/podman/images/image.go
+++ b/cmd/podman/images/image.go
@@ -9,7 +9,7 @@ import (
var (
// Pull in configured json library
- json = registry.JsonLibrary()
+ json = registry.JSONLibrary()
// Command: podman _image_
imageCmd = &cobra.Command{
diff --git a/cmd/podman/images/list.go b/cmd/podman/images/list.go
index 23757104b..236ae15b4 100644
--- a/cmd/podman/images/list.go
+++ b/cmd/podman/images/list.go
@@ -100,7 +100,7 @@ func images(cmd *cobra.Command, args []string) error {
switch {
case listFlag.quiet:
- return writeId(summaries)
+ return writeID(summaries)
case cmd.Flag("format").Changed && listFlag.format == "json":
return writeJSON(summaries)
default:
@@ -108,7 +108,7 @@ func images(cmd *cobra.Command, args []string) error {
}
}
-func writeId(imageS []*entities.ImageSummary) error {
+func writeID(imageS []*entities.ImageSummary) error {
var ids = map[string]struct{}{}
for _, e := range imageS {
i := "sha256:" + e.ID
diff --git a/cmd/podman/inspect/inspect.go b/cmd/podman/inspect/inspect.go
index 223ce00f0..1ed033ec3 100644
--- a/cmd/podman/inspect/inspect.go
+++ b/cmd/podman/inspect/inspect.go
@@ -77,7 +77,7 @@ func newInspector(options entities.InspectOptions) (*inspector, error) {
// inspect inspects the specified container/image names or IDs.
func (i *inspector) inspect(namesOrIDs []string) error {
// data - dumping place for inspection results.
- var data []interface{}
+ var data []interface{} //nolint
ctx := context.Background()
if len(namesOrIDs) == 0 {
@@ -132,7 +132,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
}
func (i *inspector) inspectAll(ctx context.Context, namesOrIDs []string) ([]interface{}, error) {
- var data []interface{}
+ var data []interface{} //nolint
for _, name := range namesOrIDs {
imgData, err := i.imageEngine.Inspect(ctx, []string{name}, i.options)
if err == nil {
diff --git a/cmd/podman/networks/list.go b/cmd/podman/networks/list.go
index 24604c055..747fef26d 100644
--- a/cmd/podman/networks/list.go
+++ b/cmd/podman/networks/list.go
@@ -33,8 +33,8 @@ var (
var (
networkListOptions entities.NetworkListOptions
- headers string = "NAME\tVERSION\tPLUGINS\n"
- defaultListRow string = "{{.Name}}\t{{.Version}}\t{{.Plugins}}\n"
+ headers = "NAME\tVERSION\tPLUGINS\n"
+ defaultListRow = "{{.Name}}\t{{.Version}}\t{{.Plugins}}\n"
)
func networkListFlags(flags *pflag.FlagSet) {
@@ -56,10 +56,6 @@ func init() {
}
func networkList(cmd *cobra.Command, args []string) error {
- var (
- nlprs []NetworkListPrintReports
- )
-
// validate the filter pattern.
if len(networkListOptions.Filter) > 0 {
tokens := strings.Split(networkListOptions.Filter, "=")
@@ -82,8 +78,9 @@ func networkList(cmd *cobra.Command, args []string) error {
return jsonOut(responses)
}
+ nlprs := make([]ListPrintReports, 0, len(responses))
for _, r := range responses {
- nlprs = append(nlprs, NetworkListPrintReports{r})
+ nlprs = append(nlprs, ListPrintReports{r})
}
row := networkListOptions.Format
@@ -125,14 +122,14 @@ func jsonOut(responses []*entities.NetworkListReport) error {
return nil
}
-type NetworkListPrintReports struct {
+type ListPrintReports struct {
*entities.NetworkListReport
}
-func (n NetworkListPrintReports) Version() string {
+func (n ListPrintReports) Version() string {
return n.CNIVersion
}
-func (n NetworkListPrintReports) Plugins() string {
+func (n ListPrintReports) Plugins() string {
return network.GetCNIPlugins(n.NetworkConfigList)
}
diff --git a/cmd/podman/parse/common.go b/cmd/podman/parse/common.go
index 13f425b6d..b3aa88da2 100644
--- a/cmd/podman/parse/common.go
+++ b/cmd/podman/parse/common.go
@@ -5,6 +5,10 @@ import (
"github.com/spf13/cobra"
)
+// TODO: the two functions here are almost identical. It may be worth looking
+// into generalizing the two a bit more and share code but time is scarce and
+// we only live once.
+
// CheckAllLatestAndCIDFile checks that --all and --latest are used correctly.
// If cidfile is set, also check for the --cidfile flag.
func CheckAllLatestAndCIDFile(c *cobra.Command, args []string, ignoreArgLen bool, cidfile bool) error {
@@ -55,3 +59,54 @@ func CheckAllLatestAndCIDFile(c *cobra.Command, args []string, ignoreArgLen bool
}
return nil
}
+
+// CheckAllLatestAndPodIDFile checks that --all and --latest are used correctly.
+// If withIDFile is set, also check for the --pod-id-file flag.
+func CheckAllLatestAndPodIDFile(c *cobra.Command, args []string, ignoreArgLen bool, withIDFile bool) error {
+ argLen := len(args)
+ if c.Flags().Lookup("all") == nil || c.Flags().Lookup("latest") == nil {
+ if !withIDFile {
+ return errors.New("unable to lookup values for 'latest' or 'all'")
+ } else if c.Flags().Lookup("pod-id-file") == nil {
+ return errors.New("unable to lookup values for 'latest', 'all' or 'pod-id-file'")
+ }
+ }
+
+ specifiedAll, _ := c.Flags().GetBool("all")
+ specifiedLatest, _ := c.Flags().GetBool("latest")
+ specifiedPodIDFile := false
+ if pid, _ := c.Flags().GetStringArray("pod-id-file"); len(pid) > 0 {
+ specifiedPodIDFile = true
+ }
+
+ if specifiedPodIDFile && (specifiedAll || specifiedLatest) {
+ return errors.Errorf("--all, --latest and --pod-id-file cannot be used together")
+ } else if specifiedAll && specifiedLatest {
+ return errors.Errorf("--all and --latest cannot be used together")
+ }
+
+ if (argLen > 0) && specifiedAll {
+ return errors.Errorf("no arguments are needed with --all")
+ }
+
+ if ignoreArgLen {
+ return nil
+ }
+
+ if argLen > 0 {
+ if specifiedLatest {
+ return errors.Errorf("no arguments are needed with --latest")
+ } else if withIDFile && (specifiedLatest || specifiedPodIDFile) {
+ return errors.Errorf("no arguments are needed with --latest or --pod-id-file")
+ }
+ }
+
+ if specifiedPodIDFile {
+ return nil
+ }
+
+ if argLen < 1 && !specifiedAll && !specifiedLatest && !specifiedPodIDFile {
+ return errors.Errorf("you must provide at least one name or id")
+ }
+ return nil
+}
diff --git a/cmd/podman/play/kube.go b/cmd/podman/play/kube.go
index 1fbf24d5e..c26ca9853 100644
--- a/cmd/podman/play/kube.go
+++ b/cmd/podman/play/kube.go
@@ -92,21 +92,29 @@ func kube(cmd *cobra.Command, args []string) error {
return err
}
- for _, l := range report.Logs {
- fmt.Fprintf(os.Stderr, l)
+ for _, pod := range report.Pods {
+ for _, l := range pod.Logs {
+ fmt.Fprintf(os.Stderr, l)
+ }
}
- fmt.Printf("Pod:\n%s\n", report.Pod)
- switch len(report.Containers) {
- case 0:
- return nil
- case 1:
- fmt.Printf("Container:\n")
- default:
- fmt.Printf("Containers:\n")
- }
- for _, ctr := range report.Containers {
- fmt.Println(ctr)
+ for _, pod := range report.Pods {
+ fmt.Printf("Pod:\n")
+ fmt.Println(pod.ID)
+
+ switch len(pod.Containers) {
+ case 0:
+ continue
+ case 1:
+ fmt.Printf("Container:\n")
+ default:
+ fmt.Printf("Containers:\n")
+ }
+ for _, ctr := range pod.Containers {
+ fmt.Println(ctr)
+ }
+ // Empty line for space for next block
+ fmt.Println()
}
return nil
diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go
index 62b5b849e..835a62359 100644
--- a/cmd/podman/pods/create.go
+++ b/cmd/podman/pods/create.go
@@ -39,6 +39,7 @@ var (
createOptions entities.PodCreateOptions
labels, labelFile []string
podIDFile string
+ replace bool
share string
)
@@ -53,6 +54,7 @@ func init() {
flags.AddFlagSet(common.GetNetFlags())
flags.StringVar(&createOptions.CGroupParent, "cgroup-parent", "", "Set parent cgroup for the pod")
flags.BoolVar(&createOptions.Infra, "infra", true, "Create an infra container associated with the pod to share namespaces with")
+ flags.StringVar(&createOptions.InfraConmonPidFile, "infra-conmon-pidfile", "", "Path to the file that will receive the POD of the infra container's conmon")
flags.StringVar(&createOptions.InfraImage, "infra-image", containerConfig.Engine.InfraImage, "The image of the infra container to associate with the pod")
flags.StringVar(&createOptions.InfraCommand, "infra-command", containerConfig.Engine.InfraCommand, "The command to run on the infra container when the pod is started")
flags.StringSliceVar(&labelFile, "label-file", []string{}, "Read in a line delimited file of labels")
@@ -60,6 +62,7 @@ func init() {
flags.StringVarP(&createOptions.Name, "name", "n", "", "Assign a name to the pod")
flags.StringVarP(&createOptions.Hostname, "hostname", "", "", "Set a hostname to the pod")
flags.StringVar(&podIDFile, "pod-id-file", "", "Write the pod ID to the file")
+ flags.BoolVar(&replace, "replace", false, "If a pod with the same exists, replace it")
flags.StringVar(&share, "share", specgen.DefaultKernelNamespaces, "A comma delimited list of kernel namespaces the pod will share")
flags.SetNormalizeFunc(aliasNetworkFlag)
}
@@ -73,8 +76,8 @@ func aliasNetworkFlag(_ *pflag.FlagSet, name string) pflag.NormalizedName {
func create(cmd *cobra.Command, args []string) error {
var (
- err error
- podIdFile *os.File
+ err error
+ podIDFD *os.File
)
createOptions.Labels, err = parse.GetAllLabels(labelFile, labels)
if err != nil {
@@ -83,6 +86,9 @@ func create(cmd *cobra.Command, args []string) error {
if !createOptions.Infra {
logrus.Debugf("Not creating an infra container")
+ if cmd.Flag("infra-conmon-pidfile").Changed {
+ return errors.New("cannot set infra-conmon-pid without an infra container")
+ }
if cmd.Flag("infra-command").Changed {
return errors.New("cannot set infra-command without an infra container")
}
@@ -101,15 +107,15 @@ func create(cmd *cobra.Command, args []string) error {
}
if cmd.Flag("pod-id-file").Changed {
- podIdFile, err = util.OpenExclusiveFile(podIDFile)
+ podIDFD, err = util.OpenExclusiveFile(podIDFile)
if err != nil && os.IsExist(err) {
return errors.Errorf("pod id file exists. Ensure another pod is not using it or delete %s", podIDFile)
}
if err != nil {
return errors.Errorf("error opening pod-id-file %s", podIDFile)
}
- defer errorhandling.CloseQuiet(podIdFile)
- defer errorhandling.SyncQuiet(podIdFile)
+ defer errorhandling.CloseQuiet(podIDFD)
+ defer errorhandling.SyncQuiet(podIDFD)
}
createOptions.Net, err = common.NetFlagsToNetOptions(cmd)
@@ -143,6 +149,12 @@ func create(cmd *cobra.Command, args []string) error {
}
}
+ if replace {
+ if err := replacePod(createOptions.Name); err != nil {
+ return err
+ }
+ }
+
response, err := registry.ContainerEngine().PodCreate(context.Background(), createOptions)
if err != nil {
return err
@@ -155,3 +167,14 @@ func create(cmd *cobra.Command, args []string) error {
fmt.Println(response.Id)
return nil
}
+
+func replacePod(name string) error {
+ if len(name) == 0 {
+ return errors.New("cannot replace pod without --name being set")
+ }
+ rmOptions := entities.PodRmOptions{
+ Force: true, // stop and remove pod
+ Ignore: true, // ignore if pod doesn't exist
+ }
+ return removePods([]string{name}, rmOptions, false)
+}
diff --git a/cmd/podman/pods/pod.go b/cmd/podman/pods/pod.go
index ed265ef90..9dc538c71 100644
--- a/cmd/podman/pods/pod.go
+++ b/cmd/podman/pods/pod.go
@@ -10,7 +10,7 @@ import (
var (
// Pull in configured json library
- json = registry.JsonLibrary()
+ json = registry.JSONLibrary()
// Command: podman _pod_
podCmd = &cobra.Command{
diff --git a/cmd/podman/pods/ps.go b/cmd/podman/pods/ps.go
index 1385ff270..0171bb243 100644
--- a/cmd/podman/pods/ps.go
+++ b/cmd/podman/pods/ps.go
@@ -68,7 +68,6 @@ func pods(cmd *cobra.Command, args []string) error {
var (
w io.Writer = os.Stdout
row string
- lpr []ListPodReporter
)
if psInput.Quiet && len(psInput.Format) > 0 {
@@ -102,6 +101,7 @@ func pods(cmd *cobra.Command, args []string) error {
return nil
}
+ lpr := make([]ListPodReporter, 0, len(responses))
for _, r := range responses {
lpr = append(lpr, ListPodReporter{r})
}
@@ -195,7 +195,7 @@ func (l ListPodReporter) ID() string {
}
// Id returns the Pod id
-func (l ListPodReporter) Id() string {
+func (l ListPodReporter) Id() string { //nolint
if noTrunc {
return l.ListPodsReport.Id
}
@@ -209,7 +209,7 @@ func (l ListPodReporter) InfraID() string {
// InfraId returns the infra container id for the pod
// depending on trunc
-func (l ListPodReporter) InfraId() string {
+func (l ListPodReporter) InfraId() string { //nolint
if len(l.ListPodsReport.InfraId) == 0 {
return ""
}
@@ -220,7 +220,7 @@ func (l ListPodReporter) InfraId() string {
}
func (l ListPodReporter) ContainerIds() string {
- var ctrids []string
+ ctrids := make([]string, 0, len(l.Containers))
for _, c := range l.Containers {
id := c.Id
if !noTrunc {
@@ -232,7 +232,7 @@ func (l ListPodReporter) ContainerIds() string {
}
func (l ListPodReporter) ContainerNames() string {
- var ctrNames []string
+ ctrNames := make([]string, 0, len(l.Containers))
for _, c := range l.Containers {
ctrNames = append(ctrNames, c.Names)
}
@@ -240,7 +240,7 @@ func (l ListPodReporter) ContainerNames() string {
}
func (l ListPodReporter) ContainerStatuses() string {
- var statuses []string
+ statuses := make([]string, 0, len(l.Containers))
for _, c := range l.Containers {
statuses = append(statuses, c.Status)
}
@@ -252,7 +252,7 @@ func sortPodPsOutput(sortBy string, lprs []*entities.ListPodsReport) error {
case "created":
sort.Sort(podPsSortedCreated{lprs})
case "id":
- sort.Sort(podPsSortedId{lprs})
+ sort.Sort(podPsSortedID{lprs})
case "name":
sort.Sort(podPsSortedName{lprs})
case "number":
@@ -276,9 +276,9 @@ func (a podPsSortedCreated) Less(i, j int) bool {
return a.lprSort[i].Created.After(a.lprSort[j].Created)
}
-type podPsSortedId struct{ lprSort }
+type podPsSortedID struct{ lprSort }
-func (a podPsSortedId) Less(i, j int) bool { return a.lprSort[i].Id < a.lprSort[j].Id }
+func (a podPsSortedID) Less(i, j int) bool { return a.lprSort[i].Id < a.lprSort[j].Id }
type podPsSortedNumber struct{ lprSort }
diff --git a/cmd/podman/pods/rm.go b/cmd/podman/pods/rm.go
index 4b9882f8a..ec8dae1d1 100644
--- a/cmd/podman/pods/rm.go
+++ b/cmd/podman/pods/rm.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
+ "github.com/containers/libpod/cmd/podman/common"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils"
@@ -11,7 +12,15 @@ import (
"github.com/spf13/cobra"
)
+// allows for splitting API and CLI-only options
+type podRmOptionsWrapper struct {
+ entities.PodRmOptions
+
+ PodIDFiles []string
+}
+
var (
+ rmOptions = podRmOptionsWrapper{}
podRmDescription = fmt.Sprintf(`podman rm will remove one or more stopped pods and their containers from the host.
The pod name or ID can be used. A pod with containers will not be removed without --force. If --force is specified, all containers will be stopped, then removed.`)
@@ -21,7 +30,7 @@ var (
Long: podRmDescription,
RunE: rm,
Args: func(cmd *cobra.Command, args []string) error {
- return parse.CheckAllLatestAndCIDFile(cmd, args, false, false)
+ return parse.CheckAllLatestAndPodIDFile(cmd, args, false, true)
},
Example: `podman pod rm mywebserverpod
podman pod rm -f 860a4b23
@@ -29,10 +38,6 @@ var (
}
)
-var (
- rmOptions = entities.PodRmOptions{}
-)
-
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
@@ -45,6 +50,7 @@ func init() {
flags.BoolVarP(&rmOptions.Force, "force", "f", false, "Force removal of a running pod by first stopping all containers, then removing all containers in the pod. The default is false")
flags.BoolVarP(&rmOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified pod is missing")
flags.BoolVarP(&rmOptions.Latest, "latest", "l", false, "Remove the latest pod podman is aware of")
+ flags.StringArrayVarP(&rmOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("ignore")
@@ -52,17 +58,30 @@ func init() {
}
func rm(cmd *cobra.Command, args []string) error {
- var (
- errs utils.OutputErrors
- )
- responses, err := registry.ContainerEngine().PodRm(context.Background(), args, rmOptions)
+ ids, err := common.ReadPodIDFiles(rmOptions.PodIDFiles)
if err != nil {
return err
}
+ args = append(args, ids...)
+ return removePods(args, rmOptions.PodRmOptions, true)
+}
+
+// removePods removes the specified pods (names or IDs). Allows for sharing
+// pod-removal logic across commands.
+func removePods(namesOrIDs []string, rmOptions entities.PodRmOptions, printIDs bool) error {
+ var errs utils.OutputErrors
+
+ responses, err := registry.ContainerEngine().PodRm(context.Background(), namesOrIDs, rmOptions)
+ if err != nil {
+ return err
+ }
+
// in the cli, first we print out all the successful attempts
for _, r := range responses {
if r.Err == nil {
- fmt.Println(r.Id)
+ if printIDs {
+ fmt.Println(r.Id)
+ }
} else {
errs = append(errs, r.Err)
}
diff --git a/cmd/podman/pods/start.go b/cmd/podman/pods/start.go
index d0150a3c2..97020b360 100644
--- a/cmd/podman/pods/start.go
+++ b/cmd/podman/pods/start.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
+ "github.com/containers/libpod/cmd/podman/common"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils"
@@ -11,6 +12,13 @@ import (
"github.com/spf13/cobra"
)
+// allows for splitting API and CLI-only options
+type podStartOptionsWrapper struct {
+ entities.PodStartOptions
+
+ PodIDFiles []string
+}
+
var (
podStartDescription = `The pod name or ID can be used.
@@ -21,7 +29,7 @@ var (
Long: podStartDescription,
RunE: start,
Args: func(cmd *cobra.Command, args []string) error {
- return parse.CheckAllLatestAndCIDFile(cmd, args, false, false)
+ return parse.CheckAllLatestAndPodIDFile(cmd, args, false, true)
},
Example: `podman pod start podID
podman pod start --latest
@@ -30,7 +38,7 @@ var (
)
var (
- startOptions = entities.PodStartOptions{}
+ startOptions = podStartOptionsWrapper{}
)
func init() {
@@ -43,6 +51,7 @@ func init() {
flags := startCommand.Flags()
flags.BoolVarP(&startOptions.All, "all", "a", false, "Restart all running pods")
flags.BoolVarP(&startOptions.Latest, "latest", "l", false, "Restart the latest pod podman is aware of")
+ flags.StringArrayVarP(&startOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
@@ -52,7 +61,14 @@ func start(cmd *cobra.Command, args []string) error {
var (
errs utils.OutputErrors
)
- responses, err := registry.ContainerEngine().PodStart(context.Background(), args, startOptions)
+
+ ids, err := common.ReadPodIDFiles(startOptions.PodIDFiles)
+ if err != nil {
+ return err
+ }
+ args = append(args, ids...)
+
+ responses, err := registry.ContainerEngine().PodStart(context.Background(), args, startOptions.PodStartOptions)
if err != nil {
return err
}
diff --git a/cmd/podman/pods/stats.go b/cmd/podman/pods/stats.go
index d3950fdbc..d14632f01 100644
--- a/cmd/podman/pods/stats.go
+++ b/cmd/podman/pods/stats.go
@@ -71,7 +71,7 @@ func stats(cmd *cobra.Command, args []string) error {
}
format := statsOptions.Format
- doJson := strings.ToLower(format) == formats.JSONString
+ doJSON := strings.ToLower(format) == formats.JSONString
header := getPodStatsHeader(format)
for {
@@ -80,7 +80,7 @@ func stats(cmd *cobra.Command, args []string) error {
return err
}
// Print the stats in the requested format and configuration.
- if doJson {
+ if doJSON {
if err := printJSONPodStats(reports); err != nil {
return err
}
diff --git a/cmd/podman/pods/stop.go b/cmd/podman/pods/stop.go
index daf05d640..628e8a536 100644
--- a/cmd/podman/pods/stop.go
+++ b/cmd/podman/pods/stop.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
+ "github.com/containers/libpod/cmd/podman/common"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils"
@@ -11,7 +12,18 @@ import (
"github.com/spf13/cobra"
)
+// allows for splitting API and CLI-only options
+type podStopOptionsWrapper struct {
+ entities.PodStopOptions
+
+ PodIDFiles []string
+ TimeoutCLI uint
+}
+
var (
+ stopOptions = podStopOptionsWrapper{
+ PodStopOptions: entities.PodStopOptions{Timeout: -1},
+ }
podStopDescription = `The pod name or ID can be used.
This command will stop all running containers in each of the specified pods.`
@@ -22,7 +34,7 @@ var (
Long: podStopDescription,
RunE: stop,
Args: func(cmd *cobra.Command, args []string) error {
- return parse.CheckAllLatestAndCIDFile(cmd, args, false, false)
+ return parse.CheckAllLatestAndPodIDFile(cmd, args, false, true)
},
Example: `podman pod stop mywebserverpod
podman pod stop --latest
@@ -30,13 +42,6 @@ var (
}
)
-var (
- stopOptions = entities.PodStopOptions{
- Timeout: -1,
- }
- timeout uint
-)
-
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
@@ -47,7 +52,8 @@ func init() {
flags.BoolVarP(&stopOptions.All, "all", "a", false, "Stop all running pods")
flags.BoolVarP(&stopOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified pod is missing")
flags.BoolVarP(&stopOptions.Latest, "latest", "l", false, "Stop the latest pod podman is aware of")
- flags.UintVarP(&timeout, "time", "t", containerConfig.Engine.StopTimeout, "Seconds to wait for pod stop before killing the container")
+ flags.UintVarP(&stopOptions.TimeoutCLI, "time", "t", containerConfig.Engine.StopTimeout, "Seconds to wait for pod stop before killing the container")
+ flags.StringArrayVarP(&stopOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("ignore")
@@ -60,9 +66,16 @@ func stop(cmd *cobra.Command, args []string) error {
errs utils.OutputErrors
)
if cmd.Flag("time").Changed {
- stopOptions.Timeout = int(timeout)
+ stopOptions.Timeout = int(stopOptions.TimeoutCLI)
+ }
+
+ ids, err := common.ReadPodIDFiles(stopOptions.PodIDFiles)
+ if err != nil {
+ return err
}
- responses, err := registry.ContainerEngine().PodStop(context.Background(), args, stopOptions)
+ args = append(args, ids...)
+
+ responses, err := registry.ContainerEngine().PodStop(context.Background(), args, stopOptions.PodStopOptions)
if err != nil {
return err
}
diff --git a/cmd/podman/registry/json.go b/cmd/podman/registry/json.go
index f25406c3c..a8a1623f5 100644
--- a/cmd/podman/registry/json.go
+++ b/cmd/podman/registry/json.go
@@ -11,8 +11,8 @@ var (
jsonSync sync.Once
)
-// JsonLibrary provides a "encoding/json" compatible API
-func JsonLibrary() jsoniter.API {
+// JSONLibrary provides a "encoding/json" compatible API
+func JSONLibrary() jsoniter.API {
jsonSync.Do(func() {
json = jsoniter.ConfigCompatibleWithStandardLibrary
})
diff --git a/cmd/podman/report/report.go b/cmd/podman/report/report.go
index 8392f10e0..ce349ef35 100644
--- a/cmd/podman/report/report.go
+++ b/cmd/podman/report/report.go
@@ -3,4 +3,4 @@ package report
import "github.com/containers/libpod/cmd/podman/registry"
// Pull in configured json library
-var json = registry.JsonLibrary()
+var json = registry.JSONLibrary()
diff --git a/cmd/podman/root.go b/cmd/podman/root.go
index b62ee144a..4f834e87d 100644
--- a/cmd/podman/root.go
+++ b/cmd/podman/root.go
@@ -119,10 +119,10 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
}
if cmd.Flag("cpu-profile").Changed {
- f, err := os.Create(cfg.CpuProfile)
+ f, err := os.Create(cfg.CPUProfile)
if err != nil {
return errors.Wrapf(err, "unable to create cpu profiling file %s",
- cfg.CpuProfile)
+ cfg.CPUProfile)
}
if err := pprof.StartCPUProfile(f); err != nil {
return err
@@ -212,13 +212,13 @@ func rootFlags(opts *entities.PodmanConfig, flags *pflag.FlagSet) {
// V2 flags
flags.BoolVarP(&opts.Remote, "remote", "r", false, "Access remote Podman service (default false)")
// TODO Read uri from containers.config when available
- flags.StringVar(&opts.Uri, "url", registry.DefaultAPIAddress(), "URL to access Podman service (CONTAINER_HOST)")
+ flags.StringVar(&opts.URI, "url", registry.DefaultAPIAddress(), "URL to access Podman service (CONTAINER_HOST)")
flags.StringSliceVar(&opts.Identities, "identity", []string{}, "path to SSH identity file, (CONTAINER_SSHKEY)")
flags.StringVar(&opts.PassPhrase, "passphrase", "", "passphrase for identity file (not secure, CONTAINER_PASSPHRASE), ssh-agent always supported")
cfg := opts.Config
flags.StringVar(&cfg.Engine.CgroupManager, "cgroup-manager", cfg.Engine.CgroupManager, "Cgroup manager to use (\"cgroupfs\"|\"systemd\")")
- flags.StringVar(&opts.CpuProfile, "cpu-profile", "", "Path for the cpu profiling results")
+ flags.StringVar(&opts.CPUProfile, "cpu-profile", "", "Path for the cpu profiling results")
flags.StringVar(&opts.ConmonPath, "conmon", "", "Path of the conmon binary")
flags.StringVar(&cfg.Engine.NetworkCmdPath, "network-cmd-path", cfg.Engine.NetworkCmdPath, "Path to the command for configuring the network")
flags.StringVar(&cfg.Network.NetworkConfigDir, "cni-config-dir", cfg.Network.NetworkConfigDir, "Path of the configuration directory for CNI networks")
diff --git a/cmd/podman/system/df.go b/cmd/podman/system/df.go
index 8fe035209..c56990cb5 100644
--- a/cmd/podman/system/df.go
+++ b/cmd/podman/system/df.go
@@ -63,7 +63,7 @@ func printSummary(reports *entities.SystemDfReport, userFormat string) error {
dfSummaries []*dfSummary
active int
size, reclaimable int64
- format string = "{{.Type}}\t{{.Total}}\t{{.Active}}\t{{.Size}}\t{{.Reclaimable}}\n"
+ format = "{{.Type}}\t{{.Total}}\t{{.Active}}\t{{.Size}}\t{{.Reclaimable}}\n"
w io.Writer = os.Stdout
)
@@ -74,7 +74,7 @@ func printSummary(reports *entities.SystemDfReport, userFormat string) error {
for _, i := range reports.Images {
if i.Containers > 0 {
- active += 1
+ active++
}
size += i.Size
if i.Containers < 1 {
@@ -99,7 +99,7 @@ func printSummary(reports *entities.SystemDfReport, userFormat string) error {
)
for _, c := range reports.Containers {
if c.Status == "running" {
- conActive += 1
+ conActive++
} else {
conReclaimable += c.RWSize
}
@@ -147,15 +147,13 @@ func printSummary(reports *entities.SystemDfReport, userFormat string) error {
func printVerbose(reports *entities.SystemDfReport) error {
var (
- dfImages []*dfImage
- dfContainers []*dfContainer
- dfVolumes []*dfVolume
- w io.Writer = os.Stdout
+ w io.Writer = os.Stdout
)
// Images
fmt.Print("\nImages space usage:\n\n")
// convert to dfImage for output
+ dfImages := make([]*dfImage, 0, len(reports.Images))
for _, d := range reports.Images {
dfImages = append(dfImages, &dfImage{SystemDfImageReport: d})
}
@@ -170,6 +168,7 @@ func printVerbose(reports *entities.SystemDfReport) error {
fmt.Print("\nContainers space usage:\n\n")
// convert to dfContainers for output
+ dfContainers := make([]*dfContainer, 0, len(reports.Containers))
for _, d := range reports.Containers {
dfContainers = append(dfContainers, &dfContainer{SystemDfContainerReport: d})
}
@@ -183,6 +182,7 @@ func printVerbose(reports *entities.SystemDfReport) error {
// Volumes
fmt.Print("\nLocal Volumes space usage:\n\n")
+ dfVolumes := make([]*dfVolume, 0, len(reports.Volumes))
// convert to dfVolume for output
for _, d := range reports.Volumes {
dfVolumes = append(dfVolumes, &dfVolume{SystemDfVolumeReport: d})
diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go
index 27e80138e..c401c5a92 100644
--- a/cmd/podman/system/events.go
+++ b/cmd/podman/system/events.go
@@ -17,8 +17,10 @@ import (
)
var (
- eventsDescription = "Monitor podman events"
- eventsCommand = &cobra.Command{
+ eventsDescription = `Monitor podman events.
+
+ By default, streaming mode is used, printing new events as they occur. Previous events can be listed via --since and --until.`
+ eventsCommand = &cobra.Command{
Use: "events",
Args: validate.NoArgs,
Short: "Show podman events",
diff --git a/cmd/podman/system/service.go b/cmd/podman/system/service.go
index 1b07ee301..ecd17c251 100644
--- a/cmd/podman/system/service.go
+++ b/cmd/podman/system/service.go
@@ -64,7 +64,7 @@ func aliasTimeoutFlag(_ *pflag.FlagSet, name string) pflag.NormalizedName {
}
func service(cmd *cobra.Command, args []string) error {
- apiURI, err := resolveApiURI(args)
+ apiURI, err := resolveAPIURI(args)
if err != nil {
return err
}
@@ -103,7 +103,7 @@ func service(cmd *cobra.Command, args []string) error {
return restService(opts, cmd.Flags(), registry.PodmanConfig())
}
-func resolveApiURI(_url []string) (string, error) {
+func resolveAPIURI(_url []string) (string, error) {
// When determining _*THE*_ listening endpoint --
// 1) User input wins always
// 2) systemd socket activation
diff --git a/cmd/podman/system/system.go b/cmd/podman/system/system.go
index d9691ad2a..acf41a32d 100644
--- a/cmd/podman/system/system.go
+++ b/cmd/podman/system/system.go
@@ -9,7 +9,7 @@ import (
var (
// Pull in configured json library
- json = registry.JsonLibrary()
+ json = registry.JSONLibrary()
// Command: podman _system_
systemCmd = &cobra.Command{
diff --git a/cmd/podman/validate/args.go b/cmd/podman/validate/args.go
index 14b4d7897..69240798f 100644
--- a/cmd/podman/validate/args.go
+++ b/cmd/podman/validate/args.go
@@ -23,8 +23,8 @@ func SubCommandExists(cmd *cobra.Command, args []string) error {
return errors.Errorf("missing command '%[1]s COMMAND'\nTry '%[1]s --help' for more information.", cmd.CommandPath())
}
-// IdOrLatestArgs used to validate a nameOrId was provided or the "--latest" flag
-func IdOrLatestArgs(cmd *cobra.Command, args []string) error {
+// IDOrLatestArgs used to validate a nameOrId was provided or the "--latest" flag
+func IDOrLatestArgs(cmd *cobra.Command, args []string) error {
if len(args) > 1 || (len(args) == 0 && !cmd.Flag("latest").Changed) {
return fmt.Errorf("`%s` requires a name, id or the \"--latest\" flag", cmd.CommandPath())
}
diff --git a/cmd/podman/validate/choice.go b/cmd/podman/validate/choice.go
index 572c5f4a5..8bb21c591 100644
--- a/cmd/podman/validate/choice.go
+++ b/cmd/podman/validate/choice.go
@@ -6,28 +6,28 @@ import (
)
// Honors cobra.Value interface
-type choiceValue struct {
+type ChoiceValue struct {
value *string
choices []string
}
-// ChoiceValue may be used in cobra FlagSet methods Var/VarP/VarPF() to select from a set of values
+// Value may be used in cobra FlagSet methods Var/VarP/VarPF() to select from a set of values
//
// Example:
// created := validate.ChoiceValue(&opts.Sort, "command", "created", "id", "image", "names", "runningfor", "size", "status")
// flags.Var(created, "sort", "Sort output by: "+created.Choices())
-func ChoiceValue(p *string, choices ...string) *choiceValue {
- return &choiceValue{
+func Value(p *string, choices ...string) *ChoiceValue {
+ return &ChoiceValue{
value: p,
choices: choices,
}
}
-func (c *choiceValue) String() string {
+func (c *ChoiceValue) String() string {
return *c.value
}
-func (c *choiceValue) Set(value string) error {
+func (c *ChoiceValue) Set(value string) error {
for _, v := range c.choices {
if v == value {
*c.value = value
@@ -37,10 +37,10 @@ func (c *choiceValue) Set(value string) error {
return fmt.Errorf("%q is not a valid value. Choose from: %q", value, c.Choices())
}
-func (c *choiceValue) Choices() string {
+func (c *ChoiceValue) Choices() string {
return strings.Join(c.choices, ", ")
}
-func (c *choiceValue) Type() string {
+func (c *ChoiceValue) Type() string {
return "choice"
}
diff --git a/cmd/podman/volumes/create.go b/cmd/podman/volumes/create.go
index 1bec8d0e7..16ac3771e 100644
--- a/cmd/podman/volumes/create.go
+++ b/cmd/podman/volumes/create.go
@@ -67,6 +67,6 @@ func create(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
- fmt.Println(response.IdOrName)
+ fmt.Println(response.IDOrName)
return nil
}
diff --git a/cmd/podman/volumes/volume.go b/cmd/podman/volumes/volume.go
index 3e90d178c..12947a6b1 100644
--- a/cmd/podman/volumes/volume.go
+++ b/cmd/podman/volumes/volume.go
@@ -9,7 +9,7 @@ import (
var (
// Pull in configured json library
- json = registry.JsonLibrary()
+ json = registry.JSONLibrary()
// Command: podman _volume_
volumeCmd = &cobra.Command{