Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions charts/descheduler/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ schedule: "*/2 * * * *"
cmdOptions:
v: 3
# evict-local-storage-pods:
# evict-system-critical-pods:
# max-pods-to-evict-per-node: 10
# node-selector: "key1=value1,key2=value2"

Expand Down
2 changes: 2 additions & 0 deletions cmd/descheduler/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ func (rs *DeschedulerServer) AddFlags(fs *pflag.FlagSet) {
fs.IntVar(&rs.MaxNoOfPodsToEvictPerNode, "max-pods-to-evict-per-node", rs.MaxNoOfPodsToEvictPerNode, "Limits the maximum number of pods to be evicted per node by descheduler")
// evict-local-storage-pods allows eviction of pods that are using local storage. This is false by default.
fs.BoolVar(&rs.EvictLocalStoragePods, "evict-local-storage-pods", rs.EvictLocalStoragePods, "Enables evicting pods using local storage by descheduler")
// evict-system-critical-pods allows eviction of critical pods. This is false by default.
fs.BoolVar(&rs.EvictSystemCriticalPods, "evict-system-critical-pods", rs.EvictSystemCriticalPods, "Enables evicting critical pods by descheduler")
}
3 changes: 3 additions & 0 deletions pkg/apis/componentconfig/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ type DeschedulerConfiguration struct {

// EvictLocalStoragePods allows pods using local storage to be evicted.
EvictLocalStoragePods bool

// EvictSystemCriticalPods allows critical pods to be evicted.
EvictSystemCriticalPods bool
}
3 changes: 3 additions & 0 deletions pkg/apis/componentconfig/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ type DeschedulerConfiguration struct {

// EvictLocalStoragePods allows pods using local storage to be evicted.
EvictLocalStoragePods bool `json:"evictLocalStoragePods,omitempty"`

// EvictSystemCriticalPods allows critical pods to be evicted.
EvictSystemCriticalPods bool `json:"evictSystemCriticalPods,omitempty"`
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/descheduler/descheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func RunDeschedulerStrategies(ctx context.Context, rs *options.DeschedulerServer
rs.MaxNoOfPodsToEvictPerNode,
nodes,
rs.EvictLocalStoragePods,
rs.EvictSystemCriticalPods,
)

for name, f := range strategyFuncs {
Expand Down
19 changes: 11 additions & 8 deletions pkg/descheduler/evictions/evictions.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ const (
type nodePodEvictedCount map[*v1.Node]int

type PodEvictor struct {
client clientset.Interface
policyGroupVersion string
dryRun bool
maxPodsToEvictPerNode int
nodepodCount nodePodEvictedCount
evictLocalStoragePods bool
client clientset.Interface
policyGroupVersion string
dryRun bool
maxPodsToEvictPerNode int
nodepodCount nodePodEvictedCount
evictLocalStoragePods bool
evictSystemCriticalPods bool
}

func NewPodEvictor(
Expand All @@ -60,6 +61,7 @@ func NewPodEvictor(
maxPodsToEvictPerNode int,
nodes []*v1.Node,
evictLocalStoragePods bool,
evictSystemCriticalPods bool,
) *PodEvictor {
var nodePodCount = make(nodePodEvictedCount)
for _, node := range nodes {
Expand All @@ -74,14 +76,15 @@ func NewPodEvictor(
maxPodsToEvictPerNode: maxPodsToEvictPerNode,
nodepodCount: nodePodCount,
evictLocalStoragePods: evictLocalStoragePods,
evictSystemCriticalPods: evictSystemCriticalPods,
}
}

// IsEvictable checks if a pod is evictable or not.
func (pe *PodEvictor) IsEvictable(pod *v1.Pod, thresholdPriority int32) bool {
checkErrs := []error{}
if IsCriticalPod(pod) {
checkErrs = append(checkErrs, fmt.Errorf("pod is critical"))
if !pe.evictSystemCriticalPods && IsCriticalPod(pod) {
checkErrs = append(checkErrs, fmt.Errorf("pod is critical and descheduler is not configured with --evict-system-critical-pods"))
}

if !IsPodEvictableBasedOnPriority(pod, thresholdPriority) {
Expand Down
11 changes: 6 additions & 5 deletions pkg/descheduler/evictions/evictions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ func TestIsEvictable(t *testing.T) {
lowPriority := int32(800)
highPriority := int32(900)
type testCase struct {
pod *v1.Pod
runBefore func(*v1.Pod)
evictLocalStoragePods bool
priorityThreshold *int32
result bool
pod *v1.Pod
runBefore func(*v1.Pod)
evictLocalStoragePods bool
evictSystemCriticalPods bool
priorityThreshold *int32
result bool
}

testCases := []testCase{
Expand Down