kubernetes/kops · error

error parsing network cidr %q: %v

Error message

error parsing network cidr %q: %v

What it means

CIDRMap.MarkInUse records a CIDR string (from cluster/subnet config) as already allocated. The string must be a valid CIDR per net.ParseCIDR; if not, the map cannot track it and returns this error quoting the bad input.

Source

Thrown at pkg/util/subnet/cidrmap.go:35

package subnet

import (
	"encoding/binary"
	"fmt"
	"net"

	"k8s.io/klog/v2"
)

// CIDRMap is a helper structure to allocate unused CIDRs
type CIDRMap struct {
	used []net.IPNet
}

func (c *CIDRMap) MarkInUse(s string) error {
	_, cidr, err := net.ParseCIDR(s)
	if err != nil {
		return fmt.Errorf("error parsing network cidr %q: %v", s, err)
	}
	c.used = append(c.used, *cidr)
	return nil
}

func incrementIP(ip net.IP, mask net.IPMask) error {
	maskOnes, maskBits := mask.Size()

	if maskBits == 32 {
		ip4 := ip.To4()

		n := binary.BigEndian.Uint32(ip4)
		n += 1 << uint(32-maskOnes)
		binary.BigEndian.PutUint32(ip, n)
	} else {
		ipv6 := ip.To16()

		high := binary.BigEndian.Uint64(ipv6[0:8])

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Fix the offending CIDR string so it parses (valid IP + prefix, e.g. 10.0.0.0/16); validate with `ipcalc` or `netmask`
  2. Run `kops replace -f cluster.yaml` / `kops edit cluster` to correct the stored spec
  3. Ensure you pass full network CIDRs, not single host IPs or hostnames, into MarkInUse

Example fix

// before
err := cidrMap.MarkInUse("10.0.0.5")   // missing mask
// after
err := cidrMap.MarkInUse("10.0.0.0/16") // valid network CIDR
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate before MarkInUse
if _, _, err := net.ParseCIDR(s); err != nil {
	return fmt.Errorf("invalid CIDR %q: %w", s, err)
}

Type guard

func isCIDR(s string) bool {
	_, _, err := net.ParseCIDR(s)
	return err == nil
}

Prevention

When it happens

Trigger: Calling MarkInUse with a string like "10.0.0.1/33", "10.0.0.5" (no mask), "::1/129", or any hostname/garbage value — typically from cluster spec subnet CIDRs or non-CIDR network ranges.

Common situations: Hand-edited cluster spec with a typo'd subnet CIDR, passing an IP without a prefix length, mixing IPv4/IPv6 unexpectedly, or reading network CIDRs from a cloud API in a different format.

Related errors


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