mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Avoid unnecessary GET request when updating pod status
When sending out an pod status update, kubelet GETs the pod from the apiserver Terminates if the apiserver returns an not found error; otherwise, proceed to to update. Even after a pod has been deleted, there might still be queued up updates for the pod. This leads to expensive, unncessary GET operations. The situation is worse when there are batch creation/deletion of a significant number of pods (e.g., E2E tests), leaving many updates in the queue. This change checks whether a pod exists before GET the pod from the apiserver to avoid redundant GETs.
This commit is contained in:
parent
5516b8684f
commit
3072754c8b
@ -347,6 +347,11 @@ func (m *manager) syncBatch() {
|
||||
|
||||
// syncPod syncs the given status with the API server. The caller must not hold the lock.
|
||||
func (m *manager) syncPod(uid types.UID, status versionedPodStatus) {
|
||||
if !m.needsUpdate(uid, status) {
|
||||
glog.V(1).Infof("Status for pod %q is up-to-date; skipping", uid)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: make me easier to express from client code
|
||||
pod, err := m.kubeClient.Core().Pods(status.podNamespace).Get(status.podName)
|
||||
if errors.IsNotFound(err) {
|
||||
@ -362,10 +367,6 @@ func (m *manager) syncPod(uid types.UID, status versionedPodStatus) {
|
||||
m.deletePodStatus(uid)
|
||||
return
|
||||
}
|
||||
if !m.needsUpdate(pod.UID, status) {
|
||||
glog.V(1).Infof("Status for pod %q is up-to-date; skipping", format.Pod(pod))
|
||||
return
|
||||
}
|
||||
pod.Status = status.status
|
||||
// TODO: handle conflict as a retry, make that easier too.
|
||||
pod, err = m.kubeClient.Core().Pods(pod.Namespace).UpdateStatus(pod)
|
||||
|
Loading…
Reference in New Issue
Block a user