Merge pull request #114361 from kerthcet/cleanup/emit-errors-more-precise

Tune the error messages in scheduler cache
This commit is contained in:
Kubernetes Prow Robot 2022-12-12 00:15:44 -08:00 committed by GitHub
commit bc6afee049
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -537,17 +537,22 @@ func (cache *cacheImpl) UpdatePod(oldPod, newPod *v1.Pod) error {
defer cache.mu.Unlock() defer cache.mu.Unlock()
currState, ok := cache.podStates[key] currState, ok := cache.podStates[key]
if !ok {
return fmt.Errorf("pod %v(%v) is not added to scheduler cache, so cannot be updated", key, klog.KObj(oldPod))
}
// An assumed pod won't have Update/Remove event. It needs to have Add event // An assumed pod won't have Update/Remove event. It needs to have Add event
// before Update event, in which case the state would change from Assumed to Added. // before Update event, in which case the state would change from Assumed to Added.
if ok && !cache.assumedPods.Has(key) { if cache.assumedPods.Has(key) {
return fmt.Errorf("assumed pod %v(%v) should not be updated", key, klog.KObj(oldPod))
}
if currState.pod.Spec.NodeName != newPod.Spec.NodeName { if currState.pod.Spec.NodeName != newPod.Spec.NodeName {
klog.ErrorS(nil, "Pod updated on a different node than previously added to", "podKey", key, "pod", klog.KObj(oldPod)) klog.ErrorS(nil, "Pod updated on a different node than previously added to", "podKey", key, "pod", klog.KObj(oldPod))
klog.ErrorS(nil, "scheduler cache is corrupted and can badly affect scheduling decisions") klog.ErrorS(nil, "scheduler cache is corrupted and can badly affect scheduling decisions")
klog.FlushAndExit(klog.ExitFlushTimeout, 1) klog.FlushAndExit(klog.ExitFlushTimeout, 1)
} }
return cache.updatePod(oldPod, newPod) return cache.updatePod(oldPod, newPod)
}
return fmt.Errorf("pod %v(%v) is not added to scheduler cache, so cannot be updated", key, klog.KObj(oldPod))
} }
func (cache *cacheImpl) RemovePod(pod *v1.Pod) error { func (cache *cacheImpl) RemovePod(pod *v1.Pod) error {