{"record":{"id":"59723b952d3fb7c9","repo":"kubernetes/kops","slug":"querying-imds-s-status-d","errorCode":null,"errorMessage":"querying IMDS %s: status %d","messagePattern":"querying IMDS (.+?): status (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/azure/azuremetadata/imds.go","lineNumber":85,"sourceCode":"\treq, err := http.NewRequestWithContext(ctx, \"GET\", imdsBaseURL+path, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating IMDS request: %w\", err)\n\t}\n\treq.Header.Add(\"Metadata\", \"True\")\n\n\tparams.Set(\"api-version\", imdsAPIVersion)\n\treq.URL.RawQuery = params.Encode()\n\n\tklog.V(4).Infof(\"Azure IMDS query: %q\", req.URL.String())\n\n\tresp, err := imdsHTTPClient.Do(req)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"querying IMDS %s: %w\", path, err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"querying IMDS %s: status %d\", path, resp.StatusCode)\n\t}\n\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"reading IMDS response: %w\", err)\n\t}\n\tklog.V(4).Infof(\"Azure IMDS response: %d bytes\", len(body))\n\n\tif err := json.Unmarshal(body, result); err != nil {\n\t\treturn fmt.Errorf(\"unmarshalling IMDS response: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// QueryComputeInstanceMetadata queries Azure IMDS for compute instance metadata.\n// https://learn.microsoft.com/en-us/azure/virtual-machines/instance-metadata-service#instance-metadata\nfunc QueryComputeInstanceMetadata(ctx context.Context) (*InstanceMetadata, error) {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/azure/azuremetadata/imds.go#L67-L103","documentation":"queryIMDS got an HTTP response from IMDS but the status code was not 200; it returns \"querying IMDS <path>: status <code>\". Common codes are 400 (bad/mismatched api-version or params), 404 (unknown path/version), 429 (throttled), and 5xx (IMDS internal issues). The library surfaces the numeric status so callers can distinguish these cases.","triggerScenarios":"queryIMDS receives resp.StatusCode != 200 from either /metadata/instance/compute (with format=json) or /metadata/attested/document (with nonce param), both pinned to api-version 2025-04-07.","commonSituations":"IMDS throttling (429) during large scale-up bursts; deprecated api-version returning 400/404; malformed nonce causing 400 on the attested endpoint; transient 503 from IMDS.","solutions":["Read the numeric status in the message: retry with backoff on 429/503, fix api-version on 400/404","Verify the pinned imdsAPIVersion (2025-04-07) is supported; upgrade kOps if Azure deprecated it","Check request shape: format=json for instance metadata, valid nonce for attested document","If throttled, reduce parallel IMDS calls during node boot"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"// Inspect the status carried in the wrapped error message\nfunc imdsStatus(err error) (int, bool) {\n    m := imdsStatusRe.FindStringSubmatch(err.Error())\n    if m == nil { return 0, false }\n    n, _ := strconv.Atoi(m[1])\n    return n, true\n}\nvar imdsStatusRe = regexp.MustCompile(`status (\\d+)`)","tryCatchPattern":"// Retry only throttling/server errors, fail fast on 4xx client errors\nif code, ok := imdsStatus(err); ok {\n    switch {\n    case code == 429 || code >= 500:\n        retryWithBackoff()\n    default: // 400/404: api-version or request problem\n        return fmt.Errorf(\"IMDS rejected request (status %d); check api-version\", code)\n    }\n}","preventionTips":["Track Azure IMDS api-version deprecations; upgrade kOps before versions retire","Rate-limit node provisioning to avoid IMDS 429s","Log the full wrapped error chain so the numeric status is visible","Use format=json and a proper nonce exactly as the API expects"],"tags":["azure","imds","http-status","throttling"],"backgroundTag":"http-429-too-many-requests","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}