{"record":{"id":"a32774378ac914c0","repo":"kubernetes/kops","slug":"error-parsing-network-cidr-q-v","errorCode":null,"errorMessage":"error parsing network cidr %q: %v","messagePattern":"error parsing network cidr %q: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/subnet/cidrmap.go","lineNumber":35,"sourceCode":"package subnet\n\nimport (\n\t\"encoding/binary\"\n\t\"fmt\"\n\t\"net\"\n\n\t\"k8s.io/klog/v2\"\n)\n\n// CIDRMap is a helper structure to allocate unused CIDRs\ntype CIDRMap struct {\n\tused []net.IPNet\n}\n\nfunc (c *CIDRMap) MarkInUse(s string) error {\n\t_, cidr, err := net.ParseCIDR(s)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error parsing network cidr %q: %v\", s, err)\n\t}\n\tc.used = append(c.used, *cidr)\n\treturn nil\n}\n\nfunc incrementIP(ip net.IP, mask net.IPMask) error {\n\tmaskOnes, maskBits := mask.Size()\n\n\tif maskBits == 32 {\n\t\tip4 := ip.To4()\n\n\t\tn := binary.BigEndian.Uint32(ip4)\n\t\tn += 1 << uint(32-maskOnes)\n\t\tbinary.BigEndian.PutUint32(ip, n)\n\t} else {\n\t\tipv6 := ip.To16()\n\n\t\thigh := binary.BigEndian.Uint64(ipv6[0:8])","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/util/subnet/cidrmap.go#L17-L53","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nerr := cidrMap.MarkInUse(\"10.0.0.5\")   // missing mask\n// after\nerr := cidrMap.MarkInUse(\"10.0.0.0/16\") // valid network CIDR","handlingStrategy":"validation","validationCode":"// Pre-validate before MarkInUse\nif _, _, err := net.ParseCIDR(s); err != nil {\n\treturn fmt.Errorf(\"invalid CIDR %q: %w\", s, err)\n}","typeGuard":"func isCIDR(s string) bool {\n\t_, _, err := net.ParseCIDR(s)\n\treturn err == nil\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["cidr","network","validation"],"backgroundTag":"invalid-cidr-notation","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}