in pkg/api/deploymentapi/deploymentsize/sizes.go [31:64]
func ParseGb(strSize string) (int32, error) {
strSize = strings.ToLower(strSize)
if strSize == "0" {
return 0, nil
}
re := regexp.MustCompile(`(?m)(.*\w)(g)`)
matches := re.FindStringSubmatch(strSize)
if len(matches) < 2 {
return 0, fmt.Errorf(`failed to convert "%s" to <size><g>`, strSize)
}
// Pops the first item out when the first match (all groups) are contained
// within the full string.
if strings.Contains(strSize, matches[0]) {
matches = matches[1:]
}
rawSize, err := strconv.ParseFloat(matches[0], 32)
if err != nil {
return 0, err
}
var size = int32(rawSize * 1024)
if size < minsize {
return 0, fmt.Errorf(`size "%s" is invalid: minimum size is %.1fg`, strSize, float32(minsize)/1024)
}
if size%512 > 0 {
return 0, fmt.Errorf(`size "%s" is invalid: only increments of 0.5g are permitted`, strSize)
}
return size, nil
}