Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup messages on podman load #2674

Merged
merged 1 commit into from
Mar 18, 2019

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Mar 15, 2019

If user does not specify file or redirect for stdin, then
throw an error

Signed-off-by: Daniel J Walsh [email protected]

@rhatdan
Copy link
Member Author

rhatdan commented Mar 15, 2019

@edsantiago PTAL

@openshift-ci-robot openshift-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M labels Mar 15, 2019
@@ -81,7 +82,7 @@ func loadCmd(c *cliconfig.LoadValues) error {
defer os.Remove(outFile.Name())
defer outFile.Close()

inFile, err := os.OpenFile(input, 0, 0666)
inFile, err := os.OpenFile("/dev/stdin", 0, 0666)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be c.Input instead of the unconditional "/dev/stdin"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is the case where the user did not specify a --input file, it will pull the image from stdin, create a temporary file and then send the temporary file to containers/storage.


if input == "" {
if terminal.IsTerminal(int(os.Stdin.Fd())) {
return errors.Errorf("can not use terminal, redirect the archive or using the --input flag required")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like @edsantiago to take a look at this line, the bit after the 'or' needs help. I'd suggest "or use the --input option as required"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions:

Cannot read from terminal. Use command-line redirection or the --input flag.
Will not read from terminal. Use the --input flag, or redirect from a file/pipe.
No archive file specified; use --input to specify one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with Ed's suggestion except 'flag' s/b 'optoin'. If you pull up the man page, you'll find --input listed under "options" not "flags"

commands.md Outdated
@@ -34,7 +34,7 @@
| [podman-info(1)](/docs/podman-info.1.md) | Display system information |[![...](/docs/play.png)](https://asciinema.org/a/yKbi5fQ89y5TJ8e1RfJd4ivTD)|
| [podman-inspect(1)](/docs/podman-inspect.1.md) | Display the configuration of a container or image |[![...](/docs/play.png)](https://asciinema.org/a/133418)|
| [podman-kill(1)](/docs/podman-kill.1.md) | Kill the main process in one or more running containers |[![...](/docs/play.png)](https://asciinema.org/a/3jNos0A5yzO4hChu7ddKkUPw7)|
| [podman-load(1)](/docs/podman-load.1.md) | Load an image from docker archive or oci |[![...](/docs/play.png)](https://asciinema.org/a/kp8kOaexEhEa20P1KLZ3L5X4g)|
| [podman-load(1)](/docs/podman-load.1.md) | Load an image from container image archive |[![...](/docs/play.png)](https://asciinema.org/a/kp8kOaexEhEa20P1KLZ3L5X4g)|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/from container/from a container/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -1,22 +1,24 @@
% podman-load(1)

## NAME
podman\-load - Load an image from docker archive
podman\-load - Load an image from container image archive into container storage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/from container/from a container/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


## DESCRIPTION
**podman load** copies an image from either **docker-archive** or **oci-archive** stored
on the local machine. **podman load** reads from stdin by default or a file if the **input** flag is set.
**podman load** loads an image from either an **oci-archive** or **docker-archive** stored on the local machine into container storage. **podman load** reads from stdin by default or a file if the **input** flag is set.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/flag is set/option is set/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -1,14 +1,13 @@
% podman-save(1)

## NAME
podman\-save - Save an image to docker-archive or oci-archive
podman\-save - Save an image to container archive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/to container/to a container/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@rhatdan rhatdan force-pushed the load branch 2 times, most recently from 41f4bd9 to c0459d8 Compare March 15, 2019 21:45
@rh-atomic-bot
Copy link
Collaborator

☔ The latest upstream changes (presumably #2643) made this pull request unmergeable. Please resolve the merge conflicts.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 16, 2019
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 16, 2019
@rhatdan
Copy link
Member Author

rhatdan commented Mar 16, 2019

Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions, and one showstopper:

$ podman  load <sdfsdfsdf                                                                                                                   pr/2674 (1)
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
github.com/containers/libpod/libpod/image.(*Runtime).pullGoalFromImageReference(0xc0008a5c50, 0x1894d00, 0xc0000d0038, 0x18a1a60, 0xc00026cda0, 0xc0006f9b0c, 0x4, 0xc0001058c0, 0x0, 0x0, ...)
        /home/esm/go/src/github.com/containers/libpod/libpod/image/pull.go:188 +0xcf5
github.com/containers/libpod/libpod/image.(*Runtime).pullImageFromReference(0xc0008a5c50, 0x1894d00, 0xc0000d0038, 0x18a1a60, 0xc00026cda0, 0x1881a20, 0xc0000d4010, 0x0, 0x0, 0x0, ...)
        /home/esm/go/src/github.com/containers/libpod/libpod/image/pull.go:229 +0x1b4
github.com/containers/libpod/libpod/image.(*Runtime).LoadFromArchiveReference(0xc0008a5c50, 0x1894d00, 0xc0000d0038, 0x18a1a60, 0xc00026cda0, 0x0, 0x0, 0x1881a20, 0xc0000d4010, 0x0, ...)
        /home/esm/go/src/github.com/containers/libpod/libpod/image/image.go:182 +0x108
github.com/containers/libpod/libpod.(*Runtime).LoadImage(0xc0006f2620, 0x1894d00, 0xc0000d0038, 0x0, 0x0, 0x0, 0x0, 0x1881a20, 0xc0000d4010, 0x0, ...)
        /home/esm/go/src/github.com/containers/libpod/libpod/runtime_img.go:264 +0x323
github.com/containers/libpod/pkg/adapter.(*LocalRuntime).LoadImage(0xc0001ba1a0, 0x1894d00, 0xc0000d0038, 0x0, 0x0, 0x28318a0, 0x58b327, 0xc0007badc0, 0xc0006f60c0, 0x17)
        /home/esm/go/src/github.com/containers/libpod/pkg/adapter/runtime.go:329 +0xc4
main.loadCmd(0x28318a0, 0x0, 0x0)
        /home/esm/go/src/github.com/containers/libpod/cmd/podman/load.go:103 +0x165
main.glob..func32(0x2689d80, 0x28524a8, 0x0, 0x0, 0x0, 0x0)
        /home/esm/go/src/github.com/containers/libpod/cmd/podman/load.go:28 +0x7f
github.com/containers/libpod/vendor/github.com/spf13/cobra.(*Command).execute(0x2689d80, 0xc0000da010, 0x0, 0x0, 0x2689d80, 0xc0000da010)
        /home/esm/go/src/github.com/containers/libpod/vendor/github.com/spf13/cobra/command.go:762 +0x473
github.com/containers/libpod/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x268e4c0, 0xc, 0x2854040, 0xc000774000)
        /home/esm/go/src/github.com/containers/libpod/vendor/github.com/spf13/cobra/command.go:852 +0x2fd
github.com/containers/libpod/vendor/github.com/spf13/cobra.(*Command).Execute(0x268e4c0, 0xc000056420, 0xc0000bc058)
        /home/esm/go/src/github.com/containers/libpod/vendor/github.com/spf13/cobra/command.go:800 +0x2b
main.main()
        /home/esm/go/src/github.com/containers/libpod/cmd/podman/main.go:231 +0x3c

I don't have time right now to diagnose and track down the cause, sorry. I suspect it will be much easier for you to track down than for me, anyway.

(FWIW the sdfsdf archive loads fine using the -i flag)

_loadCommand = &cobra.Command{
Use: "load [flags] [PATH]",
Short: "Load an image from docker archive",
Use: "load [flags] [*name*[:*tag*]]",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other Use lines, could you make this [NAME[:TAG]] (caps)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

)

var (
loadCommand cliconfig.LoadValues

loadDescription = "Loads the image from docker-archive stored on the local machine."
loadDescription = "Loads an image from container image archive stored on the local machine into container storage."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wording makes my brain hurt a bit. What would you think of any of these?

Loads a pre-saved image from a local file into container storage.
Loads an image from a locally stored archive (tar file) into container storage.
Loads a local archive file, containing a saved image, into container storage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIxed


if input == "" {
if terminal.IsTerminal(int(os.Stdin.Fd())) {
return errors.Errorf("can not use terminal, redirect the archive or using the --input flag required")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions:

Cannot read from terminal. Use command-line redirection or the --input flag.
Will not read from terminal. Use the --input flag, or redirect from a file/pipe.
No archive file specified; use --input to specify one.

input = "/dev/stdin"
c.Input = input

if input == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the reason I did len(input) == 0 is because of that usage three lines up. For the sake of consistency, and minimizing maintenance programmer confusion (like, someone some day wondering "why is it this way in one place and the other way in the other?"), could you consistentize those two?

Actually, I think it might be even more readable as

    if (whichever way you choose to check if string is empty) {
        if runtime.Remote {
            return errors.New()
        }
        ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually do not know why the runtime.Remote check is here. We should be able to support this on a remote system?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing check.
@baude @jwhonce WDYT?

@@ -92,7 +93,7 @@ func loadCmd(c *cliconfig.LoadValues) error {
return errors.Errorf("error copying file %v", err)
}

input = outFile.Name()
c.Input = outFile.Name()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I set input is because of the parse.ValidateFileName() below. Will "" validate? I can't test right now because I'm seeing a major crash in this form of usage and am very low on time right now (will have more time this afternoon).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed input altogether, now I just if c.Input > 0, then validate, otherwise I generate it from a stdin.

on the local machine. **podman load** reads from stdin by default or a file if the **input** flag is set.
The **quiet** flag suppresses the output when set.
**podman load** loads an image from either an **oci-archive** or **docker-archive** stored on the local machine into container storage. **podman load** reads from stdin by default or a file if the **input** option is set.
You can also specify a name for the image if the archive does not contain a named reference.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still find the name option confusing. It is always ignored AFAICT (probably because my saved archive includes a name). Would this make more sense?

If the archive does not include a name (FIXME: why would that be? Is that OCI vs Docker format?), you can specify a **name** and optional **tag**; these will be silently ignored if the archive already specifies them.

(And, in the spirit of not silently ignoring, would it be possible for the code to check for this condition, and say "I am completely ignoring the name:tag you gave me"?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this happens, and could not figure it out from the code. Who coded this up originally?

@edsantiago
Copy link
Member

Update: so the catch is here:

        // checking if loading from pipe
        if !fi.Mode().IsRegular() {

This triggers in a pipe: cat file | podman load. It does not trigger on redirection, as in podman load < existing-file.

Although I realize this can look like duplication, I humbly suggest that one reasonable fix is to un-delete lines 68-69, the ones in which I set both input and c.Input to "/dev/stdin". I did that because both variables are referenced further down in the code, and I wanted to guarantee that they had been properly initialized.

I think if you accept my suggestion about moving the remote client code into the if, we can completely eliminate the redundant input variable and make the code less fragile.

@rhatdan
Copy link
Member Author

rhatdan commented Mar 18, 2019

@edsantiago Take a look again.

Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passes everything I can try. LGTM aside from my request in the Use message; and I think @baude should confirm whether the -remote check should stay or go because it might require code changes in the client.

loadDescription = "Loads an image from a locally stored archive (tar file) into container storage."

_loadCommand = &cobra.Command{
Use: "load [flags] [*NAME*[:*TAG*]]",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you get rid of the asterisks? No other usage message includes them; that's a convention in .md files.

@edsantiago
Copy link
Member

Well, I've run into a snag but it doesn't seem to be related to your code. First: podman save IID does not seem to save a name in the archive; I don't know if that's expected or not (1.1.2 has the same behavior). Second, podman loadNAME:TAG <saved-file-by-iid does not actually do anything with NAME:TAG

$ iid=$(podman pull alpine:latest)
$ podman save $iid >| /tmp/alpine.tar
$ podman rmi -a
5cb3aa00f89934411ffba5c063a9bc98ace875d8f92e77d0029543d9f2ef4ad0
$ podman load alpine:latest </tmp/alpine.tar
Getting image source signatures
Copying blob bcf2f368fe23 [======================================] 5.5MiB / 5.5MiB
Copying config 5cb3aa00f8 [======================================] 1.5KiB / 1.5KiB
Writing manifest to image destination
Storing signatures
Loaded image(s): @5cb3aa00f89934411ffba5c063a9bc98ace875d8f92e77d0029543d9f2ef4ad0
$ podman images -a
REPOSITORY   TAG      IMAGE ID       CREATED       SIZE
<none>       <none>   5cb3aa00f899   10 days ago   5.79 MB

Again, podman 1.1.2 behaves the same way, I'm just wondering if that's the intention. The NAME:TAG argument still confuses me.

Copy link
Member

@jwhonce jwhonce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


fi, err := os.Stdin.Stat()
inFile, err := os.OpenFile("/dev/stdin", 0, 0666)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For portability, can you read from os.Stdin rather than opening /dev/stdin?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that simplifies the code. Thanks @jwhonce.
Fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 2-For!

If user does not specify file or redirect for stdin, then
throw an error

Signed-off-by: Daniel J Walsh <[email protected]>
@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: edsantiago, jwhonce, rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@edsantiago
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 18, 2019
@openshift-merge-robot openshift-merge-robot merged commit 9289ecd into containers:master Mar 18, 2019
edsantiago added a commit to edsantiago/libpod that referenced this pull request Mar 18, 2019
New:
 - podman exec
 - podman load (requires containers#2674)
 - CLI parsing (regression test for containers#2574)

Improved:
 - help: test "podman NoSuchCommand", and subcommands
 - help: test "podman cmd" without required args
 - pod: start with --infra=false; this allows running rootless
 - log: also run 'logs' after container is run
 - log: test -f with two containers

Also, use helpful descriptions for skip_if_rootless

Tested on f29, root and rootless. As soon as podman-remote
supports rm, I'll start testing that too.

Signed-off-by: Ed Santiago <[email protected]>
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 27, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants