kubernetes/kops · error

cannot interpret %q value as resource.Quantity

Error message

cannot interpret %q value as resource.Quantity

What it means

Fields tagged resource.Quantity are parsed with apimachinery's resource.ParseQuantity. If the string is not a valid Kubernetes quantity (number with optional SI/binary suffix), this error is returned. Quantities must look like "128974848", "129e6", "129Mi", "1G", etc.

Source

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

		}

		name, value, hasValue := strings.Cut(newValue, "=")
		newV.FieldByIndex(fdName.Index).SetString(name)
		if hasValue {
			newV.FieldByIndex(fdValue.Index).SetString(value)
		}

	case "v1.Duration":
		duration, err := time.ParseDuration(newValue)
		if err != nil {
			return fmt.Errorf("cannot interpret %q value as v1.Duration", newValue)
		}
		newV = reflect.ValueOf(metav1.Duration{Duration: duration})

	case "resource.Quantity":
		quantity, err := resource.ParseQuantity(newValue)
		if err != nil {
			return fmt.Errorf("cannot interpret %q value as resource.Quantity", newValue)
		}
		newV = reflect.ValueOf(quantity)

	default:
		// This handles enums and other simple conversions
		newV = reflect.ValueOf(newValue)
		if newV.Type().ConvertibleTo(v.Type()) {
			newV = newV.Convert(v.Type())
		} else {
			return fmt.Errorf("unhandled type %q", t)
		}
	}

	v.Set(newV)
	return nil
}

func Unset(target interface{}, targetPath string) error {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Use valid quantity syntax: "8Gi", "8000Mi", "500m", "1G" — no spaces
  2. Use binary suffixes (Ki/Mi/Gi/Ti) for memory, decimal (k/M/G) or millicores (m) for CPU
  3. Verify with `kubectl` quantity rules (Kubernetes docs on resource quantities) before setting

Example fix

// before
kops set instancegroup nodes spec.machineMemory=16 GB
// after
kops set instancegroup nodes spec.machineMemory=16Gi
Defensive patterns

Strategy: validation

Validate before calling

q := "16Gi"
if _, err := resource.ParseQuantity(q); err != nil {
	return fmt.Errorf("invalid quantity %q: %v", q, err)
}

Type guard

func isValidQuantity(s string) bool {
	_, err := resource.ParseQuantity(s)
	return err == nil
}

Try / catch

if err := doSet(); err != nil && strings.Contains(err.Error(), "as resource.Quantity") {
	// fix to valid quantity like 16Gi / 500m
}

Prevention

When it happens

Trigger: `kops set ... spec.memory=8GB` or similar on quantity-tagged fields with invalid strings such as "8 GB" (space), "8gigs", "big", or empty template values.

Common situations: Using human-friendly spellings instead of Kubernetes quantity syntax (Gi vs GB confusion), whitespace from YAML/CLI parsing, or setting CPU values like "0.5 cores".

Related errors


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