{"record":{"id":"80fdca810eaeb4df","repo":"kubernetes/kubernetes","slug":"unsupported-container-resource-v","errorCode":null,"errorMessage":"unsupported container resource : %v","messagePattern":"unsupported container resource : (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/api/v1/resource/helpers.go","lineNumber":142,"sourceCode":"\t\treturn convertResourceMemoryToString(container.Resources.Requests.Memory(), divisor)\n\tcase \"requests.ephemeral-storage\":\n\t\treturn convertResourceEphemeralStorageToString(container.Resources.Requests.StorageEphemeral(), divisor)\n\t}\n\t// handle extended standard resources with dynamic names\n\t// example: requests.hugepages-<pageSize> or limits.hugepages-<pageSize>\n\tif strings.HasPrefix(fs.Resource, \"requests.\") {\n\t\tresourceName := v1.ResourceName(strings.TrimPrefix(fs.Resource, \"requests.\"))\n\t\tif IsHugePageResourceName(resourceName) {\n\t\t\treturn convertResourceHugePagesToString(container.Resources.Requests.Name(resourceName, resource.BinarySI), divisor)\n\t\t}\n\t}\n\tif strings.HasPrefix(fs.Resource, \"limits.\") {\n\t\tresourceName := v1.ResourceName(strings.TrimPrefix(fs.Resource, \"limits.\"))\n\t\tif IsHugePageResourceName(resourceName) {\n\t\t\treturn convertResourceHugePagesToString(container.Resources.Limits.Name(resourceName, resource.BinarySI), divisor)\n\t\t}\n\t}\n\treturn \"\", fmt.Errorf(\"unsupported container resource : %v\", fs.Resource)\n}\n\n// convertResourceCPUToString converts cpu value to the format of divisor and returns\n// ceiling of the value.\nfunc convertResourceCPUToString(cpu *resource.Quantity, divisor resource.Quantity) (string, error) {\n\tc := int64(math.Ceil(float64(cpu.MilliValue()) / float64(divisor.MilliValue())))\n\treturn strconv.FormatInt(c, 10), nil\n}\n\n// convertResourceMemoryToString converts memory value to the format of divisor and returns\n// ceiling of the value.\nfunc convertResourceMemoryToString(memory *resource.Quantity, divisor resource.Quantity) (string, error) {\n\tm := int64(math.Ceil(float64(memory.Value()) / float64(divisor.Value())))\n\treturn strconv.FormatInt(m, 10), nil\n}\n\n// convertResourceHugePagesToString converts hugepages value to the format of divisor and returns\n// ceiling of the value.","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/kubernetes/kubernetes/blob/94c136764292cc5fac976c0de6587daaea56410f/pkg/api/v1/resource/helpers.go#L124-L160","documentation":"Returned by ExtractContainerResourceValue when the ResourceFieldSelector.Resource field doesn't match any of the supported resource selector paths. Supported values are limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory, requests.ephemeral-storage, and the hugepages variants (requests.hugepages-<size>, limits.hugepages-<size>). Any other value (e.g., limits.nvidia.com/gpu, requests.storage, a typo) triggers this error. This function is used by the kubelet and kubectl for Downward API resource field references.","triggerScenarios":"A pod spec uses a Downward API volume item or env var valueFrom.resourceFieldRef with a Resource value that doesn't match any of the known selector paths. The switch statement at line 114-127 exhausts all cases, the hugepages prefix checks at lines 130-140 don't match, and the error is returned. This typically happens when someone references a resource name that isn't a standard CPU/memory/ephemeral-storage/hugepages resource (e.g., an extended resource like GPU, or a typo like 'limit.cpu' instead of 'limits.cpu').","commonSituations":"Trying to expose a GPU or extended resource limit via the Downward API (not supported — only CPU/memory/ephemeral-storage/hugepages are exposed). Typographical errors in the resource path (e.g., 'limit.cpu' vs 'limits.cpu', 'request.memory' vs 'requests.memory'). Using a resource name without the limits./requests. prefix.","solutions":["Check the error message for the exact unsupported resource value.","Use only supported resource selectors: limits.cpu, requests.cpu, limits.memory, requests.memory, limits.ephemeral-storage, requests.ephemeral-storage, or limits.hugepages-<size>/requests.hugepages-<size>.","If you need to expose a non-standard resource (GPU, extended resource), use a different mechanism — the Downward API resourceFieldRef does not support extended resources.","Fix typos in the resource path (e.g., 'limit.cpu' -> 'limits.cpu')."],"exampleFix":"// before: unsupported resource in Downward API\nenv:\n  - name: GPU_LIMIT\n    valueFrom:\n      resourceFieldRef:\n        containerName: my-container\n        resource: limits.nvidia.com/gpu  # not supported\n\n// after: use a supported resource\nenv:\n  - name: CPU_LIMIT\n    valueFrom:\n      resourceFieldRef:\n        containerName: my-container\n        resource: limits.cpu","handlingStrategy":"validation","validationCode":"// Validate the resource field selector before using it in a Downward API reference\nvar supportedResourceSelectors = map[string]bool{\n    \"limits.cpu\": true, \"requests.cpu\": true,\n    \"limits.memory\": true, \"requests.memory\": true,\n    \"limits.ephemeral-storage\": true, \"requests.ephemeral-storage\": true,\n}\n\nfunc isSupportedResourceSelector(resource string) bool {\n    if supportedResourceSelectors[resource] {\n        return true\n    }\n    if strings.HasPrefix(resource, \"requests.hugepages-\") || strings.HasPrefix(resource, \"limits.hugepages-\") {\n        return true\n    }\n    return false\n}\n\n// Usage:\nif !isSupportedResourceSelector(fs.Resource) {\n    return fmt.Errorf(\"unsupported container resource: %s\", fs.Resource)\n}","typeGuard":null,"tryCatchPattern":"value, err := resource.ExtractContainerResourceValue(fs, container)\nif err != nil {\n    if strings.Contains(err.Error(), \"unsupported container resource\") {\n        klog.Warningf(\"unsupported resource field selector %q — only cpu/memory/ephemeral-storage/hugepages are supported\", fs.Resource)\n    }\n    return \"\", err\n}","preventionTips":["Only use limits.cpu, requests.cpu, limits.memory, requests.memory, limits.ephemeral-storage, requests.ephemeral-storage, or hugepages-* variants in resourceFieldRef.resource.","Double-check spelling: 'limits' not 'limit', 'requests' not 'request'.","The Downward API does not support extended resources (GPU, FPGA, etc.) — use a different mechanism for those.","Validate the resource selector string before submitting pod specs."],"tags":["downward-api","resource","container","field-selector","kubernetes"],"backgroundTag":null,"analyzedSha":"94c136764292cc5fac976c0de6587daaea56410f","analyzedAt":"2026-08-08T23:58:27.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}