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

  1. Supply a plain base-10 integer string, e.g. "42".
  2. Trim whitespace/suffixes (units) from the value before calling.
  3. Pre-validate with strconv.Atoi and surface a clear CLI error.
  4. 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

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


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