kubernetes/kops · error

unable to convert from Quantity %v to float

Error message

unable to convert from Quantity %v to float

What it means

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.

Source

Thrown at pkg/model/components/kubescheduler/model.go:173

		}
		targetPath := tagTokens[0]

		// 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
			}
		}

		isEmpty := val.IsZero()

		if !isEmpty || !omitEmpty {
			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)
				}
				if err := setValue(targetPath, floatVal); err != nil {
					return err
				}
				// Clear the field, so we don't set the flag
				val.Set(reflect.Zero(val.Type()))
			default:
				if err := setValue(targetPath, val.Interface()); err != nil {
					return err
				}
				// Clear the field, so we don't set the flag
				empty := reflect.New(val.Type()).Elem()
				val.Set(empty)
			}
		}

		return reflectutils.SkipReflection
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. 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".
  2. Re-run `kops edit cluster` / `kops replace -f` with a spec validated by `kops validate` or YAML schema checks to normalize Quantity values.
  3. Upgrade kOps and k8s.io/apimachinery so Quantity serialization round-trips are consistent.

Example fix

// before (cluster spec yaml)
kubeScheduler:
  cpuRequest: "abc"
// after
kubeScheduler:
  cpuRequest: "100m"
Defensive patterns

Strategy: validation

Validate before calling

for _, f := range []string{"cpuRequest", "cpuLimit", "memoryRequest", "memoryLimit"} {
    if q := kubeSchedulerConfigField(q, f); q != nil {
        if _, err := strconv.ParseFloat(q.AsDec().String(), 64); err != nil {
            return fmt.Errorf("invalid quantity %s: %v", f, q)
        }
    }
}

Type guard

func validQuantity(q *resource.Quantity) bool { return q != nil && q.Value() >= 0 && q.AsDec() != nil }

Try / catch

if err := buildSchedulerConfig(obj, target); err != nil {
    if strings.Contains(err.Error(), "unable to convert from Quantity") {
        // reset the offending Quantity field to a valid default and retry
    }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/08878c3b50dcfc07. Report an issue: GitHub.