From ac4e015e12ac0db86e066bb2fb3dcd23e2adacc8 Mon Sep 17 00:00:00 2001 From: Minhan Xia Date: Fri, 1 Jun 2018 18:04:39 -0700 Subject: [PATCH] trigger kubelet sync pod on reconciliation --- pkg/kubelet/kubelet.go | 7 +++++++ pkg/kubelet/status/status_manager.go | 27 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 4b94359117e..5765b73560c 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -2042,11 +2042,18 @@ func (kl *Kubelet) HandlePodRemoves(pods []*v1.Pod) { // HandlePodReconcile is the callback in the SyncHandler interface for pods // that should be reconciled. func (kl *Kubelet) HandlePodReconcile(pods []*v1.Pod) { + start := kl.clock.Now() for _, pod := range pods { // Update the pod in pod manager, status manager will do periodically reconcile according // to the pod manager. kl.podManager.UpdatePod(pod) + // Reconcile Pod "Ready" condition if necessary. Trigger sync pod for reconciliation. + if status.NeedToReconcilePodReadiness(pod) { + mirrorPod, _ := kl.podManager.GetMirrorPodByPod(pod) + kl.dispatchWork(pod, kubetypes.SyncPodSync, mirrorPod, start) + } + // After an evicted pod is synced, all dead containers in the pod can be removed. if eviction.PodIsEvicted(pod.Status) { if podStatus, err := kl.podCache.Get(pod.UID); err == nil { diff --git a/pkg/kubelet/status/status_manager.go b/pkg/kubelet/status/status_manager.go index 93eef28918a..74f458716e8 100644 --- a/pkg/kubelet/status/status_manager.go +++ b/pkg/kubelet/status/status_manager.go @@ -227,21 +227,20 @@ func (m *manager) SetContainerReadiness(podUID types.UID, containerID kubecontai containerStatus.Ready = ready // Update pod condition. - readyConditionIndex := -1 + podReadyConditionIndex := -1 for i, condition := range status.Conditions { if condition.Type == v1.PodReady { - readyConditionIndex = i + podReadyConditionIndex = i break } } - readyCondition := GeneratePodReadyCondition(&pod.Spec, status.ContainerStatuses, status.Phase) - if readyConditionIndex != -1 { - status.Conditions[readyConditionIndex] = readyCondition + podReady := GeneratePodReadyCondition(&pod.Spec, status.Conditions, status.ContainerStatuses, status.Phase) + if podReadyConditionIndex != -1 { + status.Conditions[podReadyConditionIndex] = podReady } else { glog.Warningf("PodStatus missing PodReady condition: %+v", status) - status.Conditions = append(status.Conditions, readyCondition) + status.Conditions = append(status.Conditions, podReady) } - m.updateStatusInternal(pod, status, false) } @@ -652,3 +651,17 @@ func mergePodStatus(oldPodStatus, newPodStatus v1.PodStatus) v1.PodStatus { newPodStatus.Conditions = podConditions return newPodStatus } + +// NeedToReconcilePodReadiness returns if the pod "Ready" condition need to be reconcile +func NeedToReconcilePodReadiness(pod *v1.Pod) bool { + if len(pod.Spec.ReadinessGates) == 0 { + return false + } + podReadyCondition := GeneratePodReadyCondition(&pod.Spec, pod.Status.Conditions, pod.Status.ContainerStatuses, pod.Status.Phase) + i, curCondition := podutil.GetPodConditionFromList(pod.Status.Conditions, v1.PodReady) + // Only reconcile if "Ready" condition is present + if i >= 0 && curCondition.Status != podReadyCondition.Status { + return true + } + return false +}