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

fix: quota property empty on upgrade #629

Merged
merged 1 commit into from
Feb 11, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/zfs/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,27 @@ func TestIsVolumeReady(t *testing.T) {
})
}
}

func TestReservationProperty(t *testing.T) {
tests := []struct {
name string
quotaType string
capacity string
expected string
}{
{"Empty quotaType defaults to quota", "", "10G", "reservation=10G"},
{"Valid quotaType quota", "quota", "5G", "reservation=5G"},
{"Valid quotaType refquota", "refquota", "3G", "refreservation=3G"},
{"Invalid quotaType defaults to quota", "invalid", "2G", "reservation=2G"},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := reservationProperty(tt.quotaType, tt.capacity)
if result != tt.expected {
t.Errorf("For quotaType %q and capacity %q, expected %q but got %q",
tt.quotaType, tt.capacity, tt.expected, result)
}
})
}
}
28 changes: 21 additions & 7 deletions pkg/zfs/zfs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func buildCloneCreateArgs(vol *apis.ZFSVolume) []string {

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

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

if vol.Spec.VolumeType == VolTypeDataset {
quotaProperty := vol.Spec.QuotaType + "=" + vol.Spec.Capacity
quotaProperty := quotaProperty(vol.Spec.QuotaType) + "=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, quotaProperty)
} else {
volsizeProperty := "volsize=" + vol.Spec.Capacity
Expand Down Expand Up @@ -971,11 +971,25 @@ 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{
// reservationProperty returns the reservation property based on the quota type.
func reservationProperty(quotaType, capacity string) string {
validQuotaType := quotaProperty(quotaType)

reservationProperties := map[string]string{
"quota": "reservation=",
"refquota": "refreservation=",
}
return reservationProperties[quotaType] + capacity

// Return the mapped property or default to "reservation="
return reservationProperties[validQuotaType] + capacity
}

// quotaProperty ensures backwards compatibility for the quota property.
func quotaProperty(quotaType string) string {
switch quotaType {
case "refquota":
return "refquota"
default:
return "quota"
}
}
Loading