From 0a4b8b0a25ae67b6d454471a3c5223865955a0c3 Mon Sep 17 00:00:00 2001 From: Mike Dame Date: Wed, 27 May 2020 17:40:41 -0400 Subject: [PATCH] Add more verbose logging to IsEvictable checks --- README.md | 2 ++ pkg/descheduler/pod/pods.go | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f730156a9..ec1b38362 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,8 @@ never evicted because these pods won't be recreated. annotation is used to override checks which prevent eviction and users can select which pod is evicted. Users should know how and if the pod will be recreated. +Setting `--v=4` or greater on the Descheduler will log all reasons why any pod is not evictable. + ### Pod Disruption Budget (PDB) Pods subject to a Pod Disruption Budget(PDB) are not evicted if descheduling violates its PDB. The pods diff --git a/pkg/descheduler/pod/pods.go b/pkg/descheduler/pod/pods.go index 4978e6215..e31b2d59b 100644 --- a/pkg/descheduler/pod/pods.go +++ b/pkg/descheduler/pod/pods.go @@ -18,10 +18,13 @@ package pod import ( "context" + "fmt" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" + "k8s.io/apimachinery/pkg/util/errors" clientset "k8s.io/client-go/kubernetes" + "k8s.io/klog" "sigs.k8s.io/descheduler/pkg/utils" ) @@ -31,8 +34,30 @@ const ( // IsEvictable checks if a pod is evictable or not. func IsEvictable(pod *v1.Pod, evictLocalStoragePods bool) bool { + checkErrs := []error{} + if IsCriticalPod(pod) { + checkErrs = append(checkErrs, fmt.Errorf("pod is critical")) + } + ownerRefList := OwnerRef(pod) - if !HaveEvictAnnotation(pod) && (IsMirrorPod(pod) || (!evictLocalStoragePods && IsPodWithLocalStorage(pod)) || len(ownerRefList) == 0 || IsDaemonsetPod(ownerRefList) || IsCriticalPod(pod)) { + if IsDaemonsetPod(ownerRefList) { + checkErrs = append(checkErrs, fmt.Errorf("pod is a DaemonSet pod")) + } + + if len(ownerRefList) == 0 { + checkErrs = append(checkErrs, fmt.Errorf("pod does not have any ownerrefs")) + } + + if !evictLocalStoragePods && IsPodWithLocalStorage(pod) { + checkErrs = append(checkErrs, fmt.Errorf("pod has local storage and descheduler is not configured with --evict-local-storage-pods")) + } + + if IsMirrorPod(pod) { + checkErrs = append(checkErrs, fmt.Errorf("pod is a mirror pod")) + } + + if len(checkErrs) > 0 && !HaveEvictAnnotation(pod) { + klog.V(4).Infof("Pod %s in namespace %s is not evictable: Pod lacks an eviction annotation and fails the following checks: %v", pod.Name, pod.Namespace, errors.NewAggregate(checkErrs).Error()) return false } return true