{"record":{"id":"27eff1813181ce37","repo":"kubernetes/kops","slug":"cannot-allocate-cidr-of-size-v","errorCode":null,"errorMessage":"cannot allocate CIDR of size %v","messagePattern":"cannot allocate CIDR of size (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/subnet/cidrmap.go","lineNumber":111,"sourceCode":"\t\tif err := incrementIP(candidate.IP, mask); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\t// Check we're still in the range we're drawing from\n\t\tif !cidrsOverlap(cidr, &candidate) {\n\t\t\tklog.Infof(\"candidate CIDR %v is not in CIDR %v\", candidate, cidr)\n\t\t\tbreak\n\t\t}\n\n\t\tif !c.isInUse(&candidate) {\n\t\t\tif err := c.MarkInUse(candidate.String()); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\treturn &candidate, nil\n\t\t}\n\t}\n\n\treturn nil, fmt.Errorf(\"cannot allocate CIDR of size %v\", mask)\n}\n\nfunc (c *CIDRMap) isInUse(n *net.IPNet) bool {\n\tfor i := range c.used {\n\t\tif cidrsOverlap(&c.used[i], n) {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n// cidrsOverlap returns true if and only if the two CIDRs are non-disjoint\nfunc cidrsOverlap(l, r *net.IPNet) bool {\n\treturn l.Contains(r.IP) || r.Contains(l.IP)\n}\n","sourceCodeStart":93,"sourceCodeEnd":127,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/util/subnet/cidrmap.go#L93-L127","documentation":"Allocate walks the parent CIDR and returns the first free subnet matching the requested mask size. If it exhausts every candidate position without finding a non-overlapping subnet (or the requested mask cannot fit in the parent at all), it fails with this error naming the requested mask size.","triggerScenarios":"Calling Allocate with a mask so large (subnets bigger than the parent range) or a parent range so fragmented by in-use CIDRs that no subnet of the requested size fits.","commonSituations":"Requesting /16 subnets from a /16 parent, an IPv4 parent when a huge mask is requested, or many pre-existing subnets (via MarkInUse) that fragment the space in small VPCs.","solutions":["Reduce requested subnet size (use a larger prefix number, e.g. /20 instead of /16) or enlarge the parent CIDR","Check what is already marked in-use (cluster spec subnets, VPC CIDRs) and free/consolidate overlaps","Verify the mask fits the parent range mathematically before allocating (host bits available >= requested size)"],"exampleFix":"// before\n// parent 10.0.0.0/16, requesting a /16-sized subnet\nsubnet, err := cidrMap.Allocate(\"10.0.0.0/16\", net.CIDRMask(16, 32))\n// after\nsubnet, err := cidrMap.Allocate(\"10.0.0.0/16\", net.CIDRMask(20, 32))","handlingStrategy":"validation","validationCode":"// Check requested mask fits in parent before Allocate\n_, parent, _ := net.ParseCIDR(from)\nones, _ := parent.Mask.Size()\nreqOnes, reqBits := mask.Size()\nif reqOnes < ones || reqBits != len(parent.IP)*8 {\n\treturn fmt.Errorf(\"mask /%d too large for parent /%d\", reqOnes, ones)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Size requested subnets smaller than the parent range (more host bits)","Account for already-marked in-use CIDRs that fragment the space","Prefer larger parent pools in small/fragmented VPCs"],"tags":["cidr","network","capacity"],"backgroundTag":"cidr-space-exhausted","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"}