mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +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
|
||||
// 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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user