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

Quadlet container mount - support non key=val options #20149

Merged

Conversation

ygalblum
Copy link
Contributor

@ygalblum ygalblum commented Sep 26, 2023

Some keys, e.g. ro do not have values.
The current implementation crashed looking for the = sign

Externalize findMountType in a new package
Parse mount command using FindMountType
Add test case and adjust the test framework

Does this PR introduce a user-facing change?

Yes

Quadlet container mount - support non key=val options

Resolves: #20104

@openshift-ci openshift-ci bot added release-note approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 26, 2023
@ygalblum
Copy link
Contributor Author

Sorry for opening another PR for this issue while #20108 and #20112 are open. I wasn't sure if I can push to these branches.
This change addresses the example issue in #20104 and as raised by @Luap99 here

@ygalblum
Copy link
Contributor Author

ygalblum commented Sep 26, 2023

@vrothberg @rhatdan @Luap99 @giuseppe PTAL

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

I think that the underlying problem of having two separate functions to parse essentially the same thing remains. That implies a risk of code divergence and subtle errors.

Did you consider recycling the Podman-internal function to parse mounts and change it in a way that we can re-use it in Quadlet?

@ygalblum
Copy link
Contributor Author

I think that the underlying problem of having two separate functions to parse essentially the same thing remains. That implies a risk of code divergence and subtle errors.

Did you consider recycling the Podman-internal function to parse mounts and change it in a way that we can re-use it in Quadlet?

My idea was to limit the parsing to only what Quadlet really needs and that is resolving the .volume case. Unlike the original implementation all the rest is not looked or changed. As such the assumptions are only that:

  1. The parameter separator it ,
  2. type, source and src are in the key=value format

I think that reusing the Podman parser code might raise other issues. For example, Quadlet is not supposed to do any validity checks. But, now, it will.

@Luap99
Copy link
Member

Luap99 commented Sep 26, 2023

I think that the underlying problem of having two separate functions to parse essentially the same thing remains. That implies a risk of code divergence and subtle errors.

Did you consider recycling the Podman-internal function to parse mounts and change it in a way that we can re-use it in Quadlet?

Exactly, --mount flag uses csv not split at comma, this behaves differently for special chars so it is important to use the same code. And for the future someone might change the --mount parsing and then will not update quadlet so it will diverge again. The only way to address this is to directly share the code.

@vrothberg
Copy link
Member

I think that reusing the Podman parser code might raise other issues. For example, Quadlet is not supposed to do any validity checks. But, now, it will.

That's a fair argument. I think we mostly avoid validation to avoid code duplication/divergence. But if we manage to share the same function we could do it.

But I guess it would at some dependencies to Quadlet (likely runtime spec).

@Luap99
Copy link
Member

Luap99 commented Sep 26, 2023

you can just use

func findMountType(input string) (mountType string, tokens []string, err error) {

That should already work for both use cases podman and quadlet. Simply move this function to a new package without all the extra imports as that would bloat quadlet otherwise.

@ygalblum ygalblum force-pushed the quadlet-container-mount branch from f07a6b6 to 3daf8c1 Compare September 27, 2023 06:36
@ygalblum
Copy link
Contributor Author

@vrothberg @Luap99 Done. PTAL

Comment on lines 1550 to 1551
tokens = append([]string{fmt.Sprintf("type=%s", mountType)}, tokens...)
return strings.Join(tokens, ","), nil
Copy link
Member

Choose a reason for hiding this comment

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

This will still fail when the value contains special chars, you must again encode this via the csv lib in order to encode this back into the right format. Consider a a filepath with comma:
--mount=type=bind,src=/tmp,"dst=/path,1"

Copy link
Member

Choose a reason for hiding this comment

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

Great catch. Once fixed, can we also add a test case for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding the test case is the first step in writing the fix :)

Copy link
Member

Choose a reason for hiding this comment

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

Like Batman, you are not the maintainer we deserve but the one we need :^)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Wow, making the test work was more complicated than the code fix :)

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

LGTM

@ygalblum ygalblum force-pushed the quadlet-container-mount branch 3 times, most recently from 804854d to b6fc0cf Compare September 27, 2023 13:19
Some keys, e.g. ro do not have values.
The current implementation crashed looking for the = sign

Externalize findMountType in a new package
Parse mount command using FindMountType
Rebuild parameter string using csv

Add test case and adjust the test framework

Signed-off-by: Ygal Blum <[email protected]>
@ygalblum
Copy link
Contributor Author

Does this failure block the merge: bin/quadlet grew by 53951 bytes; max allowed is 51200.?

@Luap99
Copy link
Member

Luap99 commented Sep 27, 2023

Does this failure block the merge: bin/quadlet grew by 53951 bytes; max allowed is 51200.?

Yes but we can overwrite with the label, given this is so close I am good with it. You already split out the function to not require unnecessary imports so I assume this is the best we can do and the grow is mostly caused by the CSV parser.

@Luap99 Luap99 added the bloat_approved Approve a PR in which binary file size grows by over 50k label Sep 27, 2023
@TomSweeneyRedHat
Copy link
Member

LGTM

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @ygalblum !
I let @Luap99 have a final head nod

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 28, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vrothberg, ygalblum

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

@Luap99
Copy link
Member

Luap99 commented Sep 28, 2023

/lgtm

Thanks

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 28, 2023
@openshift-merge-robot openshift-merge-robot merged commit c9730e2 into containers:main Sep 28, 2023
97 checks passed
@ygalblum ygalblum deleted the quadlet-container-mount branch September 28, 2023 10:54
@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 Dec 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 28, 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. bloat_approved Approve a PR in which binary file size grows by over 50k 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.

Quadlet: Invalid Mount directive leads to core dump
5 participants