From 69caf533f04642f21e05624790dd531fc49cea00 Mon Sep 17 00:00:00 2001 From: Yu-Ju Hong Date: Tue, 29 Nov 2016 14:57:17 -0800 Subject: [PATCH] kubelet: don't reject pods without adding them to the pod manager kubelet relies on the pod manager as a cache of the pods in the apiserver (and other sources) . The cache should be kept up-to-date even when rejecting pods. Without this, kubelet may decide at any point to drop the status update (request to the apiserver) for the rejected pod since it would think the pod no longer exists in the apiserver. Also check if the pod to-be-admitted has terminated or not. In the case where it has terminated, skip the admission process completely. --- pkg/kubelet/kubelet.go | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 67cb8f9c0ff..7d7dd99d23b 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -1911,22 +1911,32 @@ func (kl *Kubelet) HandlePodAdditions(pods []*v1.Pod) { start := kl.clock.Now() sort.Sort(sliceutils.PodsByCreationTime(pods)) for _, pod := range pods { + existingPods := kl.podManager.GetPods() + // Always add the pod to the pod manager. Kubelet relies on the pod + // manager as the source of truth for the desired state. If a pod does + // not exist in the pod manager, it means that it has been deleted in + // the apiserver and no action (other than cleanup) is required. + kl.podManager.AddPod(pod) + if kubepod.IsMirrorPod(pod) { - kl.podManager.AddPod(pod) kl.handleMirrorPod(pod, start) continue } - // Note that allPods excludes the new pod. - allPods := kl.podManager.GetPods() - // We failed pods that we rejected, so activePods include all admitted - // pods that are alive. - activePods := kl.filterOutTerminatedPods(allPods) - // Check if we can admit the pod; if not, reject it. - if ok, reason, message := kl.canAdmitPod(activePods, pod); !ok { - kl.rejectPod(pod, reason, message) - continue + + if !kl.podIsTerminated(pod) { + // Only go through the admission process if the pod is not + // terminated. + + // We failed pods that we rejected, so activePods include all admitted + // pods that are alive. + activePods := kl.filterOutTerminatedPods(existingPods) + + // Check if we can admit the pod; if not, reject it. + if ok, reason, message := kl.canAdmitPod(activePods, pod); !ok { + kl.rejectPod(pod, reason, message) + continue + } } - kl.podManager.AddPod(pod) mirrorPod, _ := kl.podManager.GetMirrorPodByPod(pod) kl.dispatchWork(pod, kubetypes.SyncPodCreate, mirrorPod, start) kl.probeManager.AddPod(pod)