mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
trigger kubelet sync pod on reconciliation
This commit is contained in:
parent
d46cdbed6c
commit
ac4e015e12
@ -2042,11 +2042,18 @@ func (kl *Kubelet) HandlePodRemoves(pods []*v1.Pod) {
|
|||||||
// HandlePodReconcile is the callback in the SyncHandler interface for pods
|
// HandlePodReconcile is the callback in the SyncHandler interface for pods
|
||||||
// that should be reconciled.
|
// that should be reconciled.
|
||||||
func (kl *Kubelet) HandlePodReconcile(pods []*v1.Pod) {
|
func (kl *Kubelet) HandlePodReconcile(pods []*v1.Pod) {
|
||||||
|
start := kl.clock.Now()
|
||||||
for _, pod := range pods {
|
for _, pod := range pods {
|
||||||
// Update the pod in pod manager, status manager will do periodically reconcile according
|
// Update the pod in pod manager, status manager will do periodically reconcile according
|
||||||
// to the pod manager.
|
// to the pod manager.
|
||||||
kl.podManager.UpdatePod(pod)
|
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.
|
// After an evicted pod is synced, all dead containers in the pod can be removed.
|
||||||
if eviction.PodIsEvicted(pod.Status) {
|
if eviction.PodIsEvicted(pod.Status) {
|
||||||
if podStatus, err := kl.podCache.Get(pod.UID); err == nil {
|
if podStatus, err := kl.podCache.Get(pod.UID); err == nil {
|
||||||
|
@ -227,21 +227,20 @@ func (m *manager) SetContainerReadiness(podUID types.UID, containerID kubecontai
|
|||||||
containerStatus.Ready = ready
|
containerStatus.Ready = ready
|
||||||
|
|
||||||
// Update pod condition.
|
// Update pod condition.
|
||||||
readyConditionIndex := -1
|
podReadyConditionIndex := -1
|
||||||
for i, condition := range status.Conditions {
|
for i, condition := range status.Conditions {
|
||||||
if condition.Type == v1.PodReady {
|
if condition.Type == v1.PodReady {
|
||||||
readyConditionIndex = i
|
podReadyConditionIndex = i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
readyCondition := GeneratePodReadyCondition(&pod.Spec, status.ContainerStatuses, status.Phase)
|
podReady := GeneratePodReadyCondition(&pod.Spec, status.Conditions, status.ContainerStatuses, status.Phase)
|
||||||
if readyConditionIndex != -1 {
|
if podReadyConditionIndex != -1 {
|
||||||
status.Conditions[readyConditionIndex] = readyCondition
|
status.Conditions[podReadyConditionIndex] = podReady
|
||||||
} else {
|
} else {
|
||||||
glog.Warningf("PodStatus missing PodReady condition: %+v", status)
|
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)
|
m.updateStatusInternal(pod, status, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,3 +651,17 @@ func mergePodStatus(oldPodStatus, newPodStatus v1.PodStatus) v1.PodStatus {
|
|||||||
newPodStatus.Conditions = podConditions
|
newPodStatus.Conditions = podConditions
|
||||||
return newPodStatus
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user