diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/commands.go | 4 | ||||
-rw-r--r-- | cmd/podman/container.go | 2 | ||||
-rw-r--r-- | cmd/podman/images.go | 2 | ||||
-rw-r--r-- | cmd/podman/images_prune.go | 2 | ||||
-rw-r--r-- | cmd/podman/main.go | 2 | ||||
-rw-r--r-- | cmd/podman/pull.go | 129 | ||||
-rw-r--r-- | cmd/podman/restart.go | 84 | ||||
-rw-r--r-- | cmd/podman/rmi.go | 2 | ||||
-rw-r--r-- | cmd/podman/shared/events.go | 115 | ||||
-rw-r--r-- | cmd/podman/system_df.go | 10 | ||||
-rw-r--r-- | cmd/podman/system_prune.go | 2 | ||||
-rw-r--r-- | cmd/podman/top.go | 28 | ||||
-rw-r--r-- | cmd/podman/varlink/io.podman.varlink | 2 |
13 files changed, 106 insertions, 278 deletions
diff --git a/cmd/podman/commands.go b/cmd/podman/commands.go index c36452cfe..c43ecec5c 100644 --- a/cmd/podman/commands.go +++ b/cmd/podman/commands.go @@ -19,10 +19,8 @@ func getMainCommands() []*cobra.Command { _mountCommand, _portCommand, _refreshCommand, - _restartCommand, _searchCommand, _statsCommand, - _topCommand, } if len(_varlinkCommand.Use) > 0 { @@ -50,12 +48,10 @@ func getContainerSubCommands() []*cobra.Command { _portCommand, _pruneContainersCommand, _refreshCommand, - _restartCommand, _restoreCommand, _runlabelCommand, _statsCommand, _stopCommand, - _topCommand, _umountCommand, } } diff --git a/cmd/podman/container.go b/cmd/podman/container.go index 7733c8eef..52152d50e 100644 --- a/cmd/podman/container.go +++ b/cmd/podman/container.go @@ -60,9 +60,11 @@ var ( _listSubCommand, _logsCommand, _pauseCommand, + _restartCommand, _runCommand, _rmCommand, _startCommand, + _topCommand, _unpauseCommand, _waitCommand, } diff --git a/cmd/podman/images.go b/cmd/podman/images.go index f584c1131..41aa213a8 100644 --- a/cmd/podman/images.go +++ b/cmd/podman/images.go @@ -243,7 +243,7 @@ func getImagesTemplateOutput(ctx context.Context, images []*adapter.ContainerIma // If all is false and the image doesn't have a name, check to see if the top layer of the image is a parent // to another image's top layer. If it is, then it is an intermediate image so don't print out if the --all flag // is not set. - isParent, err := img.IsParent() + isParent, err := img.IsParent(ctx) if err != nil { logrus.Errorf("error checking if image is a parent %q: %v", img.ID(), err) } diff --git a/cmd/podman/images_prune.go b/cmd/podman/images_prune.go index 84181d0a2..c522c8b15 100644 --- a/cmd/podman/images_prune.go +++ b/cmd/podman/images_prune.go @@ -45,7 +45,7 @@ func pruneImagesCmd(c *cliconfig.PruneImagesValues) error { // Call prune; if any cids are returned, print them and then // return err in case an error also came up - pruneCids, err := runtime.PruneImages(c.All) + pruneCids, err := runtime.PruneImages(getContext(), c.All) if len(pruneCids) > 0 { for _, cid := range pruneCids { fmt.Println(cid) diff --git a/cmd/podman/main.go b/cmd/podman/main.go index 15f4a5d71..a0f1cf401 100644 --- a/cmd/podman/main.go +++ b/cmd/podman/main.go @@ -50,12 +50,14 @@ var mainCommands = []*cobra.Command{ &_psCommand, _pullCommand, _pushCommand, + _restartCommand, _rmCommand, &_rmiCommand, _runCommand, _saveCommand, _stopCommand, _tagCommand, + _topCommand, _umountCommand, _unpauseCommand, _versionCommand, diff --git a/cmd/podman/pull.go b/cmd/podman/pull.go index 04eb5bd46..521419e7a 100644 --- a/cmd/podman/pull.go +++ b/cmd/podman/pull.go @@ -46,7 +46,7 @@ func init() { pullCommand.SetHelpTemplate(HelpTemplate()) pullCommand.SetUsageTemplate(UsageTemplate()) flags := pullCommand.Flags() - flags.BoolVar(&pullCommand.AllTags, "all-tags", false, "All tagged images inthe repository will be pulled") + flags.BoolVar(&pullCommand.AllTags, "all-tags", false, "All tagged images in the repository will be pulled") flags.StringVar(&pullCommand.CertDir, "cert-dir", "", "`Pathname` of a directory containing TLS certificates and keys") flags.StringVar(&pullCommand.Creds, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry") flags.BoolVarP(&pullCommand.Quiet, "quiet", "q", false, "Suppress output information when pulling images") @@ -94,8 +94,9 @@ func pullCmd(c *cliconfig.PullValues) (retError error) { return errors.Errorf("tag can't be used with --all-tags") } } + ctx := getContext() - img := args[0] + imgArg := args[0] var registryCreds *types.DockerAuthConfig @@ -122,68 +123,86 @@ func pullCmd(c *cliconfig.PullValues) (retError error) { dockerRegistryOptions.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!c.TlsVerify) } - // Possible for docker-archive to have multiple tags, so use LoadFromArchiveReference instead - if strings.HasPrefix(img, dockerarchive.Transport.Name()+":") { - srcRef, err := alltransports.ParseImageName(img) + // Special-case for docker-archive which allows multiple tags. + if strings.HasPrefix(imgArg, dockerarchive.Transport.Name()+":") { + srcRef, err := alltransports.ParseImageName(imgArg) if err != nil { - return errors.Wrapf(err, "error parsing %q", img) + return errors.Wrapf(err, "error parsing %q", imgArg) } newImage, err := runtime.LoadFromArchiveReference(getContext(), srcRef, c.SignaturePolicy, writer) if err != nil { - return errors.Wrapf(err, "error pulling image from %q", img) + return errors.Wrapf(err, "error pulling image from %q", imgArg) } fmt.Println(newImage[0].ID()) - } else { - authfile := getAuthFile(c.String("authfile")) - spec := img - systemContext := image.GetSystemContext("", authfile, false) - srcRef, err := alltransports.ParseImageName(spec) + + return nil + } + + authfile := getAuthFile(c.String("authfile")) + + // FIXME: the default pull consults the registries.conf's search registries + // while the all-tags pull does not. This behavior must be fixed in the + // future and span across c/buildah, c/image and c/libpod to avoid redundant + // and error prone code. + // + // See https://bugzilla.redhat.com/show_bug.cgi?id=1701922 for background + // information. + if !c.Bool("all-tags") { + newImage, err := runtime.New(getContext(), imgArg, c.SignaturePolicy, authfile, writer, &dockerRegistryOptions, image.SigningOptions{}, true, nil) if err != nil { - dockerTransport := "docker://" - logrus.Debugf("error parsing image name %q, trying with transport %q: %v", spec, dockerTransport, err) - spec = dockerTransport + spec - srcRef2, err2 := alltransports.ParseImageName(spec) - if err2 != nil { - return errors.Wrapf(err2, "error parsing image name %q", img) - } - srcRef = srcRef2 - } - var names []string - if c.Bool("all-tags") { - if srcRef.DockerReference() == nil { - return errors.New("Non-docker transport is currently not supported") - } - tags, err := docker.GetRepositoryTags(ctx, systemContext, srcRef) - if err != nil { - return errors.Wrapf(err, "error getting repository tags") - } - for _, tag := range tags { - name := spec + ":" + tag - names = append(names, name) - } - } else { - names = append(names, spec) + return errors.Wrapf(err, "error pulling image %q", imgArg) } - var foundIDs []string - foundImage := true - for _, name := range names { - newImage, err := runtime.New(getContext(), name, c.String("signature-policy"), authfile, writer, &dockerRegistryOptions, image.SigningOptions{}, true, nil) - if err != nil { - logrus.Errorf("error pulling image %q", name) - foundImage = false - continue - } - foundIDs = append(foundIDs, newImage.ID()) - } - if len(names) == 1 && !foundImage { - return errors.Wrapf(err, "error pulling image %q", img) - } - if len(names) > 1 { - fmt.Println("Pulled Images:") + fmt.Println(newImage.ID()) + return nil + } + + // FIXME: all-tags should use the libpod backend instead of baking its own bread. + spec := imgArg + systemContext := image.GetSystemContext("", authfile, false) + srcRef, err := alltransports.ParseImageName(spec) + if err != nil { + dockerTransport := "docker://" + logrus.Debugf("error parsing image name %q, trying with transport %q: %v", spec, dockerTransport, err) + spec = dockerTransport + spec + srcRef2, err2 := alltransports.ParseImageName(spec) + if err2 != nil { + return errors.Wrapf(err2, "error parsing image name %q", imgArg) } - for _, id := range foundIDs { - fmt.Println(id) + srcRef = srcRef2 + } + var names []string + if srcRef.DockerReference() == nil { + return errors.New("Non-docker transport is currently not supported") + } + tags, err := docker.GetRepositoryTags(ctx, systemContext, srcRef) + if err != nil { + return errors.Wrapf(err, "error getting repository tags") + } + for _, tag := range tags { + name := spec + ":" + tag + names = append(names, name) + } + + var foundIDs []string + foundImage := true + for _, name := range names { + newImage, err := runtime.New(getContext(), name, c.String("signature-policy"), authfile, writer, &dockerRegistryOptions, image.SigningOptions{}, true, nil) + if err != nil { + logrus.Errorf("error pulling image %q", name) + foundImage = false + continue } - } // end else if strings.HasPrefix(img, dockerarchive.Transport.Name()+":") + foundIDs = append(foundIDs, newImage.ID()) + } + if len(names) == 1 && !foundImage { + return errors.Wrapf(err, "error pulling image %q", imgArg) + } + if len(names) > 1 { + fmt.Println("Pulled Images:") + } + for _, id := range foundIDs { + fmt.Println(id) + } + return nil } diff --git a/cmd/podman/restart.go b/cmd/podman/restart.go index 5a9f3043a..9ab2dd528 100644 --- a/cmd/podman/restart.go +++ b/cmd/podman/restart.go @@ -2,11 +2,9 @@ package main import ( "github.com/containers/libpod/cmd/podman/cliconfig" - "github.com/containers/libpod/cmd/podman/libpodruntime" - "github.com/containers/libpod/cmd/podman/shared" "github.com/containers/libpod/libpod" + "github.com/containers/libpod/pkg/adapter" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -22,7 +20,6 @@ var ( RunE: func(cmd *cobra.Command, args []string) error { restartCommand.InputArgs = args restartCommand.GlobalFlags = MainGlobalOpts - restartCommand.Remote = remoteclient return restartCmd(&restartCommand) }, Args: func(cmd *cobra.Command, args []string) error { @@ -49,83 +46,30 @@ func init() { } func restartCmd(c *cliconfig.RestartValues) error { - var ( - restartFuncs []shared.ParallelWorkerInput - containers []*libpod.Container - restartContainers []*libpod.Container - ) - - args := c.InputArgs - runOnly := c.Running all := c.All - if len(args) < 1 && !c.Latest && !all { + if len(c.InputArgs) < 1 && !c.Latest && !all { return errors.Wrapf(libpod.ErrInvalidArg, "you must provide at least one container name or ID") } - runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) + runtime, err := adapter.GetRuntime(&c.PodmanCommand) if err != nil { return errors.Wrapf(err, "error creating libpod runtime") } defer runtime.Shutdown(false) - timeout := c.Timeout - useTimeout := c.Flag("timeout").Changed || c.Flag("time").Changed - - // Handle --latest - if c.Latest { - lastCtr, err := runtime.GetLatestContainer() - if err != nil { - return errors.Wrapf(err, "unable to get latest container") - } - restartContainers = append(restartContainers, lastCtr) - } else if runOnly { - containers, err = getAllOrLatestContainers(&c.PodmanCommand, runtime, libpod.ContainerStateRunning, "running") - if err != nil { - return err - } - restartContainers = append(restartContainers, containers...) - } else if all { - containers, err = runtime.GetAllContainers() - if err != nil { - return err - } - restartContainers = append(restartContainers, containers...) - } else { - for _, id := range args { - ctr, err := runtime.LookupContainer(id) - if err != nil { - return err + ok, failures, err := runtime.Restart(getContext(), c) + if err != nil { + if errors.Cause(err) == libpod.ErrNoSuchCtr { + if len(c.InputArgs) > 1 { + exitCode = 125 + } else { + exitCode = 1 } - restartContainers = append(restartContainers, ctr) } + return err } - - maxWorkers := shared.Parallelize("restart") - if c.GlobalIsSet("max-workers") { - maxWorkers = c.GlobalFlags.MaxWorks + if len(failures) > 0 { + exitCode = 125 } - - logrus.Debugf("Setting maximum workers to %d", maxWorkers) - - // We now have a slice of all the containers to be restarted. Iterate them to - // create restart Funcs with a timeout as needed - for _, ctr := range restartContainers { - con := ctr - ctrTimeout := ctr.StopTimeout() - if useTimeout { - ctrTimeout = timeout - } - - f := func() error { - return con.RestartWithTimeout(getContext(), ctrTimeout) - } - - restartFuncs = append(restartFuncs, shared.ParallelWorkerInput{ - ContainerID: con.ID(), - ParallelFunc: f, - }) - } - - restartErrors, errCount := shared.ParallelExecuteWorkerPool(maxWorkers, restartFuncs) - return printParallelOutput(restartErrors, errCount) + return printCmdResults(ok, failures) } diff --git a/cmd/podman/rmi.go b/cmd/podman/rmi.go index 7ec875d5b..be7c81dab 100644 --- a/cmd/podman/rmi.go +++ b/cmd/podman/rmi.go @@ -97,7 +97,7 @@ func rmiCmd(c *cliconfig.RmiValues) error { return errors.New("unable to delete all images; re-run the rmi command again.") } for _, i := range imagesToDelete { - isParent, err := i.IsParent() + isParent, err := i.IsParent(ctx) if err != nil { return err } diff --git a/cmd/podman/shared/events.go b/cmd/podman/shared/events.go deleted file mode 100644 index c62044271..000000000 --- a/cmd/podman/shared/events.go +++ /dev/null @@ -1,115 +0,0 @@ -package shared - -import ( - "fmt" - "strings" - "time" - - "github.com/containers/libpod/libpod/events" - "github.com/containers/libpod/pkg/util" - "github.com/pkg/errors" -) - -func generateEventFilter(filter, filterValue string) (func(e *events.Event) bool, error) { - switch strings.ToUpper(filter) { - case "CONTAINER": - return func(e *events.Event) bool { - if e.Type != events.Container { - return false - } - if e.Name == filterValue { - return true - } - return strings.HasPrefix(e.ID, filterValue) - }, nil - case "EVENT", "STATUS": - return func(e *events.Event) bool { - return fmt.Sprintf("%s", e.Status) == filterValue - }, nil - case "IMAGE": - return func(e *events.Event) bool { - if e.Type != events.Image { - return false - } - if e.Name == filterValue { - return true - } - return strings.HasPrefix(e.ID, filterValue) - }, nil - case "POD": - return func(e *events.Event) bool { - if e.Type != events.Pod { - return false - } - if e.Name == filterValue { - return true - } - return strings.HasPrefix(e.ID, filterValue) - }, nil - case "VOLUME": - return func(e *events.Event) bool { - if e.Type != events.Volume { - return false - } - return strings.HasPrefix(e.ID, filterValue) - }, nil - case "TYPE": - return func(e *events.Event) bool { - return fmt.Sprintf("%s", e.Type) == filterValue - }, nil - } - return nil, errors.Errorf("%s is an invalid filter", filter) -} - -func generateEventSinceOption(timeSince time.Time) func(e *events.Event) bool { - return func(e *events.Event) bool { - return e.Time.After(timeSince) - } -} - -func generateEventUntilOption(timeUntil time.Time) func(e *events.Event) bool { - return func(e *events.Event) bool { - return e.Time.Before(timeUntil) - - } -} - -func parseFilter(filter string) (string, string, error) { - filterSplit := strings.Split(filter, "=") - if len(filterSplit) != 2 { - return "", "", errors.Errorf("%s is an invalid filter", filter) - } - return filterSplit[0], filterSplit[1], nil -} - -func GenerateEventOptions(filters []string, since, until string) ([]events.EventFilter, error) { - var options []events.EventFilter - for _, filter := range filters { - key, val, err := parseFilter(filter) - if err != nil { - return nil, err - } - funcFilter, err := generateEventFilter(key, val) - if err != nil { - return nil, err - } - options = append(options, funcFilter) - } - - if len(since) > 0 { - timeSince, err := util.ParseInputTime(since) - if err != nil { - return nil, errors.Wrapf(err, "unable to convert since time of %s", since) - } - options = append(options, generateEventSinceOption(timeSince)) - } - - if len(until) > 0 { - timeUntil, err := util.ParseInputTime(until) - if err != nil { - return nil, errors.Wrapf(err, "unable to convert until time of %s", until) - } - options = append(options, generateEventUntilOption(timeUntil)) - } - return options, nil -} diff --git a/cmd/podman/system_df.go b/cmd/podman/system_df.go index 16a8ad120..aa0ead022 100644 --- a/cmd/podman/system_df.go +++ b/cmd/podman/system_df.go @@ -201,7 +201,7 @@ func imageUniqueSize(ctx context.Context, images []*image.Image) (map[string]uin for _, img := range images { parentImg := img for { - next, err := parentImg.GetParent() + next, err := parentImg.GetParent(ctx) if err != nil { return nil, errors.Wrapf(err, "error getting parent of image %s", parentImg.ID()) } @@ -246,11 +246,11 @@ func getImageDiskUsage(ctx context.Context, images []*image.Image, imageUsedbyCi unreclaimableSize += imageUsedSize(img, imgUniqueSizeMap, imageUsedbyCintainerMap, imageUsedbyActiveContainerMap) - isParent, err := img.IsParent() + isParent, err := img.IsParent(ctx) if err != nil { return imageDiskUsage, err } - parent, err := img.GetParent() + parent, err := img.GetParent(ctx) if err != nil { return imageDiskUsage, errors.Wrapf(err, "error getting parent of image %s", img.ID()) } @@ -437,11 +437,11 @@ func getImageVerboseDiskUsage(ctx context.Context, images []*image.Image, images return imagesVerboseDiskUsage, errors.Wrapf(err, "error getting unique size of images") } for _, img := range images { - isParent, err := img.IsParent() + isParent, err := img.IsParent(ctx) if err != nil { return imagesVerboseDiskUsage, errors.Wrapf(err, "error checking if %s is a parent images", img.ID()) } - parent, err := img.GetParent() + parent, err := img.GetParent(ctx) if err != nil { return imagesVerboseDiskUsage, errors.Wrapf(err, "error getting parent of image %s", img.ID()) } diff --git a/cmd/podman/system_prune.go b/cmd/podman/system_prune.go index 8900e2644..2c1c5607a 100644 --- a/cmd/podman/system_prune.go +++ b/cmd/podman/system_prune.go @@ -110,7 +110,7 @@ Are you sure you want to continue? [y/N] `, volumeString) // Call prune; if any cids are returned, print them and then // return err in case an error also came up - pruneCids, err := runtime.PruneImages(c.All) + pruneCids, err := runtime.PruneImages(ctx, c.All) if len(pruneCids) > 0 { fmt.Println("Deleted Images") for _, cid := range pruneCids { diff --git a/cmd/podman/top.go b/cmd/podman/top.go index 0b7da64a8..f1f594ebf 100644 --- a/cmd/podman/top.go +++ b/cmd/podman/top.go @@ -7,8 +7,8 @@ import ( "text/tabwriter" "github.com/containers/libpod/cmd/podman/cliconfig" - "github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/libpod" + "github.com/containers/libpod/pkg/adapter" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -60,7 +60,6 @@ func init() { } func topCmd(c *cliconfig.TopValues) error { - var container *libpod.Container var err error args := c.InputArgs @@ -77,37 +76,16 @@ func topCmd(c *cliconfig.TopValues) error { return errors.Errorf("you must provide the name or id of a running container") } - runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) + runtime, err := adapter.GetRuntime(&c.PodmanCommand) if err != nil { return errors.Wrapf(err, "error creating libpod runtime") } defer runtime.Shutdown(false) - var descriptors []string - if c.Latest { - descriptors = args - container, err = runtime.GetLatestContainer() - } else { - descriptors = args[1:] - container, err = runtime.LookupContainer(args[0]) - } - - if err != nil { - return errors.Wrapf(err, "unable to lookup requested container") - } - - conStat, err := container.State() - if err != nil { - return errors.Wrapf(err, "unable to look up state for %s", args[0]) - } - if conStat != libpod.ContainerStateRunning { - return errors.Errorf("top can only be used on running containers") - } - psOutput, err := container.GetContainerPidInformation(descriptors) + psOutput, err := runtime.Top(c) if err != nil { return err } - w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0) for _, proc := range psOutput { fmt.Fprintln(w, proc) diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink index 1fde72164..17179d665 100644 --- a/cmd/podman/varlink/io.podman.varlink +++ b/cmd/podman/varlink/io.podman.varlink @@ -524,6 +524,8 @@ method Ps(opts: PsOpts) -> (containers: []PsContainer) method GetContainersByStatus(status: []string) -> (containerS: []Container) +method Top (nameOrID: string, descriptors: []string) -> (top: []string) + # GetContainer returns information about a single container. If a container # with the given id doesn't exist, a [ContainerNotFound](#ContainerNotFound) # error will be returned. See also [ListContainers](ListContainers) and |