[cinder-csi-plugin] Add mkfs-options StorageClass parameter#3084
[cinder-csi-plugin] Add mkfs-options StorageClass parameter#3084rybnico wants to merge 1 commit into
Conversation
|
|
|
Hi @rybnico. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
5c03378 to
d7fa2d8
Compare
|
/ok-to-test |
|
reading the https://github.com/kubernetes/utils/blob/28399d86e0b55e612b83ad94dc6bac8e5de2a5ac/mount/mount_linux.go#L396 source code it seems that this is not a |
d7fa2d8 to
715349b
Compare
No, it's an option for |
could you point me to the code that passes |
Of course - but we don't pass them as argument We create In In mount-utils, the options is finally passed to formatAndMountSensitive and added to the |
| // parseMkfsOptions splits a comma-separated mkfsOptions string into individual | ||
| // command-line arguments. Each comma-separated token is further split on | ||
| // whitespace. Empty tokens are filtered out. | ||
| func parseMkfsOptions(mkfsOpts string) []string { |
There was a problem hiding this comment.
you can use
cloud-provider-openstack/pkg/util/util.go
Lines 175 to 182 in 9c80105
There was a problem hiding this comment.
Good catch! I removed the parseMkfsOptions function and use SplitTrim instead.
| |------------------------- |-----------------------|-----------------|-----------------| | ||
| | StorageClass `parameters` | `availability` | `nova` | String. Volume Availability Zone | | ||
| | StorageClass `parameters` | `type` | Empty String | String. Name/ID of Volume type. Corresponding volume type should exist in cinder | | ||
| | StorageClass `parameters` | `mkfsOptions` | Empty String | String. Comma-separated mkfs options passed to mkfs when formatting the volume. Useful for passing `-E nodiscard` on Ceph-backed storage to speed up provisioning. | |
There was a problem hiding this comment.
it makes sense to use kebab-case style here
There was a problem hiding this comment.
Yes, you're right. It isn't consistent across CSI implementations. However, looking at the other parameters in Cinder CSI, kebab-style is a better fit.
I also removed the overly specific comment about Ceph/nodiscard.
715349b to
cbc2205
Compare
can you fix formatting? and rename the PR title |
cbc2205 to
5b221ba
Compare
I fixed it. I don't know why it didn't get caught locally. I also changed the PR title. |
| }, | ||
| }, | ||
| Parameters: map[string]string{ | ||
| "mkfs-options": "-E nodiscard", |
There was a problem hiding this comment.
I think it also makes sense to add tests for multiple format options, separated with comma.
There was a problem hiding this comment.
This was a very good suggestion because it made me aware of a bug that occurred when using multiple arguments. Since it doesn't make sense to split the arguments by comma, I now use the strings.Fields function to split them by space.
I added tests for different/multiple arguments in mkfs-options and I made mocking commands in pkg/util/mount/mount_mock.go possible to check if the correct arguments are used in the mkfs call.
I appreciate your thorough review!
There was a problem hiding this comment.
hm. it seems we need something smarter to avoid cases like this: https://go.dev/play/p/fp3YAphLD8m
Fields are: ["-L" "\"my" "data" "disk\"" "/dev/sdb1"]
There was a problem hiding this comment.
There was a problem hiding this comment.
I noticed that, too. However, I was hesitant to add a dependency on shlex.
As far as I know, the label argument is the only one that takes a quoted string as a parameter. And the label argument doesn't make sense in our context anyway.
If you'd like, though, I can improve the parsing. Would you prefer to use shlex or copy kustomization's shlex implementation?
Another option is to keep it as it is and add a note to the documentation stating that quoted strings are not supported.
What do you prefer?
There was a problem hiding this comment.
@kayrus Could you take another look and let me know how we should proceed? Thanks in advance!
There was a problem hiding this comment.
@zetaab @stephenfin can you take a look at this PR?
There was a problem hiding this comment.
@kayrus @zetaab @stephenfin Would you mind having another look and telling me if the argument parsing needs additional work for this PR to get merged? Thanks!
There was a problem hiding this comment.
I was just thinking could it work in similar way than pod command in kubernetes ([]string)? By that way people could easily understand the syntax if its more complex than just this in test.
There was a problem hiding this comment.
First, thanks for your review!
Using a string array for the options would be great, but the parameters field in the StorageClass is of type map[string]string.
Add support for a new `mkfs-options` StorageClass parameter that allows cluster admins to pass custom mkfs flags when formatting volumes. For example, this is useful for Ceph-backed storage where passing `-E nodiscard` to mkfs.ext4 can dramatically speed up provisioning. Implementation: - Extract mkfs-options from StorageClass params in CreateVolume and pass via VolumeContext (both new-volume and idempotent early-return paths) - Parse mkfs-options in NodeStageVolume - Use FormatAndMountSensitiveWithFormatOptions() from k8s.io/mount-utils to pass format options separately from mount options - No behavior change when mkfs-options is not set Inspired by the Ceph CSI implementation (ceph/ceph-csi#621). MountMock.Mounter() now returns a stable, memoized SafeFormatAndMount with a SetMounter escape hatch, enabling tests to script and capture the mkfs argv via FakeExec.
5b221ba to
e6271a0
Compare

What this PR does / why we need it:
Add support for a new
mkfsOptionsStorageClass parameter that allows cluster admins to pass custom mkfs flags when formatting volumes. This is particularly useful for Ceph-backed storage where passing-E nodiscardto mkfs.ext4 can dramatically speed up provisioning (e.g. from ~7 minutes to seconds for a 100 GB volume).The parameter value is comma-separated, with each token further split on whitespace to produce individual mkfs command-line arguments. Example:
mkfsOptions: "-E nodiscard,-O ^metadata_csum"Implementation:
Which issue this PR fixes(if applicable):
fixes #3068
Special notes for reviewers:
Inspired by the Ceph CSI implementation (ceph/ceph-csi#621).
Release note: