-
Notifications
You must be signed in to change notification settings - Fork 41.4k
move filesystem resize code to kubernetes/mount-utils and add need re… #99223
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
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions 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/test-infra repository. I understand the commands that are listed here. |
Welcome @AndyXiangLi! |
Hi @AndyXiangLi. 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 Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions 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/test-infra repository. |
75130ae
to
ac62aca
Compare
/approve |
/assign @gnufied |
/ok-to-test |
/triage accepted |
blockCount: 0, | ||
cmdOutput: cmdOutputNoDataExt4, | ||
expectError: true, | ||
fsType: "ext4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please add a test with unknown FS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
continue | ||
} | ||
key, value := strings.TrimSpace(tokens[0]), strings.TrimSpace(tokens[1]) | ||
if key == "Block count" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we downcase before comparing them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
lines := strings.Split(string(output), "\n") | ||
var blockSize, blockCount uint64 | ||
|
||
for _, line := range lines { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @sandeen for xfs_info parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just use statfs to get the size of /any/ filesystem, instead of hard-coding and scraping individual filesystem utilities? statfs is the generic interface to query the kernel about the size of a mounted filesystem.
See statfs(2) and the -f option in statfs(1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, well, this doesn't count the log blocks I guess. Not sure what your threshold for "should try to grow" is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even just:
df -B1 --output=size /boot
1B-blocks
1063256064
and again this ignores space consumed by journals or other internal fs housekeeping, but it may be better to use standard APIs like statfs(2) (which is how df gets its information)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sandeen, I may miss something here, but IMO statfs
shows size of the filesystem available for actual files (i.e. without journal and other FS metadata), while xfs_info shows the actual size occupied by the filesystem on a device, incl. journal, inodes, and whatnot.
We need to reliably check if we should call resize2fs
/ xfs_growfs
, i.e. there is some extra space on the device that the filesystem does not know about.
$ df --output=size /boot
1K-blocks
999320
$ dumpe2fs /dev/nvme0n1p2
Block count: 262144
Block size: 4096
999320 * 1024 = 1023303680
262144 * 4096 = 1073741824
That's quite a difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just try a growfs after each initial mount, which is going to be quick and harmless if the filesystem is already maximally sized.
How safe is this for xfs and ext3/ext4? Since we will do it with every mount() and containers can move around the cluster rather quickly, we need it to be fast enough (say same as mount()?) and reliable (won't ever harm the FS, even when it gets SIGINT).
What is your typical image size, roughly?
It starts with 1 GB and goes to hundreds of GB. But I am not sure it's relevant. If user extends the volume by 1% (which can be say 1GB), we'd like the volume to be be expanded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's chat on IRC when you get a chance, higher bandwidth than github comments might help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
summary of conversation on IRC, here are the options:
<sandeen> 1) use df, and accept a small % error
<sandeen> 2) scrape filesystem utilities and hope they don't change
<sandeen> 3) always call resize, which would be a no-op if already maximally sized
<sandeen> 4) use filesystem-specific but more well-defined APIs where they exist
<sandeen> ...
<sandeen> 5) wait for a common kernel solution :(
We'd prefer 4) if available and for xfs we were able to find xfs_io -c statfs <mount>
, which is much easier to parse. In addition, it uses ioctl
to get the geometry. @AndyXiangLi can you try ioctl
with some interface to make unit testing possible?
There is no ioctl for ext3/4, so 2) is IMO the best option and luckily dumpe2fs
is not that horrible to parse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correction: is go & ioctl
portable to ARM / PPC / s390x and other weird architectures that Kubernetes supports? If not, do not hesitate to fall back to parsing xfs_io -c statfs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you parse the xfs_io output, the field you want is "geom.datablocks" to get the actual, complete number of all blocks on the filesytem's data device. Note that this is only available when running the xfs_io "statfs" command on an xfs filesystem, non-xfs filesystems will only return the basic statfs(2) information, same as df.
1f09c4c
to
89d12eb
Compare
/test pull-kubernetes-e2e-kind |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After talking w/ @gnufied I'm realizing that I may not understand the use case / workflow here.
I /can/ help with any questions about xfs_info parsing, but it concerns me that this may not be the optimal approach here.
not used to github review flow so not sure if I created something blocking here, I'll just, er, submit it now.
lines := strings.Split(string(output), "\n") | ||
var blockSize, blockCount uint64 | ||
|
||
for _, line := range lines { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just use statfs to get the size of /any/ filesystem, instead of hard-coding and scraping individual filesystem utilities? statfs is the generic interface to query the kernel about the size of a mounted filesystem.
See statfs(2) and the -f option in statfs(1)
lines := strings.Split(string(output), "\n") | ||
var blockSize, blockCount uint64 | ||
|
||
for _, line := range lines { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, well, this doesn't count the log blocks I guess. Not sure what your threshold for "should try to grow" is.
lines := strings.Split(string(output), "\n") | ||
var blockSize, blockCount uint64 | ||
|
||
for _, line := range lines { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even just:
df -B1 --output=size /boot
1B-blocks
1063256064
and again this ignores space consumed by journals or other internal fs housekeeping, but it may be better to use standard APIs like statfs(2) (which is how df gets its information)
4a1ab84
to
42cee7e
Compare
42cee7e
to
d0c2b8f
Compare
/test pull-kubernetes-e2e-kind-ipv6 |
@jsafrane Any updates? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one small nit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why empty comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for review! This is updated
d0c2b8f
to
03106a1
Compare
/test pull-kubernetes-e2e-kind |
/lgtm |
/test pull-kubernetes-integration |
/test pull-kubernetes-e2e-kind-ipv6 |
…#99223-upstream-release-1.21 Automated cherry pick of #99223: move filesystem resize code to kubernetes/mount-utils and add
What type of PR is this?
/kind cleanup
/kind feature
What this PR does / why we need it:
Move filesystem resize code to kubernetes/mount-utils so that it can be shared among with CSI drivers.
Add NeedResize function in ResizeFS
Which issue(s) this PR fixes:
Fixes #94929
Still need effort on the plugin side
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: