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
…#542)

* feat(zfs-localpv): rebase from upstream develop branch

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

* feat(zfs-localpv): add refreservation for refquota when using Thick provisioning

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

* fix(zfs-localpv): fix typo qoutatype -> quotatype

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

* fix(zfs-localpv): replace quota case with default in thin provisioning switch case

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

* feat(zfs-localpv): add deploy/crds into corresponding deploy/helm crd manifests

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

* feat(zfs-localpv): add reservationProperty function in zfs_util

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

* feat(zfs-localpv): make manifests

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

---------

Signed-off-by: cina_pm <[email protected]>
  • Loading branch information
cinapm authored Sep 21, 2024
1 parent 8d46868 commit f185333
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 8 deletions.
8 changes: 8 additions & 0 deletions deploy/helm/charts/charts/crds/templates/zfsrestore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ spec:
been provisioned.
minLength: 1
type: string
quotaType:
description: 'quotaType determines whether the dataset volume quota
type is of type "quota" or "refquota". QuotaType can not be modified
once volume has been provisioned. Default Value: quota.'
enum:
- quota
- refquota
type: string
recordsize:
description: 'Specifies a suggested block size for files in the file
system. The size specified must be a power of two greater than or
Expand Down
8 changes: 8 additions & 0 deletions deploy/helm/charts/charts/crds/templates/zfssnapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ spec:
been provisioned.
minLength: 1
type: string
quotaType:
description: 'quotaType determines whether the dataset volume quota
type is of type "quota" or "refquota". QuotaType can not be modified
once volume has been provisioned. Default Value: quota.'
enum:
- quota
- refquota
type: string
recordsize:
description: 'Specifies a suggested block size for files in the file
system. The size specified must be a power of two greater than or
Expand Down
8 changes: 8 additions & 0 deletions deploy/helm/charts/charts/crds/templates/zfsvolume.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ spec:
been provisioned.
minLength: 1
type: string
quotaType:
description: 'quotaType determines whether the dataset volume quota
type is of type "quota" or "refquota". QuotaType can not be modified
once volume has been provisioned. Default Value: quota.'
enum:
- quota
- refquota
type: string
recordsize:
description: 'Specifies a suggested block size for files in the file
system. The size specified must be a power of two greater than or
Expand Down
8 changes: 8 additions & 0 deletions deploy/yamls/zfsrestore-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ spec:
been provisioned.
minLength: 1
type: string
quotaType:
description: 'quotaType determines whether the dataset volume quota
type is of type "quota" or "refquota". QuotaType can not be modified
once volume has been provisioned. Default Value: quota.'
enum:
- quota
- refquota
type: string
recordsize:
description: 'Specifies a suggested block size for files in the file
system. The size specified must be a power of two greater than or
Expand Down
8 changes: 8 additions & 0 deletions deploy/yamls/zfssnapshot-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ spec:
been provisioned.
minLength: 1
type: string
quotaType:
description: 'quotaType determines whether the dataset volume quota
type is of type "quota" or "refquota". QuotaType can not be modified
once volume has been provisioned. Default Value: quota.'
enum:
- quota
- refquota
type: string
recordsize:
description: 'Specifies a suggested block size for files in the file
system. The size specified must be a power of two greater than or
Expand Down
8 changes: 8 additions & 0 deletions deploy/yamls/zfsvolume-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ spec:
been provisioned.
minLength: 1
type: string
quotaType:
description: 'quotaType determines whether the dataset volume quota
type is of type "quota" or "refquota". QuotaType can not be modified
once volume has been provisioned. Default Value: quota.'
enum:
- quota
- refquota
type: string
recordsize:
description: 'Specifies a suggested block size for files in the file
system. The size specified must be a power of two greater than or
Expand Down
31 changes: 31 additions & 0 deletions deploy/zfs-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ metadata:
labels:
openebs.io/version: "2.7.0-develop"
role: "openebs-zfs"
app: "openebs-zfs-node"
name: "openebs-zfs-node"
openebs.io/component-name: "openebs-zfs-node"
---
Expand All @@ -51,6 +52,7 @@ metadata:
labels:
openebs.io/version: "2.7.0-develop"
role: "openebs-zfs"
app: "openebs-zfs-node"
name: "openebs-zfs-node"
openebs.io/component-name: "openebs-zfs-node"
data:
Expand Down Expand Up @@ -1438,6 +1440,14 @@ spec:
been provisioned.
minLength: 1
type: string
quotaType:
description: 'quotaType determines whether the dataset volume quota
type is of type "quota" or "refquota". QuotaType can not be modified
once volume has been provisioned. Default Value: quota.'
enum:
- quota
- refquota
type: string
recordsize:
description: 'Specifies a suggested block size for files in the file
system. The size specified must be a power of two greater than or
Expand Down Expand Up @@ -1635,6 +1645,14 @@ spec:
been provisioned.
minLength: 1
type: string
quotaType:
description: 'quotaType determines whether the dataset volume quota
type is of type "quota" or "refquota". QuotaType can not be modified
once volume has been provisioned. Default Value: quota.'
enum:
- quota
- refquota
type: string
recordsize:
description: 'Specifies a suggested block size for files in the file
system. The size specified must be a power of two greater than or
Expand Down Expand Up @@ -2034,6 +2052,14 @@ spec:
been provisioned.
minLength: 1
type: string
quotaType:
description: 'quotaType determines whether the dataset volume quota
type is of type "quota" or "refquota". QuotaType can not be modified
once volume has been provisioned. Default Value: quota.'
enum:
- quota
- refquota
type: string
recordsize:
description: 'Specifies a suggested block size for files in the file
system. The size specified must be a power of two greater than or
Expand Down Expand Up @@ -2430,6 +2456,7 @@ metadata:
labels:
openebs.io/version: "2.7.0-develop"
role: "openebs-zfs"
app: "openebs-zfs-node"
name: "openebs-zfs-node"
openebs.io/component-name: "openebs-zfs-node"
rules:
Expand Down Expand Up @@ -2491,6 +2518,7 @@ metadata:
labels:
openebs.io/version: "2.7.0-develop"
role: "openebs-zfs"
app: "openebs-zfs-node"
name: "openebs-zfs-node"
openebs.io/component-name: "openebs-zfs-node"
subjects:
Expand All @@ -2511,11 +2539,13 @@ metadata:
labels:
openebs.io/version: "2.7.0-develop"
role: "openebs-zfs"
app: "openebs-zfs-node"
name: "openebs-zfs-node"
openebs.io/component-name: "openebs-zfs-node"
spec:
selector:
matchLabels:
app: "openebs-zfs-node"
name: "openebs-zfs-node"
updateStrategy:
rollingUpdate:
Expand All @@ -2526,6 +2556,7 @@ spec:
labels:
openebs.io/version: "2.7.0-develop"
role: "openebs-zfs"
app: "openebs-zfs-node"
name: "openebs-zfs-node"
openebs.io/component-name: "openebs-zfs-node"
spec:
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/openebs.io/zfs/v1/zfsvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ type VolumeInfo struct {
// +kubebuilder:validation:Enum=ZVOL;DATASET
VolumeType string `json:"volumeType"`

// quotaType determines whether the dataset volume quota type is of type "quota" or "refquota".
// QuotaType can not be modified once volume has been provisioned.
// +kubebuilder:validation:Enum=quota;refquota
// Default Value: quota.
QuotaType string `json:"quotaType,omitempty"`

// FsType specifies filesystem type for the zfs volume/dataset.
// If FsType is provided as "zfs", then the driver will create a
// ZFS dataset, formatting is not required as underlying filesystem is ZFS anyway.
Expand Down
10 changes: 10 additions & 0 deletions pkg/builder/volbuilder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ func (b *Builder) WithFsType(fstype string) *Builder {
return b
}

// WithQuotaType sets quota type for dataset volume
func (b *Builder) WithQuotaType(quotatype string) *Builder {
if quotatype != "" {
b.volume.Object.Spec.QuotaType = quotatype
} else {
b.volume.Object.Spec.QuotaType = "quota"
}
return b
}

// WithShared sets where filesystem is shared or not
func (b *Builder) WithShared(shared string) *Builder {
b.volume.Object.Spec.Shared = shared
Expand Down
2 changes: 2 additions & 0 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ func CreateZFSVolume(ctx context.Context, req *csi.CreateVolumeRequest) (string,
schld := parameters["scheduler"]
fstype := parameters["fstype"]
shared := parameters["shared"]
quotatype := parameters["quotatype"]

vtype := zfs.GetVolumeType(fstype)

Expand Down Expand Up @@ -279,6 +280,7 @@ func CreateZFSVolume(ctx context.Context, req *csi.CreateVolumeRequest) (string,
WithVolumeType(vtype).
WithVolumeStatus(zfs.ZFSStatusPending).
WithFsType(fstype).
WithQuotaType(quotatype).
WithShared(shared).
WithCompression(compression).Build()

Expand Down
23 changes: 15 additions & 8 deletions pkg/zfs/zfs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,15 @@ func buildCloneCreateArgs(vol *apis.ZFSVolume) []string {

if vol.Spec.VolumeType == VolTypeDataset {
if len(vol.Spec.Capacity) != 0 {
quotaProperty := "quota=" + vol.Spec.Capacity
quotaProperty := vol.Spec.QuotaType + "=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, "-o", quotaProperty)
}
if len(vol.Spec.RecordSize) != 0 {
recordsizeProperty := "recordsize=" + vol.Spec.RecordSize
ZFSVolArg = append(ZFSVolArg, "-o", recordsizeProperty)
}
if vol.Spec.ThinProvision == "no" {
reservationProperty := "reservation=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, "-o", reservationProperty)
ZFSVolArg = append(ZFSVolArg, "-o", reservationProperty(vol.Spec.QuotaType, vol.Spec.Capacity))
}
ZFSVolArg = append(ZFSVolArg, "-o", "mountpoint=legacy")
}
Expand Down Expand Up @@ -216,16 +215,15 @@ func buildDatasetCreateArgs(vol *apis.ZFSVolume) []string {
ZFSVolArg = append(ZFSVolArg, ZFSCreateArg)

if len(vol.Spec.Capacity) != 0 {
quotaProperty := "quota=" + vol.Spec.Capacity
quotaProperty := vol.Spec.QuotaType + "=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, "-o", quotaProperty)
}
if len(vol.Spec.RecordSize) != 0 {
recordsizeProperty := "recordsize=" + vol.Spec.RecordSize
ZFSVolArg = append(ZFSVolArg, "-o", recordsizeProperty)
}
if vol.Spec.ThinProvision == "no" {
reservationProperty := "reservation=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, "-o", reservationProperty)
ZFSVolArg = append(ZFSVolArg, "-o", reservationProperty(vol.Spec.QuotaType, vol.Spec.Capacity))
}
if len(vol.Spec.Dedup) != 0 {
dedupProperty := "dedup=" + vol.Spec.Dedup
Expand Down Expand Up @@ -292,7 +290,7 @@ func buildVolumeResizeArgs(vol *apis.ZFSVolume) []string {
ZFSVolArg = append(ZFSVolArg, ZFSSetArg)

if vol.Spec.VolumeType == VolTypeDataset {
quotaProperty := "quota=" + vol.Spec.Capacity
quotaProperty := vol.Spec.QuotaType + "=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, quotaProperty)
} else {
volsizeProperty := "volsize=" + vol.Spec.Capacity
Expand Down Expand Up @@ -350,7 +348,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 " + rstr.VolSpec.QuotaType + "=" + rstr.VolSpec.Capacity
}
if len(rstr.VolSpec.RecordSize) != 0 {
ZFSRecvParam += " -o recordsize=" + rstr.VolSpec.RecordSize
Expand Down Expand Up @@ -968,3 +966,12 @@ func decodeListOutput(raw []byte) ([]apis.Pool, error) {
}
return pools, nil
}

// get the reservation property based on the quota type
func reservationProperty(quotaType string, capacity string) string {
var reservationProperties = map[string]string{
"quota": "reservation=",
"refquota": "refreservation=",
}
return reservationProperties[quotaType] + capacity
}

0 comments on commit f185333

Please sign in to comment.