{"record":{"id":"08878c3b50dcfc07","repo":"kubernetes/kops","slug":"unable-to-convert-from-quantity-v-to-float-08878c","errorCode":null,"errorMessage":"unable to convert from Quantity %v to float","messagePattern":"unable to convert from Quantity (.+?) to float","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/model/components/kubescheduler/model.go","lineNumber":173,"sourceCode":"\t\t}\n\t\ttargetPath := tagTokens[0]\n\n\t\t// We do have to do this, even though the recursive walk will do it for us\n\t\t// because when we descend we won't have `field` set\n\t\tif val.Kind() == reflect.Ptr {\n\t\t\tif val.IsNil() {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}\n\n\t\tisEmpty := val.IsZero()\n\n\t\tif !isEmpty || !omitEmpty {\n\t\t\tswitch v := val.Interface().(type) {\n\t\t\tcase *resource.Quantity:\n\t\t\t\tfloatVal, err := strconv.ParseFloat(v.AsDec().String(), 64)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"unable to convert from Quantity %v to float\", v)\n\t\t\t\t}\n\t\t\t\tif err := setValue(targetPath, floatVal); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\t// Clear the field, so we don't set the flag\n\t\t\t\tval.Set(reflect.Zero(val.Type()))\n\t\t\tdefault:\n\t\t\t\tif err := setValue(targetPath, val.Interface()); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\t// Clear the field, so we don't set the flag\n\t\t\t\tempty := reflect.New(val.Type()).Elem()\n\t\t\t\tval.Set(empty)\n\t\t\t}\n\t\t}\n\n\t\treturn reflectutils.SkipReflection\n\t}","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/model/components/kubescheduler/model.go#L155-L191","documentation":"kOps converts Kubernetes API Quantity fields (CPU/memory limits such as kube-scheduler QPS) to float64 via reflection when building the scheduler config. It attempts strconv.ParseFloat on the Quantity's decimal string; if that parse fails it cannot proceed and returns this error. In practice this is nearly impossible to hit with a valid Quantity, since Quantity.AsDec() always yields a parseable decimal string; it surfaces only when the Quantity value is malformed or nil-dereferenced through reflection into an unexpected state.","triggerScenarios":"Calling MapToUnstructured on a kube-scheduler options struct whose *resource.Quantity field holds a value whose AsDec().String() cannot be parsed by strconv.ParseFloat (e.g. a corrupted/zero-value Quantity or one carrying a non-numeric representation).","commonSituations":"Hand-edited or generated cluster spec values for scheduler resource limits/requests; older or unusual k8s.io/apimachinery Quantity serializations being round-tripped through kOps model building.","solutions":["Check the Quantity fields in your cluster spec (e.g. kube-scheduler resources) for malformed or empty values and set them to valid quantities like \"100m\" or \"500Mi\".","Re-run `kops edit cluster` / `kops replace -f` with a spec validated by `kops validate` or YAML schema checks to normalize Quantity values.","Upgrade kOps and k8s.io/apimachinery so Quantity serialization round-trips are consistent."],"exampleFix":"// before (cluster spec yaml)\nkubeScheduler:\n  cpuRequest: \"abc\"\n// after\nkubeScheduler:\n  cpuRequest: \"100m\"","handlingStrategy":"validation","validationCode":"for _, f := range []string{\"cpuRequest\", \"cpuLimit\", \"memoryRequest\", \"memoryLimit\"} {\n    if q := kubeSchedulerConfigField(q, f); q != nil {\n        if _, err := strconv.ParseFloat(q.AsDec().String(), 64); err != nil {\n            return fmt.Errorf(\"invalid quantity %s: %v\", f, q)\n        }\n    }\n}","typeGuard":"func validQuantity(q *resource.Quantity) bool { return q != nil && q.Value() >= 0 && q.AsDec() != nil }","tryCatchPattern":"if err := buildSchedulerConfig(obj, target); err != nil {\n    if strings.Contains(err.Error(), \"unable to convert from Quantity\") {\n        // reset the offending Quantity field to a valid default and retry\n    }\n}","preventionTips":["Always set scheduler resources with valid k8s quantity strings (e.g. \"100m\", \"128Mi\").","Never hand-edit serialized Quantity internals; edit cluster YAML with recognized units.","Run `kops validate cluster` / spec linting before applying."],"tags":["reflection","quantity","kube-scheduler","conversion"],"backgroundTag":"quantity-parse-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}