kubernetes/kops · error

cannot interpret %q value as unsigned integer

Error message

cannot interpret %q value as unsigned integer

What it means

reflectutils.setType converts a string value into the Go type of the target struct field. When the field's type tag is an unsigned integer kind (uint, uint16, uint32, uint64) but strconv.Atoi cannot parse the string as an integer, it returns this error instead of panicking. It indicates the value supplied (e.g. via kops set / cluster spec mutation) is not a valid unsigned integer.

Source

Thrown at util/pkg/reflectutils/access.go:236

				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)
			if err != nil {
				return fmt.Errorf("cannot interpret %q value as int64", newValue)
			}
			v64 := int64(v)
			newV = reflect.ValueOf(v64)
		default:
			panic("missing case in int switch")
		}

	case "uint64", "uint32", "uint16", "uint":
		v, err := strconv.Atoi(newValue)
		if err != nil {
			return fmt.Errorf("cannot interpret %q value as unsigned integer", newValue)
		}

		switch t {
		case "uint":
			newV = reflect.ValueOf(v)
		case "uint16":
			v16 := uint16(v)
			newV = reflect.ValueOf(v16)
		case "uint32":
			v32 := uint32(v)
			newV = reflect.ValueOf(v32)
		case "uint64":
			v64 := uint64(v)
			newV = reflect.ValueOf(v64)
		default:
			panic("missing case in uint switch")
		}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Pass a plain base-10 integer without units or quotes, e.g. `--set spec.maxSize=3`
  2. Check the target field's type in the API docs to confirm it is an integer field
  3. If a quantity with units is intended, use the matching string-form field (e.g. memory quantities are resource.Quantity, not uint)
  4. Fix template/variable substitution so the value is not empty at set time

Example fix

// before
kops set cluster spec.kubelet.nodeStatusMaxWorkers=high
// after
kops set cluster spec.kubelet.nodeStatusMaxWorkers=150
Defensive patterns

Strategy: validation

Validate before calling

v := os.Args[valueIdx]
if _, err := strconv.ParseUint(v, 10, 64); err != nil {
	return fmt.Errorf("%q is not a valid unsigned integer", v)
}

Type guard

func isUint(s string) bool { _, err := strconv.ParseUint(s, 10, 64); return err == nil }

Prevention

When it happens

Trigger: Calling kops set with a field path targeting a uint-typed field and passing a non-numeric string, e.g. `kops set cluster spec.kubelet.nodeStatusMaxWorkers=many` or `kops set instancegroup ... spec.maxSize=abc`.

Common situations: Typos or pasted values with units ('2GB', '300m'), empty strings from templating/variable substitution, or accidentally setting an instance-group maxSize/maxCount to a name instead of a number.

Related errors


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