-
Notifications
You must be signed in to change notification settings - Fork 108
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
driver: check volume limit #73
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,11 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) | |
return nil, status.Error(codes.AlreadyExists, "invalid volume capabilities requested. Only SINGLE_NODE_WRITER is supported ('accessModes.ReadWriteOnce' on Kubernetes)") | ||
} | ||
|
||
ll.Info("checking volume limit") | ||
if err := d.checkLimit(ctx); err != nil { | ||
return nil, err | ||
} | ||
|
||
ll.WithField("volume_req", volumeReq).Info("creating volume") | ||
vol, _, err := d.doClient.Storage.CreateVolume(ctx, volumeReq) | ||
if err != nil { | ||
|
@@ -623,6 +628,40 @@ func (d *Driver) waitAction(ctx context.Context, volumeId string, actionId int) | |
} | ||
} | ||
|
||
// checkLimit checks whether the user hit their volume limit to ensure. | ||
func (d *Driver) checkLimit(ctx context.Context) error { | ||
// only one provisioner runs, we can make sure to prevent burst creation | ||
d.readyMu.Lock() | ||
defer d.readyMu.Unlock() | ||
|
||
account, _, err := d.doClient.Account.Get(ctx) | ||
if err != nil { | ||
return status.Errorf(codes.Internal, | ||
"couldn't get account information to check volume limit: %s", err.Error()) | ||
} | ||
|
||
// administrative accounts might have zero length limits, make sure to not check them | ||
if account.VolumeLimit == 0 { | ||
return nil // hail to the king! | ||
} | ||
|
||
volumes, _, err := d.doClient.Storage.ListVolumes(ctx, &godo.ListVolumeParams{ | ||
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. 🎗 this is listing volumes by region but the received limit is for all regions. the proper fix is for us ( DigitalOcean ) to expose limits per region. it is in the works but no ETA. 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. Thanks Lucas, good to know. I added a note to the source code so it's aware to the reader as well: 445ec7a |
||
Region: d.region, | ||
}) | ||
if err != nil { | ||
return status.Errorf(codes.Internal, | ||
"couldn't get fetch volume list to check volume limit: %s", err.Error()) | ||
} | ||
|
||
if account.VolumeLimit <= len(volumes) { | ||
return status.Errorf(codes.ResourceExhausted, | ||
"volume limit (%d) has been reached. Current number of volumes: %d. Please contact support.", | ||
account.VolumeLimit, len(volumes)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// validateCapabilities validates the requested capabilities. It returns false | ||
// if it doesn't satisfy the currently supported modes of DigitalOcean Block | ||
// Storage | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
👑