{"record":{"id":"45f9e5761a70223c","repo":"kubernetes/kops","slug":"failed-to-get-instance-metadata-type-w","errorCode":null,"errorMessage":"failed to get instance metadata type: %w","messagePattern":"failed to get instance metadata type: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/nodeup/command.go","lineNumber":422,"sourceCode":"\t\t}\n\t}\n\treturn nil\n}\n\nfunc getMachineType(ctx context.Context) (string, error) {\n\tconfig, err := awsconfig.LoadDefaultConfig(ctx)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to load AWS config: %w\", err)\n\t}\n\n\tmetadata := imds.NewFromConfig(config)\n\n\t// Get the actual instance type by querying the EC2 instance metadata service.\n\tresult, err := metadata.GetMetadata(ctx, &imds.GetMetadataInput{\n\t\tPath: \"instance-type\",\n\t})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get instance metadata type: %w\", err)\n\t}\n\tdefer result.Content.Close()\n\tinstanceTypeName, err := io.ReadAll(result.Content)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to read instance metadata response: %w\", err)\n\t}\n\treturn string(instanceTypeName), err\n}\n\nfunc completeWarmingLifecycleAction(ctx context.Context, cloud *awsup.Cloud, modelContext *model.NodeupModelContext) error {\n\tasgName := modelContext.BootConfig.InstanceGroupName + \".\" + modelContext.NodeupConfig.ClusterName\n\thookName := \"kops-warmpool\"\n\thooks, err := cloud.DescribeLifecycleHooks(ctx, &autoscaling.DescribeLifecycleHooksInput{\n\t\tAutoScalingGroupName: &asgName,\n\t\tLifecycleHookNames:   []string{hookName},\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to find lifecycle hook %q: %w\", hookName, err)","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/nodeup/command.go#L404-L440","documentation":"After loading AWS config, getMachineType queries the EC2 Instance Metadata Service at path 'instance-type' via the SDK's IMDS client. If that GetMetadata call fails (network, token, or endpoint error), nodeup wraps it with this message and cannot determine the machine type.","triggerScenarios":"imds.NewFromConfig(config).GetMetadata(ctx, {Path: \"instance-type\"}) returns an error: IMDS endpoint unreachable, IMDSv2 token request denied, metadata service disabled on the instance, or transient network failure.","commonSituations":"Nodeup running inside a container/network namespace that blocks 169.254.169.254; IMDSv2 with hop limit 1 while nodeup is one hop away; instance launched with metadata disabled (HttpEndpoint disabled); brief IMDS throttling at instance boot.","solutions":["Verify metadata access from the node: curl -H \"X-aws-ec2-metadata-token: $TOKEN\" http://169.254.169.254/latest/meta-data/instance-type.","Raise --http-put-response-hop-limit to 2+ if nodeup runs in a container.","Re-enable the metadata endpoint if the instance was launched with metadata disabled.","Retry after transient failure — IMDS token fetches can be throttled during fleet-wide scale-up events."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"curl -sf http://169.254.169.254/latest/meta-data/instance-type || echo 'IMDS unreachable pre-flight failure'","typeGuard":null,"tryCatchPattern":"result, err := metadata.GetMetadata(ctx, &imds.GetMetadataInput{Path: \"instance-type\"})\nif err != nil {\n    var rerr *retry.Error\n    if errors.As(err, &rerr) {\n        // throttled/transient: back off and retry with jitter\n    }\n    return fmt.Errorf(\"IMDS metadata query failed: %w\", err)\n}","preventionTips":["Allow link-local 169.254.169.254 in node network policies and firewalls.","Configure IMDSv2 with adequate hop limit for containerized workloads.","Use the SDK's default retryer and avoid hammering IMDS concurrently at boot.","Keep metadata HttpEndpoint enabled on node launch templates."],"tags":["aws","imds","network","nodeup"],"backgroundTag":"imds-unreachable","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"}