{"record":{"id":"cea84f46e8b9b3c5","repo":"kubernetes/kops","slug":"unable-to-convert-from-quantity-v-to-float","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/configbuilder/buildconfigfile.go","lineNumber":69,"sourceCode":"\n\t\tflagName := tokens[0]\n\n\t\ttargetValue, error := getValueFromStruct(flagName, target)\n\t\tif error != nil {\n\t\t\treturn fmt.Errorf(\"conversion error for field %s: %s\", flagName, error)\n\t\t}\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\t\tswitch v := val.Interface().(type) {\n\t\tcase *resource.Quantity:\n\t\t\tfloatVal, err := strconv.ParseFloat(v.AsDec().String(), 64)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"unable to convert from Quantity %v to float\", v)\n\t\t\t}\n\t\t\ttargetValue.Set(reflect.ValueOf(&floatVal))\n\t\tdefault:\n\t\t\ttargetValue.Set(val)\n\t\t}\n\n\t\treturn reflectutils.SkipReflection\n\t}\n\n\terr := reflectutils.ReflectRecursive(reflect.ValueOf(options), walker, &reflectutils.ReflectOptions{DeprecatedDoubleVisit: true})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"BuildFlagsList to reflect value: %s\", err)\n\t}\n\n\tconfigFile, err := yaml.Marshal(target)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/configbuilder/buildconfigfile.go#L51-L87","documentation":"When the walker encounters a *resource.Quantity (k8s.io/apimachinery quantities like CPU/memory) it converts it to a float64 by parsing the decimal string form. If strconv.ParseFloat fails on v.AsDec().String(), this error is returned. It means the Quantity's decimal representation was not a parseable float64.","triggerScenarios":"A *resource.Quantity field with a configfile tag whose AsDec().String() yields a value strconv.ParseFloat cannot parse — effectively only possible with exotic/huge-magnitude or corrupted Quantity values (ParseFloat accepts scientific notation, so ordinary values like \"100Mi\" resolve to numeric forms fine, but an uninitialized or manually constructed Quantity with a malformed decimal can fail).","commonSituations":"A user sets an unusual resource value in the cluster spec (e.g. extremely large memory/cpu limits) that overflows float64 when rendered to a component config; a Quantity is constructed programmatically without proper value initialization.","solutions":["Check the Quantity value shown in the error and reduce/normalize it (use plain numeric values instead of extreme magnitudes) in the cluster spec","Verify the Quantity is initialized with resource.MustParse or the API defaulting, not a zero-value struct","If the field is not meant to be a float in the target config, change the target field type or drop the configfile tag so it is skipped","Update kops/apimachinery versions if the Quantity came from a newer format that this converter predates"],"exampleFix":"// before\nresources:\n  requests:\n    cpu: \"9999999999999999999999\"\n// after\nresources:\n  requests:\n    cpu: \"4\"\n    memory: \"8Gi\"","handlingStrategy":"validation","validationCode":"func isFloatSafe(q *resource.Quantity) bool {\n\tf, err := strconv.ParseFloat(q.AsDec().String(), 64)\n\treturn err == nil && !math.IsInf(f, 0) && !math.IsNaN(f)\n}\n// guard cluster-spec resource values before building config","typeGuard":null,"tryCatchPattern":"floatVal, err := strconv.ParseFloat(v.AsDec().String(), 64)\nif err != nil {\n\treturn fmt.Errorf(\"unable to convert from Quantity %v to float: %w\", v, err)\n}","preventionTips":["Set resource requests/limits in the cluster spec with ordinary magnitudes (e.g. \"4\", \"8Gi\"), not astronomically large values","Initialize Quantities via resource.MustParse rather than zero-value structs","Skip exotic Quantity fields with configfile:\"-\" if the target config expects a plain float","Add a round-trip test rendering typical resource values through BuildConfigYaml"],"tags":["reflection","quantity","config-generation","go"],"backgroundTag":"quantity-to-float-conversion-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"}