Repository: kubernetes/kubernetes
File: pkg/kubelet/cm/dra/manager.go (Go)

Code before:
	}

	return nil
}

func lookupClaimRequest(claims []*drapb.Claim, claimUID string) *drapb.Claim {
	for _, claim := range claims {
		if claim.Uid == claimUID {
			return claim
		}
	}
	return nil
}

// GetResources gets a ContainerInfo object from the claimInfo cache.
// This information is used by the caller to update a container config.
func (m *Manager) GetResources(pod *v1.Pod, container *v1.Container) (*ContainerInfo, error) {
	cdiDevices := []kubecontainer.CDIDevice{}

	// claimRequests maps claimName -> []requestNames for this container
	claimRequests := make(map[string][]string)

	// Collect regular ResourceClaims
	containerClaimsMap := make(map[string]string, len(container.Resources.Claims))
	for _, claim := range container.Resources.Claims {
		containerClaimsMap[claim.Name] = claim.Request
	}

	for i := range pod.Spec.ResourceClaims {
		podClaim := &pod.Spec.ResourceClaims[i]
		request, ok := containerClaimsMap[podClaim.Name]
		if !ok {
			continue
		}

		claimName, _, err := resourceclaim.Name(pod, podClaim)
		if err != nil {
			// No wrapping, error is already informative.
			return nil, err
		}
		// The claim name might be nil if no underlying resource claim
		// was generated for the referenced claim. There are valid use
		// cases when this might happen, so we simply skip it.
		if claimName == nil {
			continue
		}

		claimRequests[*claimName] = append(claimRequests[*claimName], request)
	}

	// Collect extended resource claims if feature is enabled

Review comment (suggestion):
This is a breaking change. If a container references the same claim name multiple times (e.g., requesting different request names), later references will override earlier ones, causing the earlier requests to be discarded.

The following definition is permissible:
```
resources:
  claims:
  - name: gpu
    request: "device-0"
  - name: gpu
    request: "device-1"
```

Code after:
		return err
	}

	return nil
}

func lookupClaimRequest(claims []*drapb.Claim, claimUID string) *drapb.Claim {
	for _, claim := range claims {
		if claim.Uid == claimUID {
			return claim
		}
	}
	return nil
}

// GetResources gets a ContainerInfo object from the claimInfo cache.
// This information is used by the caller to update a container config.
func (m *Manager) GetResources(pod *v1.Pod, container *v1.Container) (*ContainerInfo, error) {
	cdiDevices := []kubecontainer.CDIDevice{}

	// claimRequests maps claimName -> []requestNames for this container
	claimRequests := make(map[string][]string)

	// Collect regular ResourceClaims
	containerClaimsMap := make(map[string][]string, len(container.Resources.Claims))
	for _, claim := range container.Resources.Claims {
		if _, ok := containerClaimsMap[claim.Name]; !ok {
			containerClaimsMap[claim.Name] = []string{}
		}
		containerClaimsMap[claim.Name] = append(containerClaimsMap[claim.Name], claim.Request)
	}

	for i := range pod.Spec.ResourceClaims {
		podClaim := &pod.Spec.ResourceClaims[i]
		requests, ok := containerClaimsMap[podClaim.Name]
		if !ok {
			continue
		}

		claimName, _, err := resourceclaim.Name(pod, podClaim)
		if err != nil {
			// No wrapping, error is already informative.
			return nil, err
		}
		// The claim name might be nil if no underlying resource claim
		// was generated for the referenced claim. There are valid use
		// cases when this might happen, so we simply skip it.
		if claimName == nil {
			continue
		}