@@ -26,6 +26,8 @@ import (
2626)
2727
2828const (
29+ // ResourceAMDGPU is the name of the AMD GPU resource.
30+ ResourceAMDGPU = "amd.com/gpu"
2931 // ResourceNvidiaGPU is the name of the Nvidia GPU resource.
3032 ResourceNvidiaGPU = "nvidia.com/gpu"
3133 // ResourceDirectX is the name of the DirectX resource on windows.
@@ -35,6 +37,14 @@ const (
3537 DefaultGPUType = "nvidia-tesla-k80"
3638)
3739
40+ // Centralized list of all known GPU vendor extended resource names.
41+ // Extend this slice if new vendor resource names are added.
42+ var GPUVendorResourceNames = []apiv1.ResourceName {
43+ ResourceNvidiaGPU ,
44+ ResourceAMDGPU ,
45+ ResourceDirectX ,
46+ }
47+
3848const (
3949 // MetricsGenericGPU - for when there is no information about GPU type
4050 MetricsGenericGPU = "generic"
@@ -109,23 +119,53 @@ func validateGpuType(availableGPUTypes map[string]struct{}, gpu string) string {
109119// if the drivers are installed and GPU is ready to use.
110120func NodeHasGpu (GPULabel string , node * apiv1.Node ) bool {
111121 _ , hasGpuLabel := node .Labels [GPULabel ]
112- gpuAllocatable , hasGpuAllocatable := node .Status .Allocatable [ResourceNvidiaGPU ]
113- return hasGpuLabel || (hasGpuAllocatable && ! gpuAllocatable .IsZero ())
122+ if hasGpuLabel {
123+ return true
124+ }
125+ // Check for extended resources as well
126+ for _ , gpuVendorResourceName := range GPUVendorResourceNames {
127+ gpuAllocatable , hasGpuAllocatable := node .Status .Allocatable [gpuVendorResourceName ]
128+ if hasGpuAllocatable && ! gpuAllocatable .IsZero () {
129+ return true
130+ }
131+ }
132+ return false
114133}
115134
116135// PodRequestsGpu returns true if a given pod has GPU request.
117136func PodRequestsGpu (pod * apiv1.Pod ) bool {
118137 podRequests := podutils .PodRequests (pod )
119- _ , gpuFound := podRequests [ResourceNvidiaGPU ]
120- return gpuFound
138+ for _ , gpuVendorResourceName := range GPUVendorResourceNames {
139+ if _ , found := podRequests [gpuVendorResourceName ]; found {
140+ return true
141+ }
142+ }
143+ return false
144+ }
145+
146+ // DetectNodeGPUResourceName inspects the node's allocatable resources and returns the first
147+ // known GPU extended resource name that has non-zero allocatable. Falls back to Nvidia for
148+ // backward compatibility if none are found but a GPU label is present.
149+ func DetectNodeGPUResourceName (node * apiv1.Node ) apiv1.ResourceName {
150+ for _ , rn := range GPUVendorResourceNames {
151+ if qty , ok := node .Status .Allocatable [rn ]; ok && ! qty .IsZero () {
152+ return rn
153+ }
154+ }
155+ // Fallback: preserve previous behavior (defaulting to Nvidia) if label existed
156+ return ResourceNvidiaGPU
121157}
122158
123159// GetNodeGPUFromCloudProvider returns the GPU the node has. Returned GPU has the GPU label of the
124160// passed in cloud provider. If the node doesn't have a GPU, returns nil.
125161func GetNodeGPUFromCloudProvider (provider cloudprovider.CloudProvider , node * apiv1.Node ) * cloudprovider.GpuConfig {
126162 gpuLabel := provider .GPULabel ()
127163 if NodeHasGpu (gpuLabel , node ) {
128- return & cloudprovider.GpuConfig {Label : gpuLabel , Type : node .Labels [gpuLabel ], ExtendedResourceName : ResourceNvidiaGPU }
164+ return & cloudprovider.GpuConfig {
165+ Label : gpuLabel ,
166+ Type : node .Labels [gpuLabel ],
167+ ExtendedResourceName : DetectNodeGPUResourceName (node ),
168+ }
129169 }
130170 return nil
131171}
0 commit comments