Skip to content

Commit 34829d8

Browse files
authored
fix: add @iecQuantity CUE attribute alongside @k8sResource (#10220)
1 parent e25fa9d commit 34829d8

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

pkg/parameters/validate/cue_util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
K8SQuantityType CueType = "quantity"
4444
ClassicStorageType CueType = "storage"
4545
ClassicTimeDurationType CueType = "timeDuration"
46+
IECQuantityType CueType = "iecQuantity"
4647
)
4748

4849
// CueValidate validates cue file

pkg/parameters/validate/cue_visitor.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ func transNumberOrBoolType(t CueType, obj reflect.Value, fn util.UpdateFn, expan
160160
return processTypeTrans[int64](obj, handleK8sQuantityType, fn, trimString, true)
161161
case ClassicStorageType:
162162
return processTypeTrans[int64](obj, handleClassicStorageType(expand), fn, trimString, true)
163+
case IECQuantityType:
164+
return processTypeTrans[int64](obj, handleIECQuantityType, fn, trimString, true)
163165
case ClassicTimeDurationType:
164166
return processTypeTrans[int64](obj, handleClassicTimeDurationType(expand), fn, trimString, true)
165167
case StringType:

pkg/parameters/validate/cuelang_expansion.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const (
3535
k8sResourceAttr = "k8sResource"
3636
attrQuantityValue = "quantity"
3737
storeResourceAttr = "storeResource"
38+
iecQuantityAttr = "iecQuantity"
3839
timeDurationResourceAttr = "timeDurationResource"
3940
// attrStorageValue = "storage"
4041
// attrTimeDurationValue = "timeDuration"
@@ -102,6 +103,8 @@ func processCueIntegerExpansion(x cue.Value) (CueType, string) {
102103
return K8SQuantityType, ""
103104
case storeResourceAttr:
104105
return ClassicStorageType, attr.Contents()
106+
case iecQuantityAttr:
107+
return IECQuantityType, ""
105108
case timeDurationResourceAttr:
106109
return ClassicTimeDurationType, attr.Contents()
107110
}
@@ -117,6 +120,17 @@ func handleK8sQuantityType(s string) (int64, error) {
117120
return quantity.Value(), nil
118121
}
119122

123+
func handleIECQuantityType(s string) (int64, error) {
124+
if !isAllNumber(s) {
125+
// IEC 80000-13 requires explicit 'B' suffix (e.g. "256MB", "256MiB").
126+
if !strings.HasSuffix(s, "B") {
127+
return 0, core.MakeError("require explicit byte-unit suffixing[%s]", s)
128+
}
129+
s = s[:len(s)-1]
130+
}
131+
return handleK8sQuantityType(s)
132+
}
133+
120134
func parseDigitNumber(s string) int {
121135
lastDigit := 0
122136
for _, b := range s {

0 commit comments

Comments
 (0)