mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-28 14:41:10 +01:00
Merge pull request #300 from damemi/refactor-is-evictable
Add more verbose logging to IsEvictable checks
This commit is contained in:
@@ -243,6 +243,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.
|
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.
|
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)
|
### Pod Disruption Budget (PDB)
|
||||||
|
|
||||||
Pods subject to a Pod Disruption Budget(PDB) are not evicted if descheduling violates its PDB. The pods
|
Pods subject to a Pod Disruption Budget(PDB) are not evicted if descheduling violates its PDB. The pods
|
||||||
|
|||||||
@@ -18,10 +18,13 @@ package pod
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/fields"
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
|
"k8s.io/apimachinery/pkg/util/errors"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
|
"k8s.io/klog"
|
||||||
"sigs.k8s.io/descheduler/pkg/utils"
|
"sigs.k8s.io/descheduler/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,8 +34,30 @@ const (
|
|||||||
|
|
||||||
// IsEvictable checks if a pod is evictable or not.
|
// IsEvictable checks if a pod is evictable or not.
|
||||||
func IsEvictable(pod *v1.Pod, evictLocalStoragePods bool) bool {
|
func IsEvictable(pod *v1.Pod, evictLocalStoragePods bool) bool {
|
||||||
|
checkErrs := []error{}
|
||||||
|
if IsCriticalPod(pod) {
|
||||||
|
checkErrs = append(checkErrs, fmt.Errorf("pod is critical"))
|
||||||
|
}
|
||||||
|
|
||||||
ownerRefList := OwnerRef(pod)
|
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 false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user