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

Feature/#21256 extend cidfile support #25512

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

findesgh
Copy link

@findesgh findesgh commented Mar 9, 2025

This PR adds support for the --cidfile-flag to podman exec. See also #21256.

Does this PR introduce a user-facing change?

Yes:

- `podman exec` now supports `--cidfile`
- `podman rm --help` referred to `imageID` in one example, this has been fixed to be `ctrID`

Signed-off-by: Martin Glatzle <[email protected]>
Copy link
Contributor

openshift-ci bot commented Mar 9, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: findesgh
Once this PR has been reviewed and has the lgtm label, please assign ygalblum for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@findesgh findesgh marked this pull request as draft March 9, 2025 20:26
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 9, 2025
@findesgh findesgh force-pushed the feature/#21256-extend-cidfile-support branch 4 times, most recently from 7fc85ff to 31cd56e Compare March 10, 2025 20:29
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Also please squash commits 2 and 3

@@ -24,7 +24,7 @@ var (
execDescription = `Execute the specified command inside a running container.
`
execCommand = &cobra.Command{
Use: "exec [options] CONTAINER COMMAND [ARG...]",
Use: "exec [options] [CONTAINER] COMMAND [ARG...]",
Copy link
Member

Choose a reason for hiding this comment

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

This breaks the cli help test, I suggest you do not change it.
Neither is right since it is not really optional on its own, only when --latest or --cidfile is given then no container name is set. Since we have no way to show that here easily I suggest you just leave it as.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, you're right. Leaving it as is is also in line with other commands that accept --cidfile. Will change this back also in the docs.

@@ -97,6 +102,7 @@ func execFlags(cmd *cobra.Command) {

if registry.IsRemote() {
_ = flags.MarkHidden("preserve-fds")
_ = flags.MarkHidden("cidfile")
Copy link
Member

Choose a reason for hiding this comment

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

That is not true, none of the other commands seem to have this limit, the file is read on the client so this works fine.

Copy link
Author

Choose a reason for hiding this comment

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

I have to admit that I don't understand why, but it seems to me that pause, restart, unpause and stop do this as well. rm and kill, on the other hand, don't.
I would tend to agree with you that there is no reason to hide the cidfile flag, but I wanted to err on the side of caution.

Copy link
Author

Choose a reason for hiding this comment

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

The behaviour should probably be consistent across all commands that accept the cidfile flag?

var command []string

if len(args) == 0 && !latestSpecified && !execCidFileProvided {
return "", []string{}, errors.New("exec requires the name or ID of a container or the --latest or --cidfile flag")
Copy link
Member

Choose a reason for hiding this comment

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

you can just return nil instead if []string{} which needs an extra allocation for no reason.
same in the error branches below.

Copy link
Author

Choose a reason for hiding this comment

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

🙈 good catch.

@findesgh
Copy link
Author

Thanks for the PR. Also please squash commits 2 and 3

Thanks for the feedback, will squash.

@findesgh findesgh force-pushed the feature/#21256-extend-cidfile-support branch from 31cd56e to b6ca843 Compare March 11, 2025 19:48
@findesgh
Copy link
Author

One more thing: exec seems to be the first command that takes only a single container to receive --cidfile-support. All the others so far can work on multiple containers. When one specifies --cidfile more than once, the behaviour for exec as of now is to just take the last one. The same is true, e.g., of run and --name so I presume this is OK?

@findesgh findesgh requested a review from Luap99 March 11, 2025 19:56
@findesgh findesgh marked this pull request as ready for review March 11, 2025 19:56
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 11, 2025
Fixes: containers#21256

Signed-off-by: Martin Glatzle <[email protected]>
@findesgh findesgh force-pushed the feature/#21256-extend-cidfile-support branch from b6ca843 to 027fecb Compare March 11, 2025 20:09
command = args[1:]
nameOrID = strings.TrimPrefix(args[0], "/")
} else {
content, err := os.ReadFile(execCidFile)
Copy link
Member

Choose a reason for hiding this comment

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

Did I miss checks to make sure the file provided is secure? I would expect an absPath kind of check at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants