kubernetes/kops · error
unable to convert from Quantity %v to float
Error message
unable to convert from Quantity %v to float
What it means
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.
Source
Thrown at pkg/configbuilder/buildconfigfile.go:69
flagName := tokens[0]
targetValue, error := getValueFromStruct(flagName, target)
if error != nil {
return fmt.Errorf("conversion error for field %s: %s", flagName, error)
}
// We do have to do this, even though the recursive walk will do it for us
// because when we descend we won't have `field` set
if val.Kind() == reflect.Ptr {
if val.IsNil() {
return nil
}
}
switch v := val.Interface().(type) {
case *resource.Quantity:
floatVal, err := strconv.ParseFloat(v.AsDec().String(), 64)
if err != nil {
return fmt.Errorf("unable to convert from Quantity %v to float", v)
}
targetValue.Set(reflect.ValueOf(&floatVal))
default:
targetValue.Set(val)
}
return reflectutils.SkipReflection
}
err := reflectutils.ReflectRecursive(reflect.ValueOf(options), walker, &reflectutils.ReflectOptions{DeprecatedDoubleVisit: true})
if err != nil {
return nil, fmt.Errorf("BuildFlagsList to reflect value: %s", err)
}
configFile, err := yaml.Marshal(target)
if err != nil {
return nil, err
}View on GitHub (pinned to 4c8573c808)
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
Example fix
// before
resources:
requests:
cpu: "9999999999999999999999"
// after
resources:
requests:
cpu: "4"
memory: "8Gi" Defensive patterns
Strategy: validation
Validate before calling
func isFloatSafe(q *resource.Quantity) bool {
f, err := strconv.ParseFloat(q.AsDec().String(), 64)
return err == nil && !math.IsInf(f, 0) && !math.IsNaN(f)
}
// guard cluster-spec resource values before building config Try / catch
floatVal, err := strconv.ParseFloat(v.AsDec().String(), 64)
if err != nil {
return fmt.Errorf("unable to convert from Quantity %v to float: %w", v, err)
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- conversion error for field %s: %s
- BuildFlagsList to reflect value: %s
- only accepts structs; got %T
- unable to convert from Quantity %v to float
- unhandled type %v %q
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/cea84f46e8b9b3c5.
Report an issue: GitHub.