kubernetes/kops · error

reading primary MAC address from ec2 metadata: %w

Error message

reading primary MAC address from ec2 metadata: %w

What it means

Thrown when io.ReadAll(resp.Content) fails after a successful GetMetadata('mac') — i.e. the IMDS response body could not be fully read (connection dropped mid-read, truncated response, IO error on the HTTP body stream).

Source

Thrown at nodeup/pkg/model/networking/eni_networking.go:201

}

// primaryInterfaceName gives the name of the primary network interface. It gets the MAC address
// of the primary ENI (device-number 0) from the IMDS item "mac". Then it compares this MAC
// address with the physical network interfaces in sysfs.
func primaryInterfaceName(ctx context.Context) (string, error) {
	config, err := awsconfig.LoadDefaultConfig(ctx)
	if err != nil {
		return "", fmt.Errorf("loading AWS config: %w", err)
	}
	metadata := imds.NewFromConfig(config)
	resp, err := metadata.GetMetadata(ctx, &imds.GetMetadataInput{Path: "mac"})
	if err != nil {
		return "", fmt.Errorf("getting primary MAC address from ec2 metadata: %w", err)
	}
	defer resp.Content.Close()
	mac, err := io.ReadAll(resp.Content)
	if err != nil {
		return "", fmt.Errorf("reading primary MAC address from ec2 metadata: %w", err)
	}

	return findPhysicalInterfaceByMAC("/sys/class/net", strings.TrimSpace(string(mac)))
}

// findPhysicalInterfaceByMAC gives the name of the physical network interface that has the
// specified MAC address. The function ignores the virtual interfaces (veths, bridges, VLANs),
// because a virtual interface can have the same MAC address as a physical interface. The
// function gives an error if it does not find exactly one physical interface with this MAC
// address.
func findPhysicalInterfaceByMAC(sysClassNet string, mac string) (string, error) {
	entries, err := os.ReadDir(sysClassNet)
	if err != nil {
		return "", fmt.Errorf("reading %s: %w", sysClassNet, err)
	}

	var matches []string
	for _, entry := range entries {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Re-run nodeup — a one-off IMDS read interruption is usually transient
  2. Check for IMDS rate limiting/many concurrent clients and add backoff
  3. Verify the ENA driver and link-local connectivity health (dmesg for ena errors)
  4. If persistent, inspect for network interception of 169.254.169.254 traffic
Defensive patterns

Strategy: retry

Try / catch

mac, err := io.ReadAll(resp.Content)
if err != nil {
    return "", fmt.Errorf("reading primary MAC address from ec2 metadata: %w", err) // callers should retry nodeup
}

Prevention

When it happens

Trigger: The IMDS HTTP response body stream errors during io.ReadAll: connection reset by the metadata service mid-response, read timeout on the body, or an interrupted local link-local connection.

Common situations: Flaky link-local networking on the instance, IMDS connection reset under high concurrency (many parallel IMDS clients), intermittent network driver issues right after boot.

Related errors


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