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
- Re-run nodeup — a one-off IMDS read interruption is usually transient
- Check for IMDS rate limiting/many concurrent clients and add backoff
- Verify the ENA driver and link-local connectivity health (dmesg for ena errors)
- 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
- Retry IMDS reads with backoff on transient IO errors
- Limit concurrent IMDS clients on the node
- Monitor for link-local connection resets in node logs
- Re-run nodeup after transient boot-time network storms
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
- error querying ec2 metadata service (for region): %v
- failed to load AWS config: %w
- failed to get local-ipv4 address from ec2 metadata: %w
- getting primary MAC address from ec2 metadata: %w
- failed to get region from ec2 metadata: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/858a68c4adac5a6f.
Report an issue: GitHub.