kubernetes/kops · error

unexpected IP address type: %s

Error message

unexpected IP address type: %s

What it means

subnet.SplitInto divides a parent CIDR into N equal child subnets. It supports IPv4 (4-byte) parents only; the IPv6 branch is not implemented, and any parent that is neither handled type triggers this error. Called via the SplitInto1/2/4/8 convenience wrappers.

Source

Thrown at pkg/util/subnet/subnet.go:87

func SplitInto(additionalBits uint, parent *net.IPNet) ([]*net.IPNet, error) {
	networkLength, _ := parent.Mask.Size()
	networkLength += int(additionalBits)

	var subnets []*net.IPNet
	for i := 0; i < 1<<additionalBits; i++ {
		ip4 := parent.IP.To4()
		if ip4 != nil {
			n := binary.BigEndian.Uint32(ip4)
			n += uint32(i) << uint(32-networkLength)
			subnetIP := make(net.IP, len(ip4))
			binary.BigEndian.PutUint32(subnetIP, n)

			subnets = append(subnets, &net.IPNet{
				IP:   subnetIP,
				Mask: net.CIDRMask(networkLength, 32),
			})
		} else {
			return nil, fmt.Errorf("unexpected IP address type: %s", parent)
		}
	}

	return subnets, nil
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Pass an IPv4 CIDR (net.ParseCIDR("10.0.0.0/16")) to SplitInto
  2. For IPv6 networks, implement/handle IPv6 subnetting separately instead of using SplitInto
  3. Verify the parent IPNet was constructed correctly and its IP is To4()-convertible before calling

Example fix

// before
parent, _ := net.ParseCIDR("2001:db8::/32")
subnets, err := subnet.SplitInto4(parent) // IPv6 not supported
// after
parent, _ := net.ParseCIDR("10.0.0.0/16")
subnets, err := subnet.SplitInto4(parent)
Defensive patterns

Strategy: validation

Validate before calling

// Ensure parent is IPv4 before SplitInto
if parent.IP.To4() == nil {
	return fmt.Errorf("SplitInto requires IPv4, got %s", parent)
}

Type guard

func isIPv4Net(n *net.IPNet) bool {
	return n != nil && n.IP.To4() != nil
}

Prevention

When it happens

Trigger: Calling SplitInto (or SplitInto2/4/8) with a parent net.IPNet whose IP is not a valid IPv4 address — e.g. an IPv6 CIDR like 2001:db8::/32, or an IPNet with a nil/zero-length IP.

Common situations: Dual-stack or IPv6 cluster configs passing IPv6 CIDRs into an IPv4-only helper, or a subnet CIDR built incorrectly (empty IP) from parsed input.

Related errors


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