{"record":{"id":"4e9c7c9e921bca0e","repo":"kubernetes/kops","slug":"cannot-interpret-q-value-as-resource-quantity","errorCode":null,"errorMessage":"cannot interpret %q value as resource.Quantity","messagePattern":"cannot interpret %q value as resource\\.Quantity","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/reflectutils/access.go","lineNumber":288,"sourceCode":"\t\t}\n\n\t\tname, value, hasValue := strings.Cut(newValue, \"=\")\n\t\tnewV.FieldByIndex(fdName.Index).SetString(name)\n\t\tif hasValue {\n\t\t\tnewV.FieldByIndex(fdValue.Index).SetString(value)\n\t\t}\n\n\tcase \"v1.Duration\":\n\t\tduration, err := time.ParseDuration(newValue)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot interpret %q value as v1.Duration\", newValue)\n\t\t}\n\t\tnewV = reflect.ValueOf(metav1.Duration{Duration: duration})\n\n\tcase \"resource.Quantity\":\n\t\tquantity, err := resource.ParseQuantity(newValue)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot interpret %q value as resource.Quantity\", newValue)\n\t\t}\n\t\tnewV = reflect.ValueOf(quantity)\n\n\tdefault:\n\t\t// This handles enums and other simple conversions\n\t\tnewV = reflect.ValueOf(newValue)\n\t\tif newV.Type().ConvertibleTo(v.Type()) {\n\t\t\tnewV = newV.Convert(v.Type())\n\t\t} else {\n\t\t\treturn fmt.Errorf(\"unhandled type %q\", t)\n\t\t}\n\t}\n\n\tv.Set(newV)\n\treturn nil\n}\n\nfunc Unset(target interface{}, targetPath string) error {","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/reflectutils/access.go#L270-L306","documentation":"Fields tagged resource.Quantity are parsed with apimachinery's resource.ParseQuantity. If the string is not a valid Kubernetes quantity (number with optional SI/binary suffix), this error is returned. Quantities must look like \"128974848\", \"129e6\", \"129Mi\", \"1G\", etc.","triggerScenarios":"`kops set ... spec.memory=8GB` or similar on quantity-tagged fields with invalid strings such as \"8 GB\" (space), \"8gigs\", \"big\", or empty template values.","commonSituations":"Using human-friendly spellings instead of Kubernetes quantity syntax (Gi vs GB confusion), whitespace from YAML/CLI parsing, or setting CPU values like \"0.5 cores\".","solutions":["Use valid quantity syntax: \"8Gi\", \"8000Mi\", \"500m\", \"1G\" — no spaces","Use binary suffixes (Ki/Mi/Gi/Ti) for memory, decimal (k/M/G) or millicores (m) for CPU","Verify with `kubectl` quantity rules (Kubernetes docs on resource quantities) before setting"],"exampleFix":"// before\nkops set instancegroup nodes spec.machineMemory=16 GB\n// after\nkops set instancegroup nodes spec.machineMemory=16Gi","handlingStrategy":"validation","validationCode":"q := \"16Gi\"\nif _, err := resource.ParseQuantity(q); err != nil {\n\treturn fmt.Errorf(\"invalid quantity %q: %v\", q, err)\n}","typeGuard":"func isValidQuantity(s string) bool {\n\t_, err := resource.ParseQuantity(s)\n\treturn err == nil\n}","tryCatchPattern":"if err := doSet(); err != nil && strings.Contains(err.Error(), \"as resource.Quantity\") {\n\t// fix to valid quantity like 16Gi / 500m\n}","preventionTips":["Use Kubernetes quantity syntax: no spaces, suffixes Mi/Gi/m","Test quantity strings with resource.ParseQuantity or kubectl first","Distinguish binary (Gi) from decimal (G) suffixes"],"tags":["kubernetes","quantity","value-parsing"],"backgroundTag":"invalid-resource-quantity","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}