Skip to content

Commit

Permalink
Added support for SoftQuotaPct volume parameter
Browse files Browse the repository at this point in the history
This feature is N/A for EFAAS

Change-Id: I26448838c77494ee51f79c76e34a289aa3d3e903
  • Loading branch information
jeanspector-google committed Oct 18, 2022
1 parent b157956 commit d7112d4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
3 changes: 2 additions & 1 deletion deploy/templates/storageclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ parameters: # Note - only string values are accepted in parameters
permissions: "777"
# Default volume size
defaultVolumeSize: "100GiB"

# Volume access. Supported values: read_write, read_only, list_only, no_access
access: "read_write"
# Volume capacity percentage to be used as the soft quota. Default: 100
softQuotaPct: "75"

# === eFaaS options ===

Expand Down
2 changes: 1 addition & 1 deletion src/ecfs/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func getCreateVolumeResponse(volumeId volumeHandleType, volOptions *volumeOption
return &csi.CreateVolumeResponse{
Volume: &csi.Volume{
VolumeId: string(volumeId),
CapacityBytes: int64(volOptions.Capacity),
CapacityBytes: volOptions.Capacity,
VolumeContext: req.GetParameters(),
},
}
Expand Down
5 changes: 2 additions & 3 deletions src/ecfs/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ func exportExists(emsClient *emanageClient, exportName string, opt *volumeOption

func createDc(emsClient *emanageClient, opt *volumeOptions) (*emanage.DataContainer, error) {
dc, err := emsClient.DataContainers.Create(string(opt.VolumeId), dcPolicy, &emanage.DcCreateOpts{
// TODO: Consider setting soft quota at a %% of capacity (to be set via storageclass)
SoftQuota: int(opt.Capacity),
HardQuota: int(opt.Capacity),
HardQuota: opt.Capacity,
SoftQuota: opt.Capacity * int64(opt.SoftQuotaPct) / 100,
DirPermissions: opt.ExportPermissions,
})
return &dc, err
Expand Down
15 changes: 15 additions & 0 deletions src/ecfs/volumeoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package main

import (
"fmt"
"strconv"

"github.com/container-storage-interface/spec/lib/go/csi"
Expand Down Expand Up @@ -46,6 +47,7 @@ type volumeOptions struct {
ExportGid optional.Int
Access string // read_write/read_only/list_only/no_access
ClientRules string // [{"sourceRange": "all", "accessRights": "readWrite"}]
SoftQuotaPct int // Capacity percentage to be used as a soft quota
}

func extractOptionString(paramName StorageClassCustomParameter, options map[string]string) (value string, err error) {
Expand All @@ -70,6 +72,7 @@ const (
DefaultVolumeSize StorageClassCustomParameter = "defaultVolumeSize"
Access StorageClassCustomParameter = "access"
ClientRules StorageClassCustomParameter = "clientRules"
SoftQuotaPct StorageClassCustomParameter = "softQuotaPct"
)

// newVolumeOptions translates CreateVolumeRequest parameters to volumeOptions
Expand Down Expand Up @@ -174,6 +177,18 @@ func newVolumeOptions(req *csi.CreateVolumeRequest) (*volumeOptions, error) {
}
opts.ClientRules = paramStr

// SoftQuotaPct
if paramStr, err = extractOptionString(SoftQuotaPct, volParams); err != nil {
paramStr = "100"
}
if opts.SoftQuotaPct, err = strconv.Atoi(paramStr); err != nil {
return nil, errors.Wrap(err, 0)
}
if opts.SoftQuotaPct < 0 || opts.SoftQuotaPct > 100 {
return nil, errors.WrapPrefix(err, fmt.Sprintf(
"Invalid soft quota percentage: %v", opts.SoftQuotaPct), 0)
}

glog.V(log.DEBUG).Infof("ecfs: Current volume options: %+v", opts)
return opts, nil
}

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

0 comments on commit d7112d4

Please sign in to comment.