-
Notifications
You must be signed in to change notification settings - Fork 237
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
feat: organize node expand logics #1008
Merged
mowangdk
merged 2 commits into
kubernetes-sigs:master
from
mowangdk:feature/check_resize_disk_size
Mar 29, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |
"crypto/sha256" | ||
"errors" | ||
"fmt" | ||
"math" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
@@ -888,8 +889,8 @@ func (ns *nodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV | |
*csi.NodeExpandVolumeResponse, error) { | ||
log.Infof("NodeExpandVolume: node expand volume: %v", req) | ||
|
||
volExpandBytes := int64(req.GetCapacityRange().GetRequiredBytes()) | ||
requestGB := float64((volExpandBytes + 1024*1024*1024 - 1) / (1024 * 1024 * 1024)) | ||
volExpandBytes := float64(req.GetCapacityRange().GetRequiredBytes()) | ||
requestGB := math.Floor(volExpandBytes / float64(1024*1024*1024)) | ||
|
||
volumePath := req.GetVolumePath() | ||
diskID := req.GetVolumeId() | ||
|
@@ -993,14 +994,14 @@ func (ns *nodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV | |
return nil, status.Error(codes.Internal, err.Error()) | ||
} | ||
deviceCapacity := getBlockDeviceCapacity(devicePath) | ||
if deviceCapacity < requestGB { | ||
// After calling openapi to expansion cloud disk, the size of the underlying block device may not change. need to retry | ||
log.Errorf("NodeExpandVolume:: Actual block size: %v is smaller than expected block size: %v, need to retry waiting", deviceCapacity, requestGB) | ||
return nil, status.Errorf(codes.Aborted, "deviceCapacity: %v, requestGB: %v not in range", deviceCapacity, requestGB) | ||
} | ||
log.Infof( | ||
"NodeExpandVolume:: filesystem resize context device capacity: %v, before resize fs capacity: %v resize fs capacity: %v, requestGB: %v. file system lose percent: %v", | ||
deviceCapacity, beforeResizeDiskCapacity, diskCapacity, requestGB, GlobalConfigVar.FilesystemLosePercent) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove all codes about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I don't think It serves its purpose. |
||
if diskCapacity >= requestGB*GlobalConfigVar.FilesystemLosePercent { | ||
// delete autoSnapshot | ||
log.Infof("NodeExpandVolume:: resizefs successful volumeId: %s, devicePath: %s, volumePath: %s", diskID, devicePath, volumePath) | ||
return &csi.NodeExpandVolumeResponse{}, nil | ||
} | ||
return nil, status.Errorf(codes.Internal, "requestGB: %v, diskCapacity: %v not in range", requestGB, diskCapacity) | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do all calculation with int64 and bytes? to avoid any potential issue with floating point precision lost. Just be consistent with
ControllerExpandVolume
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.
volExpandBytes variable here is only use to generate requestGB, I think it would be fine.