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

feat: organize node expand logics #1008

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions pkg/disk/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"crypto/sha256"
"errors"
"fmt"
"math"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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))
Copy link
Contributor

@huww98 huww98 Mar 28, 2024

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

Copy link
Contributor Author

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.


volumePath := req.GetVolumePath()
diskID := req.GetVolumeId()
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove all codes about FilesystemLosePercent?

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, 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)
}

Expand Down