Merge pull request #116739 from moshe010/clone-cdi-devices

kubelet dra: lock before getting claimInfo CDIDevices and annotations fields
This commit is contained in:
Kubernetes Prow Robot 2023-07-07 06:31:04 -07:00 committed by GitHub
commit 7581ae8123
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -978,6 +978,7 @@ func (cm *containerManagerImpl) GetDynamicResources(pod *v1.Pod, container *v1.C
} }
for _, containerClaimInfo := range containerClaimInfos { for _, containerClaimInfo := range containerClaimInfos {
var claimResources []*podresourcesapi.ClaimResource var claimResources []*podresourcesapi.ClaimResource
containerClaimInfo.RLock()
// TODO: Currently we maintain a list of ClaimResources, each of which contains // TODO: Currently we maintain a list of ClaimResources, each of which contains
// a set of CDIDevices from a different kubelet plugin. In the future we may want to // a set of CDIDevices from a different kubelet plugin. In the future we may want to
// include the name of the kubelet plugin and/or other types of resources that are // include the name of the kubelet plugin and/or other types of resources that are
@ -989,6 +990,7 @@ func (cm *containerManagerImpl) GetDynamicResources(pod *v1.Pod, container *v1.C
} }
claimResources = append(claimResources, &podresourcesapi.ClaimResource{CDIDevices: cdiDevices}) claimResources = append(claimResources, &podresourcesapi.ClaimResource{CDIDevices: cdiDevices})
} }
containerClaimInfo.RUnlock()
containerDynamicResource := podresourcesapi.DynamicResource{ containerDynamicResource := podresourcesapi.DynamicResource{
ClassName: containerClaimInfo.ClassName, ClassName: containerClaimInfo.ClassName,
ClaimName: containerClaimInfo.ClaimName, ClaimName: containerClaimInfo.ClaimName,

View File

@ -233,6 +233,7 @@ func (m *ManagerImpl) GetResources(pod *v1.Pod, container *v1.Container) (*Conta
return nil, fmt.Errorf("unable to get resource for namespace: %s, claim: %s", pod.Namespace, claimName) return nil, fmt.Errorf("unable to get resource for namespace: %s, claim: %s", pod.Namespace, claimName)
} }
claimInfo.RLock()
klog.V(3).InfoS("Add resource annotations", "claim", claimName, "annotations", claimInfo.annotations) klog.V(3).InfoS("Add resource annotations", "claim", claimName, "annotations", claimInfo.annotations)
annotations = append(annotations, claimInfo.annotations...) annotations = append(annotations, claimInfo.annotations...)
for _, devices := range claimInfo.CDIDevices { for _, devices := range claimInfo.CDIDevices {
@ -240,6 +241,7 @@ func (m *ManagerImpl) GetResources(pod *v1.Pod, container *v1.Container) (*Conta
cdiDevices = append(cdiDevices, kubecontainer.CDIDevice{Name: device}) cdiDevices = append(cdiDevices, kubecontainer.CDIDevice{Name: device})
} }
} }
claimInfo.RUnlock()
} }
} }
@ -313,8 +315,8 @@ func (m *ManagerImpl) UnprepareResources(pod *v1.Pod) error {
resourceHandle.Data) resourceHandle.Data)
if err != nil { if err != nil {
return fmt.Errorf( return fmt.Errorf(
"NodeUnprepareResource failed, pod: %s, claim UID: %s, claim name: %s, CDI devices: %s, err: %+v", "NodeUnprepareResource failed, pod: %s, claim UID: %s, claim name: %s, resource handle: %s, err: %+v",
pod.Name, claimInfo.ClaimUID, claimInfo.ClaimName, claimInfo.CDIDevices, err) pod.Name, claimInfo.ClaimUID, claimInfo.ClaimName, resourceHandle.Data, err)
} }
klog.V(3).InfoS("NodeUnprepareResource succeeded", "response", response) klog.V(3).InfoS("NodeUnprepareResource succeeded", "response", response)
} }