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

Set storage size to minimum volume size #441

Merged
merged 5 commits into from
Jul 5, 2022
Merged
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("volume capabilities cannot be satisified: %s", strings.Join(violations, "; ")))
}

size, err := extractStorage(req.CapacityRange)
size, err := d.extractStorage(req.CapacityRange)
if err != nil {
return nil, status.Errorf(codes.OutOfRange, "invalid capacity range: %v", err)
}
Expand Down Expand Up @@ -873,7 +873,7 @@ func (d *Driver) ControllerExpandVolume(ctx context.Context, req *csi.Controller
return nil, status.Errorf(codes.Internal, "ControllerExpandVolume could not retrieve existing volume: %v", err)
}

resizeBytes, err := extractStorage(req.GetCapacityRange())
resizeBytes, err := d.extractStorage(req.GetCapacityRange())
if err != nil {
return nil, status.Errorf(codes.OutOfRange, "ControllerExpandVolume invalid capacity range: %v", err)
}
Expand Down Expand Up @@ -936,7 +936,7 @@ func (d *Driver) ControllerGetVolume(ctx context.Context, req *csi.ControllerGet
// range. If the capacity range is not satisfied it returns the default volume
// size. If the capacity range is below or above supported sizes, it returns an
// error.
func extractStorage(capRange *csi.CapacityRange) (int64, error) {
func (d *Driver) extractStorage(capRange *csi.CapacityRange) (int64, error) {
if capRange == nil {
return defaultVolumeSizeInBytes, nil
}
Expand All @@ -955,7 +955,11 @@ func extractStorage(capRange *csi.CapacityRange) (int64, error) {
}

if requiredSet && !limitSet && requiredBytes < minimumVolumeSizeInBytes {
return 0, fmt.Errorf("required (%v) can not be less than minimum supported volume size (%v)", formatBytes(requiredBytes), formatBytes(minimumVolumeSizeInBytes))
d.log.WithFields(logrus.Fields{
"requiredBytes": formatBytes(requiredBytes),
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind using camel case here and on the field below in order to be consistent with the existing style?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, updated.

"minimumVolumeSizeInBytes": formatBytes(minimumVolumeSizeInBytes),
}).Warn("requiredBytes is less than minimum supported volume size, setting requiredBytes default to minimumVolumeSizeBytes")
return minimumVolumeSizeInBytes, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Let's say "minimum volume size" to not give the impression that minimumVolumeSizeBytes is a known value from the CSI spec (which requiredBytes is only).

}

if limitSet && limitBytes < minimumVolumeSizeInBytes {
Expand Down