From 5092595384d1623d133ff54751ea62080b415ca8 Mon Sep 17 00:00:00 2001 From: xujihui1985 Date: Wed, 3 Jan 2024 20:13:26 +0800 Subject: [PATCH] fix: filter pod with age greater than MaxPodLifeTimeSeconds when the pod createtimestamp is greater than the current time (which is not make sense in real life, but when doing test with such case, it is possible), it will convert to a large number if we convert it to uint, and though it can pass the test, but doesn't make sense. --- pkg/framework/plugins/podlifetime/pod_lifetime.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime.go b/pkg/framework/plugins/podlifetime/pod_lifetime.go index 0285057c3..d4d6103e7 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime.go @@ -25,6 +25,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" + frameworktypes "sigs.k8s.io/descheduler/pkg/framework/types" "sigs.k8s.io/descheduler/pkg/descheduler/evictions" @@ -67,8 +68,8 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug } podFilter = podutil.WrapFilterFuncs(podFilter, func(pod *v1.Pod) bool { - podAgeSeconds := uint(metav1.Now().Sub(pod.GetCreationTimestamp().Local()).Seconds()) - return podAgeSeconds > *podLifeTimeArgs.MaxPodLifeTimeSeconds + podAgeSeconds := int(metav1.Now().Sub(pod.GetCreationTimestamp().Local()).Seconds()) + return podAgeSeconds > int(*podLifeTimeArgs.MaxPodLifeTimeSeconds) }) if len(podLifeTimeArgs.States) > 0 {