Skip to content

Commit

Permalink
kubelet: Do not mutate pods in the pod manager
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smarterclayton authored and davidwtf committed May 11, 2023
1 parent 953be89 commit 7ececb3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/kubelet/kubelet_getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,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
}
}
}
Expand Down

0 comments on commit 7ececb3

Please sign in to comment.