summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/common/create.go7
-rw-r--r--cmd/podman/common/volumes.go2
-rw-r--r--cmd/podman/containers/checkpoint.go6
-rw-r--r--cmd/podman/containers/prune.go4
-rw-r--r--cmd/podman/containers/restore.go7
-rw-r--r--cmd/podman/containers/stats.go27
-rw-r--r--cmd/podman/images/build.go10
-rw-r--r--cmd/podman/images/load.go23
-rw-r--r--cmd/podman/images/search.go47
-rw-r--r--cmd/podman/play/kube.go23
-rw-r--r--cmd/podman/pods/inspect.go5
-rw-r--r--cmd/podman/pods/prune.go2
-rw-r--r--cmd/podman/pods/rm.go4
-rw-r--r--cmd/podman/pods/stats.go11
-rw-r--r--cmd/podman/system/prune.go4
-rw-r--r--cmd/podman/system/service.go2
16 files changed, 127 insertions, 57 deletions
diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go
index bbd4f6bae..280175f95 100644
--- a/cmd/podman/common/create.go
+++ b/cmd/podman/common/create.go
@@ -1,7 +1,6 @@
package common
import (
- "fmt"
"os"
"github.com/containers/common/pkg/auth"
@@ -181,7 +180,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) {
createFlags.StringSliceVar(
&cf.Devices,
deviceFlagName, devices(),
- fmt.Sprintf("Add a host device to the container"),
+ "Add a host device to the container",
)
_ = cmd.RegisterFlagCompletionFunc(deviceFlagName, completion.AutocompleteDefault)
@@ -336,7 +335,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) {
createFlags.BoolVar(
&cf.HTTPProxy,
- "http-proxy", true,
+ "http-proxy", containerConfig.Containers.HTTPProxy,
"Set proxy environment variables in the container based on the host proxy vars",
)
@@ -359,7 +358,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) {
&cf.InitPath,
initPathFlagName, initPath(),
// Do not use the Value field for setting the default value to determine user input (i.e., non-empty string)
- fmt.Sprintf("Path to the container-init binary"),
+ "Path to the container-init binary",
)
_ = cmd.RegisterFlagCompletionFunc(initPathFlagName, completion.AutocompleteDefault)
diff --git a/cmd/podman/common/volumes.go b/cmd/podman/common/volumes.go
index dfbb7b1b2..a6e6faeca 100644
--- a/cmd/podman/common/volumes.go
+++ b/cmd/podman/common/volumes.go
@@ -5,7 +5,7 @@ import (
"path/filepath"
"strings"
- "github.com/containers/buildah/pkg/parse"
+ "github.com/containers/common/pkg/parse"
"github.com/containers/podman/v2/pkg/specgen"
"github.com/containers/podman/v2/pkg/util"
spec "github.com/opencontainers/runtime-spec/specs-go"
diff --git a/cmd/podman/containers/checkpoint.go b/cmd/podman/containers/checkpoint.go
index 4a477eb10..14abfd5a7 100644
--- a/cmd/podman/containers/checkpoint.go
+++ b/cmd/podman/containers/checkpoint.go
@@ -58,6 +58,9 @@ func init() {
flags.BoolVar(&checkpointOptions.IgnoreRootFS, "ignore-rootfs", false, "Do not include root file-system changes when exporting")
flags.BoolVar(&checkpointOptions.IgnoreVolumes, "ignore-volumes", false, "Do not export volumes associated with container")
+ flags.BoolVarP(&checkpointOptions.PreCheckPoint, "pre-checkpoint", "P", false, "Dump container's memory information only, leave the container running")
+ flags.BoolVar(&checkpointOptions.WithPrevious, "with-previous", false, "Checkpoint container with pre-checkpoint images")
+
validate.AddLatestFlag(checkpointCommand, &checkpointOptions.Latest)
}
@@ -72,6 +75,9 @@ func checkpoint(cmd *cobra.Command, args []string) error {
if checkpointOptions.Export == "" && checkpointOptions.IgnoreVolumes {
return errors.Errorf("--ignore-volumes can only be used with --export")
}
+ if checkpointOptions.WithPrevious && checkpointOptions.PreCheckPoint {
+ return errors.Errorf("--with-previous can not be used with --pre-checkpoint")
+ }
responses, err := registry.ContainerEngine().ContainerCheckpoint(context.Background(), args, checkpointOptions)
if err != nil {
return err
diff --git a/cmd/podman/containers/prune.go b/cmd/podman/containers/prune.go
index d3842778b..50731dd21 100644
--- a/cmd/podman/containers/prune.go
+++ b/cmd/podman/containers/prune.go
@@ -18,9 +18,9 @@ import (
)
var (
- pruneDescription = fmt.Sprintf(`podman container prune
+ pruneDescription = `podman container prune
- Removes all non running containers`)
+ Removes all non running containers`
pruneCommand = &cobra.Command{
Use: "prune [options]",
Short: "Remove all non running containers",
diff --git a/cmd/podman/containers/restore.go b/cmd/podman/containers/restore.go
index 5245a68fa..49c0be88e 100644
--- a/cmd/podman/containers/restore.go
+++ b/cmd/podman/containers/restore.go
@@ -59,6 +59,10 @@ func init() {
flags.StringVarP(&restoreOptions.Name, nameFlagName, "n", "", "Specify new name for container restored from exported checkpoint (only works with --import)")
_ = restoreCommand.RegisterFlagCompletionFunc(nameFlagName, completion.AutocompleteNone)
+ importPreviousFlagName := "import-previous"
+ flags.StringVar(&restoreOptions.ImportPrevious, importPreviousFlagName, "", "Restore from exported pre-checkpoint archive (tar.gz)")
+ _ = restoreCommand.RegisterFlagCompletionFunc(importPreviousFlagName, completion.AutocompleteDefault)
+
flags.BoolVar(&restoreOptions.IgnoreRootFS, "ignore-rootfs", false, "Do not apply root file-system changes when importing from exported checkpoint")
flags.BoolVar(&restoreOptions.IgnoreStaticIP, "ignore-static-ip", false, "Ignore IP address set via --static-ip")
flags.BoolVar(&restoreOptions.IgnoreStaticMAC, "ignore-static-mac", false, "Ignore MAC address set via --mac-address")
@@ -71,6 +75,9 @@ func restore(_ *cobra.Command, args []string) error {
if rootless.IsRootless() {
return errors.New("restoring a container requires root")
}
+ if restoreOptions.Import == "" && restoreOptions.ImportPrevious != "" {
+ return errors.Errorf("--import-previous can only be used with --import")
+ }
if restoreOptions.Import == "" && restoreOptions.IgnoreRootFS {
return errors.Errorf("--ignore-rootfs can only be used with --import")
}
diff --git a/cmd/podman/containers/stats.go b/cmd/podman/containers/stats.go
index ca5c0fdb8..1a436aaef 100644
--- a/cmd/podman/containers/stats.go
+++ b/cmd/podman/containers/stats.go
@@ -147,13 +147,14 @@ func stats(cmd *cobra.Command, args []string) error {
func outputStats(reports []define.ContainerStats) error {
headers := report.Headers(define.ContainerStats{}, map[string]string{
- "ID": "ID",
- "CPUPerc": "CPU %",
- "MemUsage": "MEM USAGE / LIMIT",
- "MemPerc": "MEM %",
- "NetIO": "NET IO",
- "BlockIO": "BLOCK IO",
- "PIDS": "PIDS",
+ "ID": "ID",
+ "CPUPerc": "CPU %",
+ "MemUsage": "MEM USAGE / LIMIT",
+ "MemUsageBytes": "MEM USAGE / LIMIT",
+ "MemPerc": "MEM %",
+ "NetIO": "NET IO",
+ "BlockIO": "BLOCK IO",
+ "PIDS": "PIDS",
})
if !statsOptions.NoReset {
tm.Clear()
@@ -222,10 +223,15 @@ func (s *containerStats) PIDS() string {
}
return fmt.Sprintf("%d", s.PIDs)
}
+
func (s *containerStats) MemUsage() string {
return combineHumanValues(s.ContainerStats.MemUsage, s.ContainerStats.MemLimit)
}
+func (s *containerStats) MemUsageBytes() string {
+ return combineBytesValues(s.ContainerStats.MemUsage, s.ContainerStats.MemLimit)
+}
+
func floatToPercentString(f float64) string {
strippedFloat, err := utils.RemoveScientificNotationFromFloat(f)
if err != nil || strippedFloat == 0 {
@@ -242,6 +248,13 @@ func combineHumanValues(a, b uint64) string {
return fmt.Sprintf("%s / %s", units.HumanSize(float64(a)), units.HumanSize(float64(b)))
}
+func combineBytesValues(a, b uint64) string {
+ if a == 0 && b == 0 {
+ return "-- / --"
+ }
+ return fmt.Sprintf("%s / %s", units.BytesSize(float64(a)), units.BytesSize(float64(b)))
+}
+
func outputJSON(stats []containerStats) error {
type jstat struct {
Id string `json:"id"` // nolint
diff --git a/cmd/podman/images/build.go b/cmd/podman/images/build.go
index 3aca104e3..c0aa27ca1 100644
--- a/cmd/podman/images/build.go
+++ b/cmd/podman/images/build.go
@@ -135,6 +135,16 @@ func buildFlags(cmd *cobra.Command) {
logrus.Errorf("error setting up build flags: %v", err)
os.Exit(1)
}
+ // --http-proxy flag
+ // containers.conf defaults to true but we want to force false by default for remote, since settings do not apply
+ if registry.IsRemote() {
+ flag = fromAndBudFlags.Lookup("http-proxy")
+ buildOpts.HTTPProxy = false
+ if err := flag.Value.Set("false"); err != nil {
+ logrus.Errorf("unable to set --https-proxy to %v: %v", false, err)
+ }
+ flag.DefValue = "false"
+ }
flags.AddFlagSet(&fromAndBudFlags)
// Add the completion functions
fromAndBudFlagsCompletions := buildahCLI.GetFromAndBudFlagsCompletions()
diff --git a/cmd/podman/images/load.go b/cmd/podman/images/load.go
index a24f46781..59fc6f54c 100644
--- a/cmd/podman/images/load.go
+++ b/cmd/podman/images/load.go
@@ -9,9 +9,8 @@ import (
"strings"
"github.com/containers/common/pkg/completion"
- "github.com/containers/image/v5/docker/reference"
- "github.com/containers/podman/v2/cmd/podman/parse"
"github.com/containers/podman/v2/cmd/podman/registry"
+ "github.com/containers/podman/v2/cmd/podman/validate"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/containers/podman/v2/pkg/util"
"github.com/pkg/errors"
@@ -22,11 +21,11 @@ import (
var (
loadDescription = "Loads an image from a locally stored archive (tar file) into container storage."
loadCommand = &cobra.Command{
- Use: "load [options] [NAME[:TAG]]",
+ Use: "load [options]",
Short: "Load image(s) from a tar archive",
Long: loadDescription,
RunE: load,
- Args: cobra.MaximumNArgs(1),
+ Args: validate.NoArgs,
ValidArgsFunction: completion.AutocompleteNone,
}
@@ -71,22 +70,8 @@ func loadFlags(cmd *cobra.Command) {
}
func load(cmd *cobra.Command, args []string) error {
- if len(args) > 0 {
- ref, err := reference.Parse(args[0])
- if err != nil {
- return err
- }
- if t, ok := ref.(reference.Tagged); ok {
- loadOpts.Tag = t.Tag()
- } else {
- loadOpts.Tag = "latest"
- }
- if r, ok := ref.(reference.Named); ok {
- loadOpts.Name = r.Name()
- }
- }
if len(loadOpts.Input) > 0 {
- if err := parse.ValidateFileName(loadOpts.Input); err != nil {
+ if _, err := os.Stat(loadOpts.Input); err != nil {
return err
}
} else {
diff --git a/cmd/podman/images/search.go b/cmd/podman/images/search.go
index c2ef7d767..c8ea4b04a 100644
--- a/cmd/podman/images/search.go
+++ b/cmd/podman/images/search.go
@@ -26,6 +26,12 @@ type searchOptionsWrapper struct {
Format string // For go templating
}
+// listEntryTag is a utility structure used for json serialization.
+type listEntryTag struct {
+ Name string
+ Tags []string
+}
+
var (
searchOptions = searchOptionsWrapper{}
searchDescription = `Search registries for a given image. Can search all the default registries or a specific registry.
@@ -149,14 +155,13 @@ func imageSearch(cmd *cobra.Command, args []string) error {
if len(searchOptions.Filters) != 0 {
return errors.Errorf("filters are not applicable to list tags result")
}
+ if report.IsJSON(searchOptions.Format) {
+ listTagsEntries := buildListTagsJson(searchReport)
+ return printJson(listTagsEntries)
+ }
row = "{{.Name}}\t{{.Tag}}\n"
case report.IsJSON(searchOptions.Format):
- prettyJSON, err := json.MarshalIndent(searchReport, "", " ")
- if err != nil {
- return err
- }
- fmt.Println(string(prettyJSON))
- return nil
+ return printJson(searchReport)
case cmd.Flags().Changed("format"):
renderHeaders = parse.HasTable(searchOptions.Format)
row = report.NormalizeFormat(searchOptions.Format)
@@ -180,3 +185,33 @@ func imageSearch(cmd *cobra.Command, args []string) error {
return tmpl.Execute(w, searchReport)
}
+
+func printJson(v interface{}) error {
+ prettyJSON, err := json.MarshalIndent(v, "", " ")
+ if err != nil {
+ return err
+ }
+ fmt.Println(string(prettyJSON))
+ return nil
+}
+
+func buildListTagsJson(searchReport []entities.ImageSearchReport) []listEntryTag {
+ entries := []listEntryTag{}
+
+ReportLoop:
+ for _, report := range searchReport {
+ for idx, entry := range entries {
+ if entry.Name == report.Name {
+ entries[idx].Tags = append(entries[idx].Tags, report.Tag)
+ continue ReportLoop
+ }
+ }
+ newElem := listEntryTag{
+ report.Name,
+ []string{report.Tag},
+ }
+
+ entries = append(entries, newElem)
+ }
+ return entries
+}
diff --git a/cmd/podman/play/kube.go b/cmd/podman/play/kube.go
index db7280b1d..4c44fa30f 100644
--- a/cmd/podman/play/kube.go
+++ b/cmd/podman/play/kube.go
@@ -12,6 +12,7 @@ import (
"github.com/containers/podman/v2/cmd/podman/utils"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/containers/podman/v2/pkg/util"
+ "github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -126,28 +127,42 @@ func kube(cmd *cobra.Command, args []string) error {
for _, pod := range report.Pods {
for _, l := range pod.Logs {
- fmt.Fprintf(os.Stderr, l)
+ fmt.Fprint(os.Stderr, l)
}
}
+ ctrsFailed := 0
+
for _, pod := range report.Pods {
- fmt.Printf("Pod:\n")
+ fmt.Println("Pod:")
fmt.Println(pod.ID)
switch len(pod.Containers) {
case 0:
continue
case 1:
- fmt.Printf("Container:\n")
+ fmt.Println("Container:")
default:
- fmt.Printf("Containers:\n")
+ fmt.Println("Containers:")
}
for _, ctr := range pod.Containers {
fmt.Println(ctr)
}
+ ctrsFailed += len(pod.ContainerErrors)
+ // If We have errors, add a newline
+ if len(pod.ContainerErrors) > 0 {
+ fmt.Println()
+ }
+ for _, err := range pod.ContainerErrors {
+ fmt.Fprintln(os.Stderr, err)
+ }
// Empty line for space for next block
fmt.Println()
}
+ if ctrsFailed > 0 {
+ return errors.Errorf("failed to start %d containers", ctrsFailed)
+ }
+
return nil
}
diff --git a/cmd/podman/pods/inspect.go b/cmd/podman/pods/inspect.go
index 091094ff6..e809be0c9 100644
--- a/cmd/podman/pods/inspect.go
+++ b/cmd/podman/pods/inspect.go
@@ -2,7 +2,6 @@ package pods
import (
"context"
- "fmt"
"os"
"text/tabwriter"
"text/template"
@@ -21,9 +20,9 @@ var (
)
var (
- inspectDescription = fmt.Sprintf(`Display the configuration for a pod by name or id
+ inspectDescription = `Display the configuration for a pod by name or id
- By default, this will render all results in a JSON array.`)
+ By default, this will render all results in a JSON array.`
inspectCmd = &cobra.Command{
Use: "inspect [options] POD [POD...]",
diff --git a/cmd/podman/pods/prune.go b/cmd/podman/pods/prune.go
index 965c36398..a040a21b6 100644
--- a/cmd/podman/pods/prune.go
+++ b/cmd/podman/pods/prune.go
@@ -20,7 +20,7 @@ var (
)
var (
- pruneDescription = fmt.Sprintf(`podman pod prune Removes all exited pods`)
+ pruneDescription = `podman pod prune Removes all exited pods`
pruneCommand = &cobra.Command{
Use: "prune [options]",
diff --git a/cmd/podman/pods/rm.go b/cmd/podman/pods/rm.go
index ff238aa20..109f18b78 100644
--- a/cmd/podman/pods/rm.go
+++ b/cmd/podman/pods/rm.go
@@ -25,9 +25,9 @@ type podRmOptionsWrapper struct {
var (
rmOptions = podRmOptionsWrapper{}
- podRmDescription = fmt.Sprintf(`podman rm will remove one or more stopped pods and their containers from the host.
+ podRmDescription = `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.`)
+ 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.`
rmCommand = &cobra.Command{
Use: "rm [options] POD [POD...]",
Short: "Remove one or more pods",
diff --git a/cmd/podman/pods/stats.go b/cmd/podman/pods/stats.go
index 79e7cd8ed..5f79fa016 100644
--- a/cmd/podman/pods/stats.go
+++ b/cmd/podman/pods/stats.go
@@ -75,11 +75,12 @@ func stats(cmd *cobra.Command, args []string) error {
doJSON := report.IsJSON(row)
headers := report.Headers(entities.PodStatsReport{}, map[string]string{
- "CPU": "CPU %",
- "MemUsage": "MEM USAGE/ LIMIT",
- "MEM": "MEM %",
- "NET IO": "NET IO",
- "BlockIO": "BLOCK IO",
+ "CPU": "CPU %",
+ "MemUsage": "MEM USAGE/ LIMIT",
+ "MemUsageBytes": "MEM USAGE/ LIMIT",
+ "MEM": "MEM %",
+ "NET IO": "NET IO",
+ "BlockIO": "BLOCK IO",
})
for ; ; time.Sleep(time.Second) {
diff --git a/cmd/podman/system/prune.go b/cmd/podman/system/prune.go
index 87bb947ed..5e96a654a 100644
--- a/cmd/podman/system/prune.go
+++ b/cmd/podman/system/prune.go
@@ -20,11 +20,11 @@ import (
var (
pruneOptions = entities.SystemPruneOptions{}
filters []string
- pruneDescription = fmt.Sprintf(`
+ pruneDescription = `
podman system prune
Remove unused data
-`)
+`
pruneCommand = &cobra.Command{
Use: "prune [options]",
diff --git a/cmd/podman/system/service.go b/cmd/podman/system/service.go
index f8bdbfa10..f5760e172 100644
--- a/cmd/podman/system/service.go
+++ b/cmd/podman/system/service.go
@@ -80,7 +80,7 @@ func service(cmd *cobra.Command, args []string) error {
}
// socket activation uses a unix:// socket in the shipped unit files but apiURI is coded as "" at this layer.
- if "unix" == uri.Scheme && !registry.IsRemote() {
+ if uri.Scheme == "unix" && !registry.IsRemote() {
if err := syscall.Unlink(uri.Path); err != nil && !os.IsNotExist(err) {
return err
}