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
- Fix the offending CIDR string so it parses (valid IP + prefix, e.g. 10.0.0.0/16); validate with `ipcalc` or `netmask`
- Run `kops replace -f cluster.yaml` / `kops edit cluster` to correct the stored spec
- 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
- Always store network ranges as CIDRs including the /mask
- Validate cluster spec CIDR fields with a linter before applying
- Never pass bare IPs or hostnames where CIDRs are expected
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
- error parsing CIDR %q: %v
- invalid subnet %q CIDR: %q
- subnet %q has unexpected CIDR %q
- linode VPC requires at least one subnet
- linode subnet %q requires a CIDR
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/a32774378ac914c0.
Report an issue: GitHub.