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 quota for volumes #48264

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/persistent-volume-provisioning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ parameters:
* **group** maps all access to this group. Default is `nfsnobody`.
* **quobyteConfig** use the specified configuration to create the volume. You can create a new configuration or modify an existing one with the Web console or the quobyte CLI. Default is `BASE`
* **quobyteTenant** use the specified tenant ID to create/delete the volume. This Quobyte tenant has to be already present in Quobyte. For Quobyte < 1.4 use an empty string `""` as `DEFAULT` tenant. Default is `DEFAULT`
* **createQuota** if set all volumes created by this storage class will get a Quota for the specified size. The quota is set for the logical disk size (which can differ from the physical size e.q. if replication is used). Default is ``False

First create Quobyte admin's Secret in the system namespace. Here the Secret is created in `kube-system`:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ parameters:
group: "root"
quobyteConfig: "BASE"
quobyteTenant: "DEFAULT"
createQuota: "False"
5 changes: 4 additions & 1 deletion pkg/volume/quobyte/quobyte.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ func (provisioner *quobyteVolumeProvisioner) Provision() (*v1.PersistentVolume,
}
provisioner.config = "BASE"
provisioner.tenant = "DEFAULT"
createQuota := false

cfg, err := parseAPIConfig(provisioner.plugin, provisioner.options.Parameters)
if err != nil {
Expand All @@ -382,6 +383,8 @@ func (provisioner *quobyteVolumeProvisioner) Provision() (*v1.PersistentVolume,
provisioner.tenant = v
case "quobyteconfig":
provisioner.config = v
case "createquota":
createQuota = gostrings.ToLower(v) == "true"
case "adminsecretname",
"adminsecretnamespace",
"quobyteapiserver":
Expand All @@ -402,7 +405,7 @@ func (provisioner *quobyteVolumeProvisioner) Provision() (*v1.PersistentVolume,
config: cfg,
}

vol, sizeGB, err := manager.createVolume(provisioner)
vol, sizeGB, err := manager.createVolume(provisioner, createQuota)
if err != nil {
return nil, err
}
Expand Down
16 changes: 13 additions & 3 deletions pkg/volume/quobyte/quobyte_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ type quobyteVolumeManager struct {
config *quobyteAPIConfig
}

func (manager *quobyteVolumeManager) createVolume(provisioner *quobyteVolumeProvisioner) (quobyte *v1.QuobyteVolumeSource, size int, err error) {
func (manager *quobyteVolumeManager) createVolume(provisioner *quobyteVolumeProvisioner, createQuota bool) (quobyte *v1.QuobyteVolumeSource, size int, err error) {
capacity := provisioner.options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
volumeSize := int(volume.RoundUpSize(capacity.Value(), 1024*1024*1024))
// Quobyte has the concept of Volumes which doen't have a specific size (they can grow unlimited)
// to simulate a size constraint we could set here a Quota
// to simulate a size constraint we set here a Quota for logical space
volumeRequest := &quobyteapi.CreateVolumeRequest{
Name: provisioner.volume,
RootUserID: provisioner.user,
Expand All @@ -45,10 +45,20 @@ func (manager *quobyteVolumeManager) createVolume(provisioner *quobyteVolumeProv
ConfigurationName: provisioner.config,
}

if _, err := manager.createQuobyteClient().CreateVolume(volumeRequest); err != nil {
quobyteClient := manager.createQuobyteClient()
volumeUUID, err := quobyteClient.CreateVolume(volumeRequest)
if err != nil {
return &v1.QuobyteVolumeSource{}, volumeSize, err
}

// Set Quota for Volume with specified byte size
if createQuota {
err = quobyteClient.SetVolumeQuota(volumeUUID, uint64(capacity.Value()))
if err != nil {
return &v1.QuobyteVolumeSource{}, volumeSize, err
}
}

glog.V(4).Infof("Created Quobyte volume %s", provisioner.volume)
return &v1.QuobyteVolumeSource{
Registry: provisioner.registry,
Expand Down
8 changes: 4 additions & 4 deletions vendor/github.com/quobyte/api/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion vendor/github.com/quobyte/api/quobyte.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/quobyte/api/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.