From 6a88a03d59e96be590cf2be2056d4e19847902da Mon Sep 17 00:00:00 2001 From: Johannes Scheuermann Date: Wed, 28 Jun 2017 23:03:33 +0200 Subject: [PATCH 1/4] Set a Quobyte quota for newly created volumes --- pkg/volume/quobyte/quobyte_util.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/volume/quobyte/quobyte_util.go b/pkg/volume/quobyte/quobyte_util.go index cd32637c58..e094133bf4 100644 --- a/pkg/volume/quobyte/quobyte_util.go +++ b/pkg/volume/quobyte/quobyte_util.go @@ -36,7 +36,7 @@ func (manager *quobyteVolumeManager) createVolume(provisioner *quobyteVolumeProv 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, @@ -45,7 +45,15 @@ 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 Quoate for Volume with specified byte size + err = quobyteClient.SetVolumeQuota(volumeUUID, capacity.Value()) + if err != nil { return &v1.QuobyteVolumeSource{}, volumeSize, err } From 7ce5478c0ced59869da3eedbfd2b4bf95d0d9fe0 Mon Sep 17 00:00:00 2001 From: Johannes Scheuermann Date: Thu, 29 Jun 2017 12:15:22 +0200 Subject: [PATCH 2/4] Update Quobyte API repo --- Godeps/Godeps.json | 2 +- vendor/github.com/quobyte/api/BUILD | 31 ------------------------ vendor/github.com/quobyte/api/README.md | 8 +++--- vendor/github.com/quobyte/api/quobyte.go | 27 ++++++++++++++++++++- vendor/github.com/quobyte/api/types.go | 22 +++++++++++++++++ 5 files changed, 53 insertions(+), 37 deletions(-) delete mode 100644 vendor/github.com/quobyte/api/BUILD diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 8238ba1ea3..f09e0f0380 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -2218,7 +2218,7 @@ }, { "ImportPath": "github.com/quobyte/api", - "Rev": "bf713b5a4333f44504fa1ce63690de45cfed6413" + "Rev": "cb10db90715b14d4784465d2fa3b915dfacc0628" }, { "ImportPath": "github.com/rackspace/gophercloud", diff --git a/vendor/github.com/quobyte/api/BUILD b/vendor/github.com/quobyte/api/BUILD deleted file mode 100644 index 84fec6cd09..0000000000 --- a/vendor/github.com/quobyte/api/BUILD +++ /dev/null @@ -1,31 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -licenses(["notice"]) - -load( - "@io_bazel_rules_go//go:def.bzl", - "go_library", -) - -go_library( - name = "go_default_library", - srcs = [ - "quobyte.go", - "rpc_client.go", - "types.go", - ], - tags = ["automanaged"], -) - -filegroup( - name = "package-srcs", - srcs = glob(["**"]), - tags = ["automanaged"], - visibility = ["//visibility:private"], -) - -filegroup( - name = "all-srcs", - srcs = [":package-srcs"], - tags = ["automanaged"], -) diff --git a/vendor/github.com/quobyte/api/README.md b/vendor/github.com/quobyte/api/README.md index 7ed01f10d2..072033b7bd 100644 --- a/vendor/github.com/quobyte/api/README.md +++ b/vendor/github.com/quobyte/api/README.md @@ -22,14 +22,14 @@ func main() { Name: "MyVolume", RootUserID: "root", RootGroupID: "root", - ConfigurationName: "base", + ConfigurationName: "BASE", } - volume_uuid, err := client.CreateVolume(req) + volumeUUID, err := client.CreateVolume(req) if err != nil { log.Fatalf("Error:", err) } - log.Printf("%s", volume_uuid) + log.Printf("%s", volumeUUID) } -``` +``` \ No newline at end of file diff --git a/vendor/github.com/quobyte/api/quobyte.go b/vendor/github.com/quobyte/api/quobyte.go index 88f7c84827..3a2a5fd17a 100644 --- a/vendor/github.com/quobyte/api/quobyte.go +++ b/vendor/github.com/quobyte/api/quobyte.go @@ -1,7 +1,9 @@ // Package quobyte represents a golang API for the Quobyte Storage System package quobyte -import "net/http" +import ( + "net/http" +) type QuobyteClient struct { client *http.Client @@ -77,3 +79,26 @@ func (client *QuobyteClient) GetClientList(tenant string) (GetClientListResponse return response, nil } + +func (client *QuobyteClient) SetVolumeQuota(volumeUUID string, quotaSize uint64) error { + request := &setQuotaRequest{ + Quotas: []*quota{ + "a{ + Consumer: []*consumingEntity{ + &consumingEntity{ + Type: "VOLUME", + Identifier: volumeUUID, + }, + }, + Limits: []*resource{ + &resource{ + Type: "LOGICAL_DISK_SPACE", + Value: quotaSize, + }, + }, + }, + }, + } + + return client.sendRequest("setQuota", request, nil) +} diff --git a/vendor/github.com/quobyte/api/types.go b/vendor/github.com/quobyte/api/types.go index 2ed5698aa1..c1a87d3371 100644 --- a/vendor/github.com/quobyte/api/types.go +++ b/vendor/github.com/quobyte/api/types.go @@ -32,3 +32,25 @@ type Client struct { MountedUserName string `json:"mount_user_name,omitempty"` MountedVolumeUUID string `json:"mounted_volume_uuid,omitempty"` } + +type consumingEntity struct { + Type string `json:"type,omitempty"` + Identifier string `json:"identifier,omitempty"` + TenantID string `json:"tenant_id,omitempty"` +} + +type resource struct { + Type string `json:"type,omitempty"` + Value uint64 `json:"value,omitempty"` +} + +type quota struct { + ID string `json:"id,omitempty"` + Consumer []*consumingEntity `json:"consumer,omitempty"` + Limits []*resource `json:"limits,omitempty"` + Currentusage []*resource `json:"current_usage,omitempty"` +} + +type setQuotaRequest struct { + Quotas []*quota `json:"quotas,omitempty"` +} From e631550ef3b23b2ede9774ebc6daf2e7f13f441c Mon Sep 17 00:00:00 2001 From: Johannes Scheuermann Date: Thu, 29 Jun 2017 13:12:24 +0200 Subject: [PATCH 3/4] Make the Quota creation optional --- examples/persistent-volume-provisioning/README.md | 1 + .../quobyte/quobyte-storage-class.yaml | 1 + pkg/volume/quobyte/quobyte.go | 5 ++++- pkg/volume/quobyte/quobyte_util.go | 12 +++++++----- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/persistent-volume-provisioning/README.md b/examples/persistent-volume-provisioning/README.md index 4d3f00af64..a2f4753f06 100644 --- a/examples/persistent-volume-provisioning/README.md +++ b/examples/persistent-volume-provisioning/README.md @@ -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`: diff --git a/examples/persistent-volume-provisioning/quobyte/quobyte-storage-class.yaml b/examples/persistent-volume-provisioning/quobyte/quobyte-storage-class.yaml index 739b94fe91..b9679d61df 100644 --- a/examples/persistent-volume-provisioning/quobyte/quobyte-storage-class.yaml +++ b/examples/persistent-volume-provisioning/quobyte/quobyte-storage-class.yaml @@ -12,3 +12,4 @@ parameters: group: "root" quobyteConfig: "BASE" quobyteTenant: "DEFAULT" + createQuota: "False" diff --git a/pkg/volume/quobyte/quobyte.go b/pkg/volume/quobyte/quobyte.go index 7cc9813891..5fae74de72 100644 --- a/pkg/volume/quobyte/quobyte.go +++ b/pkg/volume/quobyte/quobyte.go @@ -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 { @@ -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": @@ -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 } diff --git a/pkg/volume/quobyte/quobyte_util.go b/pkg/volume/quobyte/quobyte_util.go index e094133bf4..2b5db49fa2 100644 --- a/pkg/volume/quobyte/quobyte_util.go +++ b/pkg/volume/quobyte/quobyte_util.go @@ -32,7 +32,7 @@ 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) @@ -51,10 +51,12 @@ func (manager *quobyteVolumeManager) createVolume(provisioner *quobyteVolumeProv return &v1.QuobyteVolumeSource{}, volumeSize, err } - // Set Quoate for Volume with specified byte size - err = quobyteClient.SetVolumeQuota(volumeUUID, capacity.Value()) - 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) From 74fde1893edc0c456e785a441e267d2e1c3bc129 Mon Sep 17 00:00:00 2001 From: Johannes Scheuermann Date: Fri, 30 Jun 2017 20:41:34 +0200 Subject: [PATCH 4/4] Add bazel build file --- vendor/github.com/quobyte/api/BUILD | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 vendor/github.com/quobyte/api/BUILD diff --git a/vendor/github.com/quobyte/api/BUILD b/vendor/github.com/quobyte/api/BUILD new file mode 100644 index 0000000000..84fec6cd09 --- /dev/null +++ b/vendor/github.com/quobyte/api/BUILD @@ -0,0 +1,31 @@ +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_library", +) + +go_library( + name = "go_default_library", + srcs = [ + "quobyte.go", + "rpc_client.go", + "types.go", + ], + tags = ["automanaged"], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +)