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

Add --preservefds to podman run #6625

Merged
merged 1 commit into from
Jun 23, 2020
Merged

Conversation

QiWang19
Copy link
Contributor

Add --preservefds to podman run. close #6458

Signed-off-by: Qi Wang [email protected]

@rhatdan
Copy link
Member

rhatdan commented Jun 16, 2020

LGTM
/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: QiWang19, 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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 16, 2020
@edsantiago
Copy link
Member

Please add a system test, possibly in test/system/030-run.bats, using something like what I messaged you earlier today. The e2e test here is not very useful: all it does is confirm that the option does not cause a syntax error. It does not test any actual functionality.

@@ -61,10 +61,12 @@ func runFlags(flags *pflag.FlagSet) {
flags.SetNormalizeFunc(common.AliasFlags)
flags.BoolVar(&runOpts.SigProxy, "sig-proxy", true, "Proxy received signals to the process")
flags.BoolVar(&runRmi, "rmi", false, "Remove container image unless used by other containers")
flags.UintVar(&runOpts.PreserveFDs, "preserve-fds", 0, "Pass N additional file descriptors to the container")
Copy link
Member

Choose a reason for hiding this comment

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

Recommend rewording to "Pass a number of additional file descriptors into the container"

// PreserveFDs is a number of additional file descriptors (in addition
// to 0, 1, 2) that will be passed to the executed process. The total FDs
// passed will be 3 + PreserveFDs.
PreserveFDs uint `json:"-"`
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment that this is not in the JSON because it is not supported for remote connections?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, wait, nevermind - this needs to actually have a JSON tag here, not "-" - that should only be in Specgen. This is for the DB, and we do want to save this to the container in the DB.

@@ -1369,6 +1369,17 @@ func WithHealthCheck(healthCheck *manifest.Schema2HealthConfig) CtrCreateOption
}
}

// WithPreserveFDs adds the file descriptors to the container config
Copy link
Member

Choose a reason for hiding this comment

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

Suggest "WithPreserveFDs forwards from the process running Libpod into the container the given number of extra FDs (starting after the standard streams) to the created container"

@QiWang19 QiWang19 force-pushed the fd branch 3 times, most recently from dcfb003 to 738c4d6 Compare June 17, 2020 19:08
@QiWang19
Copy link
Contributor Author

Please add a system test, possibly in test/system/030-run.bats, using something like what I messaged you earlier today. The e2e test here is not very useful: all it does is confirm that the option does not cause a syntax error. It does not test any actual functionality.

https://github.com/containers/libpod/pull/6625/files#diff-f1c2f651579cf49df98160fa0e2d50a7 test failed. @edsantiago Can you help me diagnose if it's because the test not correct? Otherwise, my implementation may not as expected.

@edsantiago
Copy link
Member

@QiWang19 this is what the test should look like:

@test "podman run --preserve-fds" {
    skip_if_remote

    content=$(random_string 20)
    echo "$content" > $PODMAN_TMPDIR/tempfile

    run_podman run --rm -i --preserve-fds=2 $IMAGE sh -c "cat <&4" 4<$PODMAN_TMPDIR/tempfile
    is "$output" "$content" "container read input from fd 4"
}

Please use that. It still fails, but it does so for a real-problem reason which is being tracked in #6653

 2020/06/17 15:51:44 bolt.Close(): funlock error: bad file descriptor
time="2020-06-17T15:51:44-06:00" level=error msg="failed to close libpod db: \"db file close: close /var/lib/containers/storage/libpod/bolt_state.db: bad file descriptor\""
Error: error saving container 26cd8352b73d3c07b46343c63f3b3b5c00e37f28ed685ace08788745025a0704 state: write /var/lib/containers/storage/libpod/bolt_state.db: bad file descriptor

Please coordinate efforts to resolve that issue.

Explanation of what I changed:

  • use FD 4, not 3: I forgot that BATS uses fd 3 for internal purposes.
  • Remove the NONLOCAL_IMAGE stuff. You copy-pasted that from another test. It is not necessary or desired here (it introduces a point of failure because it relies on remote registry)
  • use random content, not hardcoded strings which could easily appear via other ways
  • use a file in $PODMAN_TMPDIR - otherwise "testfile" will pollute your current working directory
  • use --rm in the run command, to avoid having to clean up

@QiWang19
Copy link
Contributor Author

@edsantiago Thanks!

@QiWang19 QiWang19 force-pushed the fd branch 2 times, most recently from 2bf6ac5 to df221d5 Compare June 18, 2020 17:38
@edsantiago
Copy link
Member

@QiWang19 it looks like #6653 might not get attention soon. Since I believe your PR is correct, and the real problem is elsewhere, I'd be OK with you adding skip "enable this once #6653 is fixed" to the BATS test and trying to get your PR committed.

Add --preservefds to podman run. close containers#6458

Signed-off-by: Qi Wang <[email protected]>
@mheon
Copy link
Member

mheon commented Jun 19, 2020

Hold this until Monday, 2.0 is feature-frozen

@rhatdan
Copy link
Member

rhatdan commented Jun 22, 2020

@mheon Are you ok to merge this now?

@mheon
Copy link
Member

mheon commented Jun 22, 2020

LGTM, but would like final signoff from @giuseppe

@QiWang19
Copy link
Contributor Author

Thanks.
@giuseppe PTAL.

@giuseppe
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 23, 2020
@openshift-merge-robot openshift-merge-robot merged commit 9e37fd4 into containers:master Jun 23, 2020
@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 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 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.

Add support for --preserve-fds to podman run
7 participants