kubernetes/kops · error
cannot interpret %q value as integer
Error message
cannot interpret %q value as integer
What it means
The target field is of type int; strconv.Atoi failed on the supplied string, so it is not a valid base-10 integer (may be empty, contain units, or overflow on 32-bit platforms).
Source
Thrown at util/pkg/reflectutils/access.go:205
var newV reflect.Value
switch t {
case "string":
newV = reflect.ValueOf(newValue)
case "bool":
b, err := strconv.ParseBool(newValue)
if err != nil {
return fmt.Errorf("cannot interpret %q value as bool", newValue)
}
newV = reflect.ValueOf(b)
case "int64", "int32", "int16", "int":
switch t {
case "int":
v, err := strconv.Atoi(newValue)
if err != nil {
return fmt.Errorf("cannot interpret %q value as integer", newValue)
}
newV = reflect.ValueOf(v)
case "int16":
v, err := strconv.ParseInt(newValue, 10, 16)
if err != nil {
return fmt.Errorf("cannot interpret %q value as int16", newValue)
}
v16 := int16(v)
newV = reflect.ValueOf(v16)
case "int32":
v, err := strconv.ParseInt(newValue, 10, 32)
if err != nil {
return fmt.Errorf("cannot interpret %q value as int32", newValue)
}
v32 := int32(v)
newV = reflect.ValueOf(v32)
case "int64":
v, err := strconv.ParseInt(newValue, 10, 64)View on GitHub (pinned to 4c8573c808)
Solutions
- Supply a plain base-10 integer string, e.g. "42".
- Trim whitespace/suffixes (units) from the value before calling.
- Pre-validate with strconv.Atoi and surface a clear CLI error.
- If the field should accept sizes, change its type to resource.Quantity.
Example fix
// before SetString(&c, "spec.maxInstances", "1,000") // after SetString(&c, "spec.maxInstances", "1000")
Defensive patterns
Strategy: validation
Validate before calling
if _, err := strconv.Atoi(val); err != nil {
return fmt.Errorf("value %q is not a valid int", val)
} Type guard
func isGoInt(s string) bool {
_, err := strconv.Atoi(s)
return err == nil
} Try / catch
if err := SetString(&obj, path, val); err != nil {
if strings.Contains(err.Error(), "as integer") {
return fmt.Errorf("%q is not a plain base-10 integer", val)
}
return err
} Prevention
- Strip units/separators before setting integer fields.
- Trim shell whitespace and quotes.
- Use resource.Quantity fields for sizes instead of raw ints.
When it happens
Trigger: SetString(&obj, "spec.someInt", "12abc"), "", "1_000", or a value exceeding int range.
Common situations: Passing numbers with thousands separators or units ("1024MB") to integer fields via `kops set`; whitespace from shell quoting.
Related errors
- cannot interpret %q value as int16
- cannot interpret %q value as int32
- cannot interpret %q value as int64
- unable to parse sha: %q, %v
- unexpected integer value: %q
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/2a94cd7a3c1f4312.
Report an issue: GitHub.