Skip to content

Conversation

@mheon
Copy link
Member

@mheon mheon commented Nov 11, 2024

All the backend work was done a while back for image volumes, so this is effectively just plumbing the option in for volumes in the parser logic. It's a little uglier than I'd like because our volume mount parser produces an OCI Spec mount struct, which doesn't have a field for subpath, so we have to pass through the options array and parse it back out after, which is a little gross. But not gross enough to rewrite that parsing logic.

Fixes #20661

Does this PR introduce a user-facing change?

The `--mount type=volume` option to `podman run`, `podman create`, and `podman volume create` now supports a new option, `subpath=`, to make only a subset of the volume visible in the container ([#20661](https://github.com/containers/podman/issues/20661)). 

@openshift-ci openshift-ci bot added release-note approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 11, 2024
@mheon mheon force-pushed the subpath branch 2 times, most recently from f7bdadf to 61e5275 Compare November 11, 2024 20:40
Comment on lines 591 to 602
safeOpts := make([]string, 0, len(mnt.Options))
for _, opt := range mnt.Options {
splitOpt := strings.SplitN(opt, "=", 2)
if splitOpt[0] == "subpath" {
if len(splitOpt) != 2 {
return nil, fmt.Errorf("subpath was not provided a path")
}
newVolume.SubPath = splitOpt[1]
} else {
safeOpts = append(safeOpts, opt)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Please not another "random" place to parse options. Can't we just fix parseMountOptions() to return a suitable type? We already have to many different places where we pass mount options

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

)

type universalMount struct {
mount spec.Mount
Copy link
Member

Choose a reason for hiding this comment

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

if we embed the struct we would not need to add the extra .mount everywhere

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'd prefer it that way if we could just cast the universalMount to a spec.Mount after, but we can't. So it saves us a few changes in parseMountOptions but hurts more than helps in the callers.

Copy link
Member

Choose a reason for hiding this comment

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

ok fair enough

All the backend work was done a while back for image volumes, so
this is effectively just plumbing the option in for volumes in
the parser logic. We do need to change the return type of the
volume parser as it only worked on spec.Mount before (which does
not have subpath support, so we'd have to pass it as an option
and parse it again) but that is cleaner than the alternative.

Fixes containers#20661

Signed-off-by: Matt Heon <mheon@redhat.com>
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.

LGTM

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99, mheon

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

@baude
Copy link
Member

baude commented Nov 12, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 12, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 8f2d501 into containers:main Nov 12, 2024
77 checks passed
@cyqsimon
Copy link

Can we expect this in the next minor version?

@mheon
Copy link
Member Author

mheon commented Dec 13, 2024

Yes. Per our release schedule that is 5.4 in February.

@stale-locking-app stale-locking-app bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label May 10, 2025
@stale-locking-app stale-locking-app bot locked as resolved and limited conversation to collaborators May 10, 2025
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. release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support subpath paths for -v or --mount

4 participants