kubelet: Do not mutate pods in the pod manager

The pod manager is a cache and modifying objects returned from the
pod manager can cause race conditions in the Kubelet. In this case,
it causes static pod status from the mirror pod to leak back to
the config source, which means a static pod whose mirror pod is
set to a terminal phase (succeeded or failed) cannot restart.
This commit is contained in:
Clayton Coleman 2023-03-10 13:15:13 -06:00
parent fcfe5dfc21
commit aadb87bdcd
No known key found for this signature in database
GPG Key ID: CF7DB7FC943D3E0E

View File

@ -176,11 +176,14 @@ func (kl *Kubelet) GetPods() []*v1.Pod {
pods := kl.podManager.GetPods()
// a kubelet running without apiserver requires an additional
// update of the static pod status. See #57106
for _, p := range pods {
for i, p := range pods {
if kubelettypes.IsStaticPod(p) {
if status, ok := kl.statusManager.GetPodStatus(p.UID); ok {
klog.V(2).InfoS("Pod status updated", "pod", klog.KObj(p), "status", status.Phase)
// do not mutate the cache
p = p.DeepCopy()
p.Status = status
pods[i] = p
}
}
}