diff options
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/common/completion.go | 8 | ||||
-rw-r--r-- | cmd/podman/common/create.go | 8 | ||||
-rw-r--r-- | cmd/podman/common/create_opts.go | 16 | ||||
-rw-r--r-- | cmd/podman/completion/completion.go | 6 | ||||
-rw-r--r-- | cmd/podman/containers/create.go | 16 | ||||
-rw-r--r-- | cmd/podman/images/list.go | 4 | ||||
-rw-r--r-- | cmd/podman/images/pull.go | 20 | ||||
-rw-r--r-- | cmd/podman/networks/create.go | 21 | ||||
-rw-r--r-- | cmd/podman/networks/list.go | 38 |
9 files changed, 109 insertions, 28 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go index 9856e46ef..7fed15e5e 100644 --- a/cmd/podman/common/completion.go +++ b/cmd/podman/common/completion.go @@ -861,10 +861,10 @@ func AutocompletePsFilters(cmd *cobra.Command, args []string, toComplete string) "status=": func(_ string) ([]string, cobra.ShellCompDirective) { return containerStatuses, cobra.ShellCompDirectiveNoFileComp }, - "ancestor": func(s string) ([]string, cobra.ShellCompDirective) { return getImages(cmd, s) }, - "before=": func(s string) ([]string, cobra.ShellCompDirective) { return getContainers(cmd, s, completeDefault) }, - "since=": func(s string) ([]string, cobra.ShellCompDirective) { return getContainers(cmd, s, completeDefault) }, - "volume=": func(s string) ([]string, cobra.ShellCompDirective) { return getVolumes(cmd, s) }, + "ancestor=": func(s string) ([]string, cobra.ShellCompDirective) { return getImages(cmd, s) }, + "before=": func(s string) ([]string, cobra.ShellCompDirective) { return getContainers(cmd, s, completeDefault) }, + "since=": func(s string) ([]string, cobra.ShellCompDirective) { return getContainers(cmd, s, completeDefault) }, + "volume=": func(s string) ([]string, cobra.ShellCompDirective) { return getVolumes(cmd, s) }, "health=": func(_ string) ([]string, cobra.ShellCompDirective) { return []string{define.HealthCheckHealthy, define.HealthCheckUnhealthy}, cobra.ShellCompDirectiveNoFileComp diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 599b430ea..14086ace4 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -513,6 +513,14 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) { ) _ = cmd.RegisterFlagCompletionFunc(pidsLimitFlagName, completion.AutocompleteNone) + platformFlagName := "platform" + createFlags.StringVar( + &cf.Platform, + platformFlagName, "", + "Specify the platform for selecting the image. (Conflicts with override-arch and override-os)", + ) + _ = cmd.RegisterFlagCompletionFunc(platformFlagName, completion.AutocompleteNone) + podFlagName := "pod" createFlags.StringVar( &cf.Pod, diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go index 6dc43dbc6..4b0e40df2 100644 --- a/cmd/podman/common/create_opts.go +++ b/cmd/podman/common/create_opts.go @@ -78,6 +78,7 @@ type ContainerCLIOpts struct { OverrideVariant string PID string PIDsLimit *int64 + Platform string Pod string PodIDFile string PreserveFDs uint @@ -203,20 +204,14 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup for _, m := range cc.HostConfig.Mounts { mount := fmt.Sprintf("type=%s", m.Type) if len(m.Source) > 0 { - mount += fmt.Sprintf("source=%s", m.Source) + mount += fmt.Sprintf(",source=%s", m.Source) } if len(m.Target) > 0 { - mount += fmt.Sprintf("dest=%s", m.Target) + mount += fmt.Sprintf(",dst=%s", m.Target) } mounts = append(mounts, mount) } - // volumes - volumes := make([]string, 0, len(cc.Config.Volumes)) - for v := range cc.Config.Volumes { - volumes = append(volumes, v) - } - // dns dns := make([]net.IP, 0, len(cc.HostConfig.DNS)) for _, d := range cc.HostConfig.DNS { @@ -373,7 +368,6 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup UserNS: string(cc.HostConfig.UsernsMode), UTS: string(cc.HostConfig.UTSMode), Mount: mounts, - Volume: volumes, VolumesFrom: cc.HostConfig.VolumesFrom, Workdir: cc.Config.WorkingDir, Net: &netInfo, @@ -388,6 +382,10 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup } } + // volumes + if volumes := cc.HostConfig.Binds; len(volumes) > 0 { + cliOpts.Volume = volumes + } if len(cc.HostConfig.BlkioWeightDevice) > 0 { devices := make([]string, 0, len(cc.HostConfig.BlkioWeightDevice)) for _, d := range cc.HostConfig.BlkioWeightDevice { diff --git a/cmd/podman/completion/completion.go b/cmd/podman/completion/completion.go index ead8d1f05..84942a508 100644 --- a/cmd/podman/completion/completion.go +++ b/cmd/podman/completion/completion.go @@ -67,11 +67,7 @@ func completion(cmd *cobra.Command, args []string) error { var err error switch args[0] { case "bash": - if noDesc { - err = cmd.Root().GenBashCompletion(w) - } else { - err = cmd.Root().GenBashCompletionWithDesc(w) - } + err = cmd.Root().GenBashCompletion(w) case "zsh": if noDesc { err = cmd.Root().GenZshCompletionNoDesc(w) diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go index db920554e..3d87c71a9 100644 --- a/cmd/podman/containers/create.go +++ b/cmd/podman/containers/create.go @@ -18,6 +18,7 @@ import ( "github.com/containers/podman/v2/pkg/specgen" "github.com/containers/podman/v2/pkg/util" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -236,6 +237,21 @@ func pullImage(imageName string) (string, error) { imageMissing = !br.Value } + if cliVals.Platform != "" { + if cliVals.OverrideArch != "" || cliVals.OverrideOS != "" { + return "", errors.Errorf("--platform option can not be specified with --overide-arch or --override-os") + } + split := strings.SplitN(cliVals.Platform, "/", 2) + cliVals.OverrideOS = split[0] + if len(split) > 1 { + cliVals.OverrideArch = split[1] + } + if pullPolicy != config.PullImageAlways { + logrus.Info("--platform causes the pull policy to be \"always\"") + pullPolicy = config.PullImageAlways + } + } + if imageMissing || pullPolicy == config.PullImageAlways { if pullPolicy == config.PullImageNever { return "", errors.Wrapf(define.ErrNoSuchImage, "unable to find a name and tag match for %s in repotags", imageName) diff --git a/cmd/podman/images/list.go b/cmd/podman/images/list.go index bcb31e6ee..8a7951923 100644 --- a/cmd/podman/images/list.go +++ b/cmd/podman/images/list.go @@ -126,8 +126,8 @@ func images(cmd *cobra.Command, args []string) error { case listFlag.quiet: return writeID(imgs) default: - if cmd.Flag("format").Changed { - listFlag.noHeading = true // V1 compatibility + if cmd.Flags().Changed("format") && !parse.HasTable(listFlag.format) { + listFlag.noHeading = true } return writeTemplate(imgs) } diff --git a/cmd/podman/images/pull.go b/cmd/podman/images/pull.go index a6f41688c..f8e1ee226 100644 --- a/cmd/podman/images/pull.go +++ b/cmd/podman/images/pull.go @@ -3,6 +3,7 @@ package images import ( "fmt" "os" + "strings" "github.com/containers/common/pkg/auth" "github.com/containers/common/pkg/completion" @@ -11,6 +12,7 @@ import ( "github.com/containers/podman/v2/cmd/podman/registry" "github.com/containers/podman/v2/pkg/domain/entities" "github.com/containers/podman/v2/pkg/util" + "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -94,6 +96,10 @@ func pullFlags(cmd *cobra.Command) { flags.StringVar(&pullOptions.OverrideVariant, overrideVariantFlagName, "", " use VARIANT instead of the running architecture variant for choosing images") _ = cmd.RegisterFlagCompletionFunc(overrideVariantFlagName, completion.AutocompleteNone) + platformFlagName := "platform" + flags.String(platformFlagName, "", "Specify the platform for selecting the image. (Conflicts with override-arch and override-os)") + _ = cmd.RegisterFlagCompletionFunc(platformFlagName, completion.AutocompleteNone) + 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)") @@ -127,6 +133,20 @@ func imagePull(cmd *cobra.Command, args []string) error { return err } } + platform, err := cmd.Flags().GetString("platform") + if err != nil { + return err + } + if platform != "" { + if pullOptions.OverrideArch != "" || pullOptions.OverrideOS != "" { + return errors.Errorf("--platform option can not be specified with --overide-arch or --override-os") + } + split := strings.SplitN(platform, "/", 2) + pullOptions.OverrideOS = split[0] + if len(split) > 1 { + pullOptions.OverrideArch = split[1] + } + } if pullOptions.CredentialsCLI != "" { creds, err := util.ParseRegistryCreds(pullOptions.CredentialsCLI) diff --git a/cmd/podman/networks/create.go b/cmd/podman/networks/create.go index 17de2c95d..8db4bb89a 100644 --- a/cmd/podman/networks/create.go +++ b/cmd/podman/networks/create.go @@ -6,9 +6,11 @@ import ( "github.com/containers/common/pkg/completion" "github.com/containers/podman/v2/cmd/podman/common" + "github.com/containers/podman/v2/cmd/podman/parse" "github.com/containers/podman/v2/cmd/podman/registry" "github.com/containers/podman/v2/libpod/define" "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -27,6 +29,8 @@ var ( var ( networkCreateOptions entities.NetworkCreateOptions + labels []string + opts []string ) func networkCreateFlags(cmd *cobra.Command) { @@ -36,6 +40,10 @@ func networkCreateFlags(cmd *cobra.Command) { flags.StringVarP(&networkCreateOptions.Driver, driverFlagName, "d", "bridge", "driver to manage the network") _ = cmd.RegisterFlagCompletionFunc(driverFlagName, common.AutocompleteNetworkDriver) + optFlagName := "opt" + flags.StringArrayVarP(&opts, optFlagName, "o", []string{}, "Set driver specific options (default [])") + _ = cmd.RegisterFlagCompletionFunc(optFlagName, completion.AutocompleteNone) + gatewayFlagName := "gateway" flags.IPVar(&networkCreateOptions.Gateway, gatewayFlagName, nil, "IPv4 or IPv6 gateway for the subnet") _ = cmd.RegisterFlagCompletionFunc(gatewayFlagName, completion.AutocompleteNone) @@ -50,6 +58,10 @@ func networkCreateFlags(cmd *cobra.Command) { flags.StringVar(&networkCreateOptions.MacVLAN, macvlanFlagName, "", "create a Macvlan connection based on this device") _ = cmd.RegisterFlagCompletionFunc(macvlanFlagName, completion.AutocompleteNone) + labelFlagName := "label" + flags.StringArrayVar(&labels, labelFlagName, nil, "set metadata on a network") + _ = cmd.RegisterFlagCompletionFunc(labelFlagName, completion.AutocompleteNone) + // TODO not supported yet // flags.StringVar(&networkCreateOptions.IPamDriver, "ipam-driver", "", "IP Address Management Driver") @@ -81,6 +93,15 @@ func networkCreate(cmd *cobra.Command, args []string) error { } name = args[0] } + var err error + networkCreateOptions.Labels, err = parse.GetAllLabels([]string{}, labels) + if err != nil { + return errors.Wrap(err, "failed to parse labels") + } + networkCreateOptions.Options, err = parse.GetAllLabels([]string{}, opts) + if err != nil { + return errors.Wrapf(err, "unable to process options") + } response, err := registry.ContainerEngine().NetworkCreate(registry.Context(), name, networkCreateOptions) if err != nil { return err diff --git a/cmd/podman/networks/list.go b/cmd/podman/networks/list.go index dcba3f186..16ae980dc 100644 --- a/cmd/podman/networks/list.go +++ b/cmd/podman/networks/list.go @@ -16,6 +16,7 @@ import ( "github.com/containers/podman/v2/cmd/podman/validate" "github.com/containers/podman/v2/libpod/network" "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -35,17 +36,20 @@ var ( var ( networkListOptions entities.NetworkListOptions + filters []string + noTrunc bool ) func networkListFlags(flags *pflag.FlagSet) { formatFlagName := "format" - flags.StringVarP(&networkListOptions.Format, formatFlagName, "f", "", "Pretty-print networks to JSON or using a Go template") + flags.StringVar(&networkListOptions.Format, formatFlagName, "", "Pretty-print networks to JSON or using a Go template") _ = networklistCommand.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteJSONFormat) flags.BoolVarP(&networkListOptions.Quiet, "quiet", "q", false, "display only names") + flags.BoolVar(&noTrunc, "no-trunc", false, "Do not truncate the network ID") filterFlagName := "filter" - flags.StringVarP(&networkListOptions.Filter, filterFlagName, "", "", "Provide filter values (e.g. 'name=podman')") + flags.StringArrayVarP(&filters, filterFlagName, "f", nil, "Provide filter values (e.g. 'name=podman')") _ = networklistCommand.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteNetworkFilters) } @@ -61,14 +65,14 @@ func init() { } func networkList(cmd *cobra.Command, args []string) error { - // validate the filter pattern. - if len(networkListOptions.Filter) > 0 { - tokens := strings.Split(networkListOptions.Filter, "=") - if len(tokens) != 2 { - return fmt.Errorf("invalid filter syntax : %s", networkListOptions.Filter) + networkListOptions.Filters = make(map[string][]string) + for _, f := range filters { + split := strings.SplitN(f, "=", 2) + if len(split) == 1 { + return errors.Errorf("invalid filter %q", f) } + networkListOptions.Filters[split[0]] = append(networkListOptions.Filters[split[0]], split[1]) } - responses, err := registry.ContainerEngine().NetworkList(registry.Context(), networkListOptions) if err != nil { return err @@ -93,6 +97,8 @@ func networkList(cmd *cobra.Command, args []string) error { "CNIVersion": "version", "Version": "version", "Plugins": "plugins", + "Labels": "labels", + "ID": "network id", }) renderHeaders := true row := "{{.Name}}\t{{.Version}}\t{{.Plugins}}\n" @@ -144,3 +150,19 @@ func (n ListPrintReports) Version() string { func (n ListPrintReports) Plugins() string { return network.GetCNIPlugins(n.NetworkConfigList) } + +func (n ListPrintReports) Labels() string { + list := make([]string, 0, len(n.NetworkListReport.Labels)) + for k, v := range n.NetworkListReport.Labels { + list = append(list, k+"="+v) + } + return strings.Join(list, ",") +} + +func (n ListPrintReports) ID() string { + length := 12 + if noTrunc { + length = 64 + } + return network.GetNetworkID(n.Name)[:length] +} |