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

Create mountpoint.Args for parsing and accessing Mountpoint args #349

Merged
merged 9 commits into from
Jan 22, 2025

Conversation

unexge
Copy link
Contributor

@unexge unexge commented Jan 20, 2025

Previously, accessing and manipulating of Mountpoint arguments was spread over to the codebase. This new mountpoint package contains all the logic related to Mountpoint arguments.

Splitted out of #328.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@unexge unexge requested a review from a team as a code owner January 20, 2025 13:42
@unexge unexge force-pushed the add-mountpoint-args-struct branch from c5af302 to 90245ac Compare January 20, 2025 13:43
}
// add the hard coded S3 CSI driver user agent string
return append(options, userAgentPrefix+"="+userAgent)
func addUserAgentToArguments(args mountpoint.Args, userAgent string) mountpoint.Args {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove this function now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed with e35a629

// Ex: --key=value, key=value
key, value = parts[0], parts[1]
} else {
// Ex: --key value, key value
Copy link
Contributor

Choose a reason for hiding this comment

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

This section doesn't make sense to me what it's meant to catch. Don't we only support one key/value pair per argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we only support one argument per line, the comments lists some example usages which would fall into the associated blocks. Here, this block is if the user provide arguments like: --key value or key value (without -- prefix) without using = between key and value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, could you make the comments '--key value, or key value'? Or some other way to make it obvious the comma isn't part of the example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed with 21a0fe0

pkg/mountpoint/args.go Show resolved Hide resolved
}

// SortedList returns ordered list of normalized arguments.
func (a *Args) SortedList() []string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Why do we need this? If it's just for equality, couldn't we return a set? (Presumably this isn't called enough to care about time complexity though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used while passing these arguments to Mountpoint via systemd or via exec.Command and also in tests as you mentioned

// find tries to find given key from [Args], and returns whole entry, and whether the key was found.
func (a *Args) find(key ArgKey) (Arg, bool) {
key = normalizeKey(key)
for _, arg := range a.args.UnsortedList() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remind me again why we can't use a hashmap here and avoid doing this iteration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to support multi arguments with the same key. I think iteration wouldn't matter here much as we'd be dealing with a dozen arguments at max, but also not sure if we have a multi argument use-case with Mountpoint currently. It was just to create an ideal argument parser, might not be needed with Mountpoint args.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is for multi-arguments, then this find will only find the first occurrence, which doesn't feel right. I'm happy to approve though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's correct, I renamed Insert method to Set which should make it clear for now I think. If we need to support multi arguments we'd also add Insert and revisit the semantics I guess.

name: "with multiple spaces",
input: []string{
"--allow-other",
"--uid 1000",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably test spaces after as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed with 41c1418

@unexge
Copy link
Contributor Author

unexge commented Jan 21, 2025

Also added a new commit, Use mountpoint.Args in CredentialProvider, the whole CredentialProvider was split into smaller parts in the original PR, but since this is a standalone PR, I also updated usages in CredentialProvider as well.

@unexge unexge deployed to approval-gate January 21, 2025 13:55 — with GitHub Actions Active
// find tries to find given key from [Args], and returns whole entry, and whether the key was found.
func (a *Args) find(key ArgKey) (Arg, bool) {
key = normalizeKey(key)
for _, arg := range a.args.UnsortedList() {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is for multi-arguments, then this find will only find the first occurrence, which doesn't feel right. I'm happy to approve though

@unexge unexge deployed to untrusted January 22, 2025 14:49 — with GitHub Actions Active
@unexge unexge added this pull request to the merge queue Jan 22, 2025
Merged via the queue into awslabs:main with commit ef1c705 Jan 22, 2025
23 checks passed
@unexge unexge deleted the add-mountpoint-args-struct branch January 22, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants