Skip to content

Commit

Permalink
feat(zfs-localpv): add option for choosing between refquota and quota
Browse files Browse the repository at this point in the history
Signed-off-by: cina_pm <[email protected]>

feat(zfs-localpv): add comments for quota types

Signed-off-by: cina_pm <[email protected]>

fix(zfs-localpv): run goimports on main.go

Signed-off-by: cina_pm <[email protected]>
  • Loading branch information
cinapm committed Jun 23, 2024
1 parent 1b0b77e commit ab2b941
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
15 changes: 12 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (
"log"
"os"

config "github.com/openebs/zfs-localpv/pkg/config"
configs "github.com/openebs/zfs-localpv/pkg/config"

"github.com/openebs/zfs-localpv/pkg/driver"
"github.com/openebs/zfs-localpv/pkg/version"
zfs "github.com/openebs/zfs-localpv/pkg/zfs"
Expand All @@ -40,7 +41,7 @@ import (
*/
func main() {
_ = flag.CommandLine.Parse([]string{})
var config = config.Default()
var config = configs.Default()

cmd := &cobra.Command{
Use: "zfs-driver",
Expand Down Expand Up @@ -74,18 +75,26 @@ func main() {
&config.PluginType, "plugin", "csi-plugin", "Type of this driver i.e. controller or node",
)

cmd.PersistentFlags().StringVar(
&configs.QuotaType, "quota-type", "quota", "quota type: refquota or quota",
)

err := cmd.Execute()
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%s", err.Error())
os.Exit(1)
}
}

func run(config *config.Config) {
func run(config *configs.Config) {
if config.Version == "" {
config.Version = version.Current()
}

if configs.QuotaType != configs.Quota && configs.QuotaType != configs.RefQuota {
log.Fatalln(fmt.Errorf("quota-type should be quota or refquota"))
}

klog.Infof("ZFS Driver Version :- %s - commit :- %s", version.Current(), version.GetGitCommit())
klog.Infof(
"DriverName: %s Plugin: %s EndPoint: %s Node Name: %s",
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ type Config struct {
Nodename string
}

const (
Quota = "quota" // This option sets a limit on the amount of disk space a dataset can use
RefQuota = "refquota" // This option sets a limit on the amount of disk space a dataset and all its snapshots can use
)

var QuotaType string

// Default returns a new instance of config
// required to initialize a driver instance
func Default() *Config {
Expand Down
9 changes: 5 additions & 4 deletions pkg/zfs/zfs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package zfs

import (
"bufio"
configs "github.com/openebs/zfs-localpv/pkg/config"
"os/exec"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -143,7 +144,7 @@ func buildCloneCreateArgs(vol *apis.ZFSVolume) []string {

if vol.Spec.VolumeType == VolTypeDataset {
if len(vol.Spec.Capacity) != 0 {
quotaProperty := "quota=" + vol.Spec.Capacity
quotaProperty := configs.QuotaType + "=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, "-o", quotaProperty)
}
if len(vol.Spec.RecordSize) != 0 {
Expand Down Expand Up @@ -216,7 +217,7 @@ func buildDatasetCreateArgs(vol *apis.ZFSVolume) []string {
ZFSVolArg = append(ZFSVolArg, ZFSCreateArg)

if len(vol.Spec.Capacity) != 0 {
quotaProperty := "quota=" + vol.Spec.Capacity
quotaProperty := configs.QuotaType + "=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, "-o", quotaProperty)
}
if len(vol.Spec.RecordSize) != 0 {
Expand Down Expand Up @@ -292,7 +293,7 @@ func buildVolumeResizeArgs(vol *apis.ZFSVolume) []string {
ZFSVolArg = append(ZFSVolArg, ZFSSetArg)

if vol.Spec.VolumeType == VolTypeDataset {
quotaProperty := "quota=" + vol.Spec.Capacity
quotaProperty := configs.QuotaType + "=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, quotaProperty)
} else {
volsizeProperty := "volsize=" + vol.Spec.Capacity
Expand Down Expand Up @@ -350,7 +351,7 @@ func buildVolumeRestoreArgs(rstr *apis.ZFSRestore) ([]string, error) {

if rstr.VolSpec.VolumeType == VolTypeDataset {
if len(rstr.VolSpec.Capacity) != 0 {
ZFSRecvParam += " -o quota=" + rstr.VolSpec.Capacity
ZFSRecvParam += " -o " + configs.QuotaType + "=" + rstr.VolSpec.Capacity
}
if len(rstr.VolSpec.RecordSize) != 0 {
ZFSRecvParam += " -o recordsize=" + rstr.VolSpec.RecordSize
Expand Down

0 comments on commit ab2b941

Please sign in to comment.