Skip to content

Commit

Permalink
Merge pull request #7908 from rhatdan/diff
Browse files Browse the repository at this point in the history
fix podman container exists and diff for storage containers
  • Loading branch information
openshift-merge-robot authored Oct 19, 2020
2 parents 6ec96dc + 571ae9d commit 7ffcab0
Show file tree
Hide file tree
Showing 18 changed files with 384 additions and 431 deletions.
15 changes: 12 additions & 3 deletions cmd/podman/containers/exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ var (
containerExistsDescription = `If the named container exists in local storage, podman container exists exits with 0, otherwise the exit code will be 1.`

existsCommand = &cobra.Command{
Use: "exists CONTAINER",
Use: "exists [flags] CONTAINER",
Short: "Check if a container exists in local storage",
Long: containerExistsDescription,
Example: `podman container exists containerID
Example: `podman container exists --external containerID
podman container exists myctr || podman run --name myctr [etc...]`,
RunE: exists,
Args: cobra.ExactArgs(1),
Expand All @@ -29,10 +29,19 @@ func init() {
Command: existsCommand,
Parent: containerCmd,
})
flags := existsCommand.Flags()
flags.Bool("external", false, "Check external storage containers as well as Podman containers")
}

func exists(cmd *cobra.Command, args []string) error {
response, err := registry.ContainerEngine().ContainerExists(context.Background(), args[0])
external, err := cmd.Flags().GetBool("external")
if err != nil {
return err
}
options := entities.ContainerExistsOptions{
External: external,
}
response, err := registry.ContainerEngine().ContainerExists(context.Background(), args[0], options)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func init() {
func listFlagSet(flags *pflag.FlagSet) {
flags.BoolVarP(&listOpts.All, "all", "a", false, "Show all the containers, default is only running containers")
flags.StringSliceVarP(&filters, "filter", "f", []string{}, "Filter output based on conditions given")
flags.BoolVar(&listOpts.Storage, "storage", false, "Show containers in storage not controlled by Podman")
flags.BoolVar(&listOpts.Storage, "external", false, "Show containers in storage not controlled by Podman")
flags.StringVar(&listOpts.Format, "format", "", "Pretty-print containers to JSON or using a Go template")
flags.IntVarP(&listOpts.Last, "last", "n", -1, "Print the n last created containers (all states)")
flags.BoolVar(&listOpts.Namespace, "ns", false, "Display namespace information")
Expand Down
5 changes: 4 additions & 1 deletion cmd/podman/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ func diff(cmd *cobra.Command, args []string) error {
return containers.Diff(cmd, args, diffOpts)
}

if found, err := registry.ContainerEngine().ContainerExists(registry.GetContext(), args[0]); err != nil {
options := entities.ContainerExistsOptions{
External: true,
}
if found, err := registry.ContainerEngine().ContainerExists(registry.GetContext(), args[0], options); err != nil {
return err
} else if found.Value {
return containers.Diff(cmd, args, diffOpts)
Expand Down
2 changes: 2 additions & 0 deletions cmd/podman/utils/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func AliasFlags(f *pflag.FlagSet, name string) pflag.NormalizedName {
name = "time"
case "namespace":
name = "ns"
case "storage":
name = "external"
}
return pflag.NormalizedName(name)
}
Loading

0 comments on commit 7ffcab0

Please sign in to comment.