diff options
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/containers/mount.go | 17 | ||||
-rw-r--r-- | cmd/podman/containers/unmount.go | 41 | ||||
-rw-r--r-- | cmd/podman/main.go | 18 | ||||
-rw-r--r-- | cmd/podman/networks/inspect.go | 2 | ||||
-rw-r--r-- | cmd/podman/networks/list.go | 2 | ||||
-rw-r--r-- | cmd/podman/registry/config.go | 3 | ||||
-rw-r--r-- | cmd/podman/system/df.go | 2 | ||||
-rw-r--r-- | cmd/podman/system/events.go | 2 | ||||
-rw-r--r-- | cmd/podman/volumes/inspect.go | 2 | ||||
-rw-r--r-- | cmd/podman/volumes/list.go | 2 |
10 files changed, 55 insertions, 36 deletions
diff --git a/cmd/podman/containers/mount.go b/cmd/podman/containers/mount.go index 186c4df16..b578daa49 100644 --- a/cmd/podman/containers/mount.go +++ b/cmd/podman/containers/mount.go @@ -10,6 +10,7 @@ import ( "github.com/containers/libpod/v2/cmd/podman/utils" "github.com/containers/libpod/v2/cmd/podman/validate" "github.com/containers/libpod/v2/pkg/domain/entities" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -31,7 +32,8 @@ var ( return validate.CheckAllLatestAndCIDFile(cmd, args, true, false) }, Annotations: map[string]string{ - registry.ParentNSRequired: "", + registry.UnshareNSRequired: "", + registry.ParentNSRequired: "", }, } @@ -51,7 +53,7 @@ var ( func mountFlags(flags *pflag.FlagSet) { flags.BoolVarP(&mountOpts.All, "all", "a", false, "Mount all containers") - flags.StringVar(&mountOpts.Format, "format", "", "Change the output format to Go template") + flags.StringVar(&mountOpts.Format, "format", "", "Print the mounted containers in specified format (json)") flags.BoolVar(&mountOpts.NoTruncate, "notruncate", false, "Do not truncate output") } @@ -90,14 +92,21 @@ func mount(_ *cobra.Command, args []string) error { } return errs.PrintErrors() } - if mountOpts.Format == "json" { + + switch mountOpts.Format { + case "json": return printJSON(reports) + case "": + // do nothing + default: + return errors.Errorf("unknown --format argument: %s", mountOpts.Format) } + mrs := make([]mountReporter, 0, len(reports)) for _, r := range reports { mrs = append(mrs, mountReporter{r}) } - row := "{{.ID}} {{.Path}}" + row := "{{.ID}} {{.Path}}\n" format := "{{range . }}" + row + "{{end}}" tmpl, err := template.New("mounts").Parse(format) if err != nil { diff --git a/cmd/podman/containers/unmount.go b/cmd/podman/containers/unmount.go index c40c2be7e..6556a6510 100644 --- a/cmd/podman/containers/unmount.go +++ b/cmd/podman/containers/unmount.go @@ -18,31 +18,32 @@ var ( An unmount can be forced with the --force flag. ` - umountCommand = &cobra.Command{ - Use: "umount [flags] CONTAINER [CONTAINER...]", - Aliases: []string{"unmount"}, + unmountCommand = &cobra.Command{ + Use: "unmount [flags] CONTAINER [CONTAINER...]", + Aliases: []string{"umount"}, Short: "Unmounts working container's root filesystem", Long: description, RunE: unmount, Args: func(cmd *cobra.Command, args []string) error { return validate.CheckAllLatestAndCIDFile(cmd, args, false, false) }, - Example: `podman umount ctrID - podman umount ctrID1 ctrID2 ctrID3 - podman umount --all`, + Example: `podman unmount ctrID + podman unmount ctrID1 ctrID2 ctrID3 + podman unmount --all`, } containerUnmountCommand = &cobra.Command{ - Use: umountCommand.Use, - Short: umountCommand.Short, - Long: umountCommand.Long, - RunE: umountCommand.RunE, + Use: unmountCommand.Use, + Short: unmountCommand.Short, + Aliases: unmountCommand.Aliases, + Long: unmountCommand.Long, + RunE: unmountCommand.RunE, Args: func(cmd *cobra.Command, args []string) error { return validate.CheckAllLatestAndCIDFile(cmd, args, false, false) }, - Example: `podman container umount ctrID - podman container umount ctrID1 ctrID2 ctrID3 - podman container umount --all`, + Example: `podman container unmount ctrID + podman container unmount ctrID1 ctrID2 ctrID3 + podman container unmount --all`, } ) @@ -50,25 +51,25 @@ var ( unmountOpts entities.ContainerUnmountOptions ) -func umountFlags(flags *pflag.FlagSet) { - flags.BoolVarP(&unmountOpts.All, "all", "a", false, "Umount all of the currently mounted containers") - flags.BoolVarP(&unmountOpts.Force, "force", "f", false, "Force the complete umount all of the currently mounted containers") +func unmountFlags(flags *pflag.FlagSet) { + flags.BoolVarP(&unmountOpts.All, "all", "a", false, "Unmount all of the currently mounted containers") + flags.BoolVarP(&unmountOpts.Force, "force", "f", false, "Force the complete unmount of the specified mounted containers") } func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ Mode: []entities.EngineMode{entities.ABIMode}, - Command: umountCommand, + Command: unmountCommand, }) - umountFlags(umountCommand.Flags()) - validate.AddLatestFlag(umountCommand, &unmountOpts.Latest) + unmountFlags(unmountCommand.Flags()) + validate.AddLatestFlag(unmountCommand, &unmountOpts.Latest) registry.Commands = append(registry.Commands, registry.CliCommand{ Mode: []entities.EngineMode{entities.ABIMode}, Command: containerUnmountCommand, Parent: containerCmd, }) - umountFlags(containerUnmountCommand.Flags()) + unmountFlags(containerUnmountCommand.Flags()) validate.AddLatestFlag(containerUnmountCommand, &unmountOpts.Latest) } diff --git a/cmd/podman/main.go b/cmd/podman/main.go index f46f74547..d0e89c2f5 100644 --- a/cmd/podman/main.go +++ b/cmd/podman/main.go @@ -40,13 +40,21 @@ func main() { for _, m := range c.Mode { if cfg.EngineMode == m { // Command cannot be run rootless - _, found := c.Command.Annotations[registry.ParentNSRequired] - if rootless.IsRootless() && found { - c.Command.RunE = func(cmd *cobra.Command, args []string) error { - return fmt.Errorf("cannot run command %q in rootless mode", cmd.CommandPath()) + _, found := c.Command.Annotations[registry.UnshareNSRequired] + if found { + if rootless.IsRootless() && found && os.Getuid() != 0 { + c.Command.RunE = func(cmd *cobra.Command, args []string) error { + return fmt.Errorf("cannot run command %q in rootless mode, must execute `podman unshare` first", cmd.CommandPath()) + } + } + } else { + _, found = c.Command.Annotations[registry.ParentNSRequired] + if rootless.IsRootless() && found { + c.Command.RunE = func(cmd *cobra.Command, args []string) error { + return fmt.Errorf("cannot run command %q in rootless mode", cmd.CommandPath()) + } } } - parent := rootCmd if c.Parent != nil { parent = c.Parent diff --git a/cmd/podman/networks/inspect.go b/cmd/podman/networks/inspect.go index bf2c7a5e0..bfbb09cb8 100644 --- a/cmd/podman/networks/inspect.go +++ b/cmd/podman/networks/inspect.go @@ -3,10 +3,10 @@ package network import ( "encoding/json" "fmt" - "html/template" "io" "os" "strings" + "text/template" "github.com/containers/libpod/v2/cmd/podman/registry" "github.com/containers/libpod/v2/pkg/domain/entities" diff --git a/cmd/podman/networks/list.go b/cmd/podman/networks/list.go index ad2ee98b1..105bd25c6 100644 --- a/cmd/podman/networks/list.go +++ b/cmd/podman/networks/list.go @@ -3,10 +3,10 @@ package network import ( "encoding/json" "fmt" - "html/template" "os" "strings" "text/tabwriter" + "text/template" "github.com/containers/libpod/v2/cmd/podman/registry" "github.com/containers/libpod/v2/cmd/podman/validate" diff --git a/cmd/podman/registry/config.go b/cmd/podman/registry/config.go index f5a231172..a62a41c12 100644 --- a/cmd/podman/registry/config.go +++ b/cmd/podman/registry/config.go @@ -15,7 +15,8 @@ import ( ) const ( - ParentNSRequired = "ParentNSRequired" + ParentNSRequired = "ParentNSRequired" + UnshareNSRequired = "UnshareNSRequired" ) var ( diff --git a/cmd/podman/system/df.go b/cmd/podman/system/df.go index c2308f0cc..a242c4f66 100644 --- a/cmd/podman/system/df.go +++ b/cmd/podman/system/df.go @@ -2,11 +2,11 @@ package system import ( "fmt" - "html/template" "io" "os" "strings" "text/tabwriter" + "text/template" "time" "github.com/containers/libpod/v2/cmd/podman/registry" diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go index 246611c1a..0a46a4042 100644 --- a/cmd/podman/system/events.go +++ b/cmd/podman/system/events.go @@ -3,9 +3,9 @@ package system import ( "bufio" "context" - "html/template" "os" "strings" + "text/template" "github.com/containers/buildah/pkg/formats" "github.com/containers/libpod/v2/cmd/podman/registry" diff --git a/cmd/podman/volumes/inspect.go b/cmd/podman/volumes/inspect.go index 9a8f4049b..235137fc7 100644 --- a/cmd/podman/volumes/inspect.go +++ b/cmd/podman/volumes/inspect.go @@ -2,9 +2,9 @@ package volumes import ( "fmt" - "html/template" "os" "strings" + "text/template" "github.com/containers/buildah/pkg/formats" "github.com/containers/libpod/v2/cmd/podman/registry" diff --git a/cmd/podman/volumes/list.go b/cmd/podman/volumes/list.go index 9e3a8f77b..804b9f319 100644 --- a/cmd/podman/volumes/list.go +++ b/cmd/podman/volumes/list.go @@ -3,11 +3,11 @@ package volumes import ( "context" "fmt" - "html/template" "io" "os" "strings" "text/tabwriter" + "text/template" "github.com/containers/libpod/v2/cmd/podman/registry" "github.com/containers/libpod/v2/cmd/podman/validate" |