mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Fix pod object update that may cause data race
This commit is contained in:
parent
8b2dae57d4
commit
f66e8848ee
@ -2701,7 +2701,7 @@ func (kl *Kubelet) handlePodResourcesResize(pod *v1.Pod) {
|
|||||||
//TODO(vinaykul,InPlacePodVerticalScaling): Can we recover from this in some way? Investigate
|
//TODO(vinaykul,InPlacePodVerticalScaling): Can we recover from this in some way? Investigate
|
||||||
klog.ErrorS(err, "SetPodAllocation failed", "pod", klog.KObj(pod))
|
klog.ErrorS(err, "SetPodAllocation failed", "pod", klog.KObj(pod))
|
||||||
}
|
}
|
||||||
*pod = *updatedPod
|
pod = updatedPod
|
||||||
}
|
}
|
||||||
if resizeStatus != "" {
|
if resizeStatus != "" {
|
||||||
// Save resize decision to checkpoint
|
// Save resize decision to checkpoint
|
||||||
|
@ -2585,8 +2585,10 @@ func TestHandlePodResourcesResize(t *testing.T) {
|
|||||||
tt.pod.Spec.Containers[0].Resources.Requests = tt.newRequests
|
tt.pod.Spec.Containers[0].Resources.Requests = tt.newRequests
|
||||||
tt.pod.Status.ContainerStatuses[0].AllocatedResources = v1.ResourceList{v1.ResourceCPU: cpu1000m, v1.ResourceMemory: mem1000M}
|
tt.pod.Status.ContainerStatuses[0].AllocatedResources = v1.ResourceList{v1.ResourceCPU: cpu1000m, v1.ResourceMemory: mem1000M}
|
||||||
kubelet.handlePodResourcesResize(tt.pod)
|
kubelet.handlePodResourcesResize(tt.pod)
|
||||||
assert.Equal(t, tt.expectedAllocations, tt.pod.Status.ContainerStatuses[0].AllocatedResources, tt.name)
|
updatedPod, found := kubelet.podManager.GetPodByName(tt.pod.Namespace, tt.pod.Name)
|
||||||
assert.Equal(t, tt.expectedResize, tt.pod.Status.Resize, tt.name)
|
assert.True(t, found, "expected to find pod %s", tt.pod.Name)
|
||||||
|
assert.Equal(t, tt.expectedAllocations, updatedPod.Status.ContainerStatuses[0].AllocatedResources, tt.name)
|
||||||
|
assert.Equal(t, tt.expectedResize, updatedPod.Status.Resize, tt.name)
|
||||||
testKubelet.fakeKubeClient.ClearActions()
|
testKubelet.fakeKubeClient.ClearActions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user