Skip to content

Commit

Permalink
fix: quota property empty on upgrade (#629) (#630)
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinandan Purkait <[email protected]>
  • Loading branch information
Abhinandan-Purkait authored Feb 11, 2025
1 parent 9d22d06 commit cdfd13b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
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"
}
}

0 comments on commit cdfd13b

Please sign in to comment.