summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/common/create.go6
-rw-r--r--cmd/podman/common/volumes.go46
-rw-r--r--cmd/podman/containers/create.go1
-rw-r--r--cmd/podman/containers/pause.go6
-rw-r--r--cmd/podman/containers/stats.go56
-rw-r--r--cmd/podman/containers/unpause.go6
-rw-r--r--cmd/podman/images/build.go1
-rw-r--r--cmd/podman/images/list.go15
-rw-r--r--cmd/podman/images/pull.go13
-rw-r--r--cmd/podman/images/save.go7
-rw-r--r--cmd/podman/pods/ps.go2
-rw-r--r--cmd/podman/root.go6
-rw-r--r--cmd/podman/system/version.go7
13 files changed, 102 insertions, 70 deletions
diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go
index cfbcf6140..4efdf1164 100644
--- a/cmd/podman/common/create.go
+++ b/cmd/podman/common/create.go
@@ -363,7 +363,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.StringVar(
&cf.Pull,
- "pull", "missing",
+ "pull", containerConfig.Engine.PullPolicy,
`Pull image before creating ("always"|"missing"|"never")`,
)
createFlags.BoolVarP(
@@ -448,7 +448,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
createFlags.StringSliceVar(
&cf.Sysctl,
- "sysctl", containerConfig.Sysctls(),
+ "sysctl", []string{},
"Sysctl options",
)
createFlags.StringVar(
@@ -509,7 +509,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
"volume", "v", containerConfig.Volumes(),
"Bind mount a volume into the container",
)
- createFlags.StringSliceVar(
+ createFlags.StringArrayVar(
&cf.VolumesFrom,
"volumes-from", []string{},
"Mount volumes from the specified container(s)",
diff --git a/cmd/podman/common/volumes.go b/cmd/podman/common/volumes.go
index ca0b10765..2a82451e4 100644
--- a/cmd/podman/common/volumes.go
+++ b/cmd/podman/common/volumes.go
@@ -28,6 +28,7 @@ var (
errDuplicateDest = errors.Errorf("duplicate mount destination")
optionArgError = errors.Errorf("must provide an argument for option")
noDestError = errors.Errorf("must set volume destination")
+ errInvalidSyntax = errors.Errorf("incorrect mount format: should be --mount type=<bind|tmpfs|volume>,[src=<host-dir|volume-name>,]target=<ctr-dir>[,options]")
)
// Parse all volume-related options in the create config into a set of mounts
@@ -147,6 +148,27 @@ func parseVolumes(volumeFlag, mountFlag, tmpfsFlag []string, addReadOnlyTmpfs bo
return finalMounts, finalVolumes, finalOverlayVolume, nil
}
+// findMountType parses the input and extracts the type of the mount type and
+// the remaining non-type tokens.
+func findMountType(input string) (mountType string, tokens []string, err error) {
+ // Split by comma, iterate over the slice and look for
+ // "type=$mountType". Everything else is appended to tokens.
+ found := false
+ for _, s := range strings.Split(input, ",") {
+ kv := strings.Split(s, "=")
+ if found || !(len(kv) == 2 && kv[0] == "type") {
+ tokens = append(tokens, s)
+ continue
+ }
+ mountType = kv[1]
+ found = true
+ }
+ if !found {
+ err = errInvalidSyntax
+ }
+ return
+}
+
// getMounts takes user-provided input from the --mount flag and creates OCI
// spec mounts and Libpod named volumes.
// podman run --mount type=bind,src=/etc/resolv.conf,target=/etc/resolv.conf ...
@@ -156,25 +178,13 @@ func getMounts(mountFlag []string) (map[string]spec.Mount, map[string]*specgen.N
finalMounts := make(map[string]spec.Mount)
finalNamedVolumes := make(map[string]*specgen.NamedVolume)
- errInvalidSyntax := errors.Errorf("incorrect mount format: should be --mount type=<bind|tmpfs|volume>,[src=<host-dir|volume-name>,]target=<ctr-dir>[,options]")
-
- // TODO(vrothberg): the manual parsing can be replaced with a regular expression
- // to allow a more robust parsing of the mount format and to give
- // precise errors regarding supported format versus supported options.
for _, mount := range mountFlag {
- arr := strings.SplitN(mount, ",", 2)
- if len(arr) < 2 {
- return nil, nil, errors.Wrapf(errInvalidSyntax, "%q", mount)
+ // TODO: Docker defaults to "volume" if no mount type is specified.
+ mountType, tokens, err := findMountType(mount)
+ if err != nil {
+ return nil, nil, err
}
- kv := strings.Split(arr[0], "=")
- // TODO: type is not explicitly required in Docker.
- // If not specified, it defaults to "volume".
- if len(kv) != 2 || kv[0] != "type" {
- return nil, nil, errors.Wrapf(errInvalidSyntax, "%q", mount)
- }
-
- tokens := strings.Split(arr[1], ",")
- switch kv[1] {
+ switch mountType {
case TypeBind:
mount, err := getBindMount(tokens)
if err != nil {
@@ -212,7 +222,7 @@ func getMounts(mountFlag []string) (map[string]spec.Mount, map[string]*specgen.N
}
finalNamedVolumes[volume.Dest] = volume
default:
- return nil, nil, errors.Errorf("invalid filesystem type %q", kv[1])
+ return nil, nil, errors.Errorf("invalid filesystem type %q", mountType)
}
}
diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go
index 96d94dc00..d75352848 100644
--- a/cmd/podman/containers/create.go
+++ b/cmd/podman/containers/create.go
@@ -261,6 +261,7 @@ func pullImage(imageName string) (string, error) {
OverrideOS: cliVals.OverrideOS,
OverrideVariant: cliVals.OverrideVariant,
SignaturePolicy: cliVals.SignaturePolicy,
+ PullPolicy: pullPolicy,
})
if pullErr != nil {
return "", pullErr
diff --git a/cmd/podman/containers/pause.go b/cmd/podman/containers/pause.go
index c2218bc44..c5171303d 100644
--- a/cmd/podman/containers/pause.go
+++ b/cmd/podman/containers/pause.go
@@ -6,6 +6,7 @@ import (
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/utils"
+ "github.com/containers/podman/v2/pkg/cgroups"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/containers/podman/v2/pkg/rootless"
"github.com/pkg/errors"
@@ -64,7 +65,10 @@ func pause(cmd *cobra.Command, args []string) error {
errs utils.OutputErrors
)
if rootless.IsRootless() && !registry.IsRemote() {
- return errors.New("pause is not supported for rootless containers")
+ cgroupv2, _ := cgroups.IsCgroup2UnifiedMode()
+ if !cgroupv2 {
+ return errors.New("pause is not supported for cgroupv1 rootless containers")
+ }
}
if len(args) < 1 && !pauseOpts.All {
diff --git a/cmd/podman/containers/stats.go b/cmd/podman/containers/stats.go
index ddb5f32ef..bbd389bbf 100644
--- a/cmd/podman/containers/stats.go
+++ b/cmd/podman/containers/stats.go
@@ -4,7 +4,6 @@ import (
"fmt"
"os"
"strings"
- "sync"
"text/tabwriter"
"text/template"
@@ -48,8 +47,18 @@ var (
}
)
+// statsOptionsCLI is used for storing CLI arguments. Some fields are later
+// used in the backend.
+type statsOptionsCLI struct {
+ All bool
+ Format string
+ Latest bool
+ NoReset bool
+ NoStream bool
+}
+
var (
- statsOptions entities.ContainerStatsOptions
+ statsOptions statsOptionsCLI
defaultStatsRow = "{{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDS}}\n"
defaultStatsHeader = "ID\tNAME\tCPU %\tMEM USAGE / LIMIT\tMEM %\tNET IO\tBLOCK IO\tPIDS\n"
)
@@ -107,32 +116,37 @@ func stats(cmd *cobra.Command, args []string) error {
return errors.New("stats is not supported in rootless mode without cgroups v2")
}
}
- statsOptions.StatChan = make(chan []*define.ContainerStats, 1)
- wg := sync.WaitGroup{}
- wg.Add(1)
- go func() {
- for reports := range statsOptions.StatChan {
- if err := outputStats(reports); err != nil {
- logrus.Error(err)
- }
- }
- wg.Done()
- }()
- err := registry.ContainerEngine().ContainerStats(registry.Context(), args, statsOptions)
- wg.Wait()
- return err
+ // Convert to the entities options. We should not leak CLI-only
+ // options into the backend and separate concerns.
+ opts := entities.ContainerStatsOptions{
+ Latest: statsOptions.Latest,
+ Stream: !statsOptions.NoStream,
+ }
+ statsChan, err := registry.ContainerEngine().ContainerStats(registry.Context(), args, opts)
+ if err != nil {
+ return err
+ }
+ for report := range statsChan {
+ if report.Error != nil {
+ return report.Error
+ }
+ if err := outputStats(report.Stats); err != nil {
+ logrus.Error(err)
+ }
+ }
+ return nil
}
-func outputStats(reports []*define.ContainerStats) error {
+func outputStats(reports []define.ContainerStats) error {
if len(statsOptions.Format) < 1 && !statsOptions.NoReset {
tm.Clear()
tm.MoveCursor(1, 1)
tm.Flush()
}
- stats := make([]*containerStats, 0, len(reports))
+ stats := make([]containerStats, 0, len(reports))
for _, r := range reports {
- stats = append(stats, &containerStats{r})
+ stats = append(stats, containerStats{r})
}
if statsOptions.Format == "json" {
return outputJSON(stats)
@@ -163,7 +177,7 @@ func outputStats(reports []*define.ContainerStats) error {
}
type containerStats struct {
- *define.ContainerStats
+ define.ContainerStats
}
func (s *containerStats) ID() string {
@@ -213,7 +227,7 @@ func combineHumanValues(a, b uint64) string {
return fmt.Sprintf("%s / %s", units.HumanSize(float64(a)), units.HumanSize(float64(b)))
}
-func outputJSON(stats []*containerStats) error {
+func outputJSON(stats []containerStats) error {
type jstat struct {
Id string `json:"id"` //nolint
Name string `json:"name"`
diff --git a/cmd/podman/containers/unpause.go b/cmd/podman/containers/unpause.go
index 50113669c..43eaad72b 100644
--- a/cmd/podman/containers/unpause.go
+++ b/cmd/podman/containers/unpause.go
@@ -6,6 +6,7 @@ import (
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/utils"
+ "github.com/containers/podman/v2/pkg/cgroups"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/containers/podman/v2/pkg/rootless"
"github.com/pkg/errors"
@@ -62,7 +63,10 @@ func unpause(cmd *cobra.Command, args []string) error {
errs utils.OutputErrors
)
if rootless.IsRootless() && !registry.IsRemote() {
- return errors.New("unpause is not supported for rootless containers")
+ cgroupv2, _ := cgroups.IsCgroup2UnifiedMode()
+ if !cgroupv2 {
+ return errors.New("unpause is not supported for cgroupv1 rootless containers")
+ }
}
if len(args) < 1 && !unPauseOptions.All {
return errors.Errorf("you must provide at least one container name or id")
diff --git a/cmd/podman/images/build.go b/cmd/podman/images/build.go
index 00777c48c..d24bb18b6 100644
--- a/cmd/podman/images/build.go
+++ b/cmd/podman/images/build.go
@@ -436,6 +436,7 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
Quiet: flags.Quiet,
RemoveIntermediateCtrs: flags.Rm,
ReportWriter: reporter,
+ Runtime: containerConfig.RuntimePath,
RuntimeArgs: runtimeFlags,
SignBy: flags.SignBy,
SignaturePolicyPath: flags.SignaturePolicy,
diff --git a/cmd/podman/images/list.go b/cmd/podman/images/list.go
index 043871a8c..ffb341fc4 100644
--- a/cmd/podman/images/list.go
+++ b/cmd/podman/images/list.go
@@ -184,13 +184,26 @@ func sortImages(imageS []*entities.ImageSummary) ([]imageReporter, error) {
for _, e := range imageS {
var h imageReporter
if len(e.RepoTags) > 0 {
+ tagged := []imageReporter{}
+ untagged := []imageReporter{}
for _, tag := range e.RepoTags {
h.ImageSummary = *e
h.Repository, h.Tag, err = tokenRepoTag(tag)
if err != nil {
return nil, errors.Wrapf(err, "error parsing repository tag %q:", tag)
}
- imgs = append(imgs, h)
+ if h.Tag == "<none>" {
+ untagged = append(untagged, h)
+ } else {
+ tagged = append(tagged, h)
+ }
+ }
+ // Note: we only want to display "<none>" if we
+ // couldn't find any tagged name in RepoTags.
+ if len(tagged) > 0 {
+ imgs = append(imgs, tagged...)
+ } else {
+ imgs = append(imgs, untagged[0])
}
} else {
h.ImageSummary = *e
diff --git a/cmd/podman/images/pull.go b/cmd/podman/images/pull.go
index d86f9800c..448543b4d 100644
--- a/cmd/podman/images/pull.go
+++ b/cmd/podman/images/pull.go
@@ -44,10 +44,10 @@ var (
// child of the images command.
imagesPullCmd = &cobra.Command{
Use: pullCmd.Use,
+ Args: pullCmd.Args,
Short: pullCmd.Short,
Long: pullCmd.Long,
RunE: pullCmd.RunE,
- Args: cobra.ExactArgs(1),
Example: `podman image pull imageName
podman image pull fedora:latest`,
}
@@ -77,8 +77,6 @@ func init() {
// pullFlags set the flags for the pull command.
func pullFlags(flags *pflag.FlagSet) {
flags.BoolVar(&pullOptions.AllTags, "all-tags", false, "All tagged images in the repository will be pulled")
- flags.StringVar(&pullOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
- flags.StringVar(&pullOptions.CertDir, "cert-dir", "", "`Pathname` of a directory containing TLS certificates and keys")
flags.StringVar(&pullOptions.CredentialsCLI, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
flags.StringVar(&pullOptions.OverrideArch, "override-arch", "", "Use `ARCH` instead of the architecture of the machine for choosing images")
flags.StringVar(&pullOptions.OverrideOS, "override-os", "", "Use `OS` instead of the running OS for choosing images")
@@ -86,12 +84,11 @@ func pullFlags(flags *pflag.FlagSet) {
flags.Bool("disable-content-trust", false, "This is a Docker specific option and is a NOOP")
flags.BoolVarP(&pullOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images")
flags.StringVar(&pullOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
- flags.BoolVar(&pullOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")
- if registry.IsRemote() {
- _ = flags.MarkHidden("authfile")
- _ = flags.MarkHidden("cert-dir")
- _ = flags.MarkHidden("tls-verify")
+ if !registry.IsRemote() {
+ flags.StringVar(&pullOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
+ flags.StringVar(&pullOptions.CertDir, "cert-dir", "", "`Pathname` of a directory containing TLS certificates and keys")
+ flags.BoolVar(&pullOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")
}
_ = flags.MarkHidden("signature-policy")
}
diff --git a/cmd/podman/images/save.go b/cmd/podman/images/save.go
index c57f61221..b164a2534 100644
--- a/cmd/podman/images/save.go
+++ b/cmd/podman/images/save.go
@@ -94,6 +94,7 @@ func save(cmd *cobra.Command, args []string) (finalErr error) {
return errors.Errorf("--compress can only be set when --format is either 'oci-dir' or 'docker-dir'")
}
if len(saveOpts.Output) == 0 {
+ saveOpts.Quiet = true
fi := os.Stdout
if terminal.IsTerminal(int(fi.Fd())) {
return errors.Errorf("refusing to save to terminal. Use -o flag or redirect")
@@ -122,12 +123,6 @@ func save(cmd *cobra.Command, args []string) (finalErr error) {
tags = args[1:]
}
- // Decide whether c/image's progress bars should use stderr or stdout.
- // If the output is set of stdout, any log message there would corrupt
- // the tarfile.
- if saveOpts.Output == os.Stdout.Name() {
- saveOpts.Quiet = true
- }
err := registry.ImageEngine().Save(context.Background(), args[0], tags, saveOpts)
if err == nil {
succeeded = true
diff --git a/cmd/podman/pods/ps.go b/cmd/podman/pods/ps.go
index 97e528c7c..7b755cb22 100644
--- a/cmd/podman/pods/ps.go
+++ b/cmd/podman/pods/ps.go
@@ -73,7 +73,7 @@ func pods(cmd *cobra.Command, _ []string) error {
if cmd.Flag("filter").Changed {
psInput.Filters = make(map[string][]string)
for _, f := range inputFilters {
- split := strings.Split(f, "=")
+ split := strings.SplitN(f, "=", 2)
if len(split) < 2 {
return errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f)
}
diff --git a/cmd/podman/root.go b/cmd/podman/root.go
index d079018a0..6424ec12e 100644
--- a/cmd/podman/root.go
+++ b/cmd/podman/root.go
@@ -63,7 +63,7 @@ var (
PersistentPreRunE: persistentPreRunE,
RunE: validate.SubCommandExists,
PersistentPostRunE: persistentPostRunE,
- Version: version.Version,
+ Version: version.Version.String(),
}
logLevels = []string{"debug", "info", "warn", "error", "fatal", "panic"}
@@ -80,10 +80,6 @@ func init() {
)
rootFlags(rootCmd, registry.PodmanConfig())
-
- // "version" is a local flag to avoid collisions with sub-commands that use "-v"
- var dummyVersion bool
- rootCmd.Flags().BoolVarP(&dummyVersion, "version", "v", false, "Version of Podman")
}
func Execute() {
diff --git a/cmd/podman/system/version.go b/cmd/podman/system/version.go
index edc860d0e..9da7da54a 100644
--- a/cmd/podman/system/version.go
+++ b/cmd/podman/system/version.go
@@ -47,12 +47,9 @@ func version(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
- _, err = io.WriteString(os.Stdout, s)
+ _, err = io.WriteString(os.Stdout, s+"\n")
return err
case cmd.Flag("format").Changed:
- if !strings.HasSuffix(versionFormat, "\n") {
- versionFormat += "\n"
- }
out := formats.StdoutTemplate{Output: versions, Template: versionFormat}
err := out.Out()
if err != nil {
@@ -86,7 +83,7 @@ func version(cmd *cobra.Command, args []string) error {
func formatVersion(writer io.Writer, version *define.Version) {
fmt.Fprintf(writer, "Version:\t%s\n", version.Version)
- fmt.Fprintf(writer, "API Version:\t%d\n", version.APIVersion)
+ fmt.Fprintf(writer, "API Version:\t%s\n", version.APIVersion)
fmt.Fprintf(writer, "Go Version:\t%s\n", version.GoVersion)
if version.GitCommit != "" {
fmt.Fprintf(writer, "Git Commit:\t%s\n", version.GitCommit)