Skip to content

Conversation

@ygalblum
Copy link
Contributor

@ygalblum ygalblum commented Jan 6, 2026

Add a per-volume 'nocreate' option that prevents automatic creation of named volumes when they don't exist. When specified, Podman will fail if the volume is not found instead of creating it automatically.

Usage: -v myvolume:/data:nocreate
--mount type=volume,src=myvolume,dst=/data,nocreate

See: #27862

Checklist

Ensure you have completed the following checklist for your pull request to be reviewed:

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all
    commits. (git commit -s). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. See CONTRIBUTING.md
    for more information.
  • Referenced issues using Fixes: #00000 in commit message (if applicable)
  • Tests have been added/updated (or no tests are needed)
  • Documentation has been updated (or no documentation changes are needed)
  • All commits pass make validatepr (format/lint checks)
  • Release note entered in the section below (or None if no user-facing changes)

Does this PR introduce a user-facing change?

Add nocreate option for named volumes to instruct podman to fail when a named volume does not exist instead of creating one.

@ygalblum
Copy link
Contributor Author

ygalblum commented Jan 6, 2026

@Luap99 @mheon This comes to replace #27866 .

Let me know what you think is better

@ygalblum ygalblum added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 6, 2026
Add a per-volume 'nocreate' option that prevents automatic creation of
named volumes when they don't exist. When specified, Podman will fail
if the volume is not found instead of creating it automatically.

Usage: -v myvolume:/data:nocreate
       --mount type=volume,src=myvolume,dst=/data,nocreate

See: containers#27862
Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
@packit-as-a-service
Copy link

tmt tests failed for commit 2efb9ae. @lsm5, @psss, @thrix please check.

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, I prefer this one. One comment on the implementation code but otherwise this seem fine.

Comment on lines +137 to +150
// Extract nocreate option before validation since it's not a standard mount option
rawOpts := strings.Split(splitVol[2], ",")
filteredOpts := make([]string, 0, len(rawOpts))
for _, opt := range rawOpts {
if opt == "nocreate" {
noCreate = true
} else {
filteredOpts = append(filteredOpts, opt)
}
}
if len(filteredOpts) > 0 {
if options, err = parse.ValidateVolumeOpts(filteredOpts); err != nil {
return nil, nil, nil, err
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs to be moved into ValidateVolumeOpts it already has options there that are not real mount options anyway.

Doing parsing in several places is never good otherwise, we should filter that option out later I think for consistent, i.e.
#26945

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I chose this way was that ValidateVolumeOpts is implemented in the common repo and this option was only for Podman. So, I wasn't sure if putting a usage specific option in the common code would be a better practice. But, I guess this is not the only case. So, I'll open a PR there and update this PR once its merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added it to the valid list: containers/container-libs#585
Once merged, I will move the actual parsing into

func processOptionsInternal(options []string, isTmpfs bool, sourcePath string, getDefaultMountOptions getDefaultMountOptionsFn) ([]string, error) {

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

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants