From 180b082c49c90963e62ba2aa55ddbc985b46354f Mon Sep 17 00:00:00 2001 From: kerthcet Date: Thu, 8 Dec 2022 15:41:43 +0800 Subject: [PATCH] Make the error messages in scheduler cache more precise Signed-off-by: kerthcet --- pkg/scheduler/internal/cache/cache.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/scheduler/internal/cache/cache.go b/pkg/scheduler/internal/cache/cache.go index 041bf4178a7..0b60a82f9c2 100644 --- a/pkg/scheduler/internal/cache/cache.go +++ b/pkg/scheduler/internal/cache/cache.go @@ -537,17 +537,22 @@ func (cache *cacheImpl) UpdatePod(oldPod, newPod *v1.Pod) error { defer cache.mu.Unlock() 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 // before Update event, in which case the state would change from Assumed to Added. - if ok && !cache.assumedPods.Has(key) { - 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, "scheduler cache is corrupted and can badly affect scheduling decisions") - klog.FlushAndExit(klog.ExitFlushTimeout, 1) - } - return cache.updatePod(oldPod, newPod) + if cache.assumedPods.Has(key) { + return fmt.Errorf("assumed pod %v(%v) should not be updated", key, klog.KObj(oldPod)) } - return fmt.Errorf("pod %v(%v) is not added to scheduler cache, so cannot be updated", key, klog.KObj(oldPod)) + + 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, "scheduler cache is corrupted and can badly affect scheduling decisions") + klog.FlushAndExit(klog.ExitFlushTimeout, 1) + } + return cache.updatePod(oldPod, newPod) } func (cache *cacheImpl) RemovePod(pod *v1.Pod) error {