Merge pull request #6056 from jwhonce/wip/rootless

V2 Commands that require ParentNS (rootful) are report error
This commit is contained in:
OpenShift Merge Robot
2020-04-30 21:48:07 +02:00
committed by GitHub
2 changed files with 14 additions and 0 deletions

View File

@ -27,6 +27,9 @@ var (
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return parse.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Annotations: map[string]string{
registry.ParentNSRequired: "",
},
Example: `podman umount ctrID Example: `podman umount ctrID
podman umount ctrID1 ctrID2 ctrID3 podman umount ctrID1 ctrID2 ctrID3
podman umount --all`, podman umount --all`,

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"os" "os"
_ "github.com/containers/libpod/cmd/podman/containers" _ "github.com/containers/libpod/cmd/podman/containers"
@ -12,7 +13,9 @@ import (
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
_ "github.com/containers/libpod/cmd/podman/system" _ "github.com/containers/libpod/cmd/podman/system"
_ "github.com/containers/libpod/cmd/podman/volumes" _ "github.com/containers/libpod/cmd/podman/volumes"
"github.com/containers/libpod/pkg/rootless"
"github.com/containers/storage/pkg/reexec" "github.com/containers/storage/pkg/reexec"
"github.com/spf13/cobra"
) )
func main() { func main() {
@ -26,6 +29,14 @@ func main() {
for _, c := range registry.Commands { for _, c := range registry.Commands {
for _, m := range c.Mode { for _, m := range c.Mode {
if cfg.EngineMode == m { 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 `%s` in rootless mode", cmd.CommandPath())
}
}
parent := rootCmd parent := rootCmd
if c.Parent != nil { if c.Parent != nil {
parent = c.Parent parent = c.Parent