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

controller get capacity method added #483

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 21 additions & 5 deletions driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,28 @@ func (d *Driver) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (

// GetCapacity returns the capacity of the storage pool
func (d *Driver) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) {
// TODO(arslan): check if we can provide this information somehow
volumes, _, err := d.storage.ListVolumes(ctx, &godo.ListVolumeParams{})
if err != nil {
return nil, err
}

totalCapacity := int64(0)
for _, volume := range volumes {
if volume.Region.Slug == d.region {
totalCapacity += int64(volume.SizeGigaBytes) * 1024 * 1024 * 1024
}
}

// Create a new response object
resp := &csi.GetCapacityResponse{
AvailableCapacity: totalCapacity,
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIU the spec for GetCapacity, the availability capacity is not how much storage capacity is currently in use but how much capacity is available to the user.

I believe this is essentially the volume limit (which we still reference to some extent in the checkLimit method that is otherwise unused and was missed for removal in #481) minus the currently used capacity.

Copy link
Author

@basit9958 basit9958 Apr 13, 2023

Choose a reason for hiding this comment

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

Yes you are correct, we can use limitdetails.limit and minus it with used capacity. Used capacity can be calculated by checking volumes whose droplet id are not nil and adding their size.

}
d.log.WithFields(logrus.Fields{
"params": req.Parameters,
"method": "get_capacity",
}).Warn("get capacity is not implemented")
return nil, status.Error(codes.Unimplemented, "")
"response": resp,
"method": "controller_get_capacity",
}).Info("controller get capacity called")
return resp, nil

}

// ControllerGetCapabilities returns the capabilities of the controller service.
Expand Down