Skip to content

Commit 23b925f

Browse files
committed
feature: add IgnorePodsWithResourceClaims parameter for configuration
1 parent 71726c8 commit 23b925f

17 files changed

+140
-70
lines changed

pkg/api/v1alpha2/zz_generated.conversion.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/v1alpha2/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/v1alpha2/zz_generated.defaults.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/componentconfig/types.go

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ type DeschedulerConfiguration struct {
5757
// IgnorePVCPods sets whether PVC pods should be allowed to be evicted
5858
IgnorePVCPods bool
5959

60+
// IgnorePodsWithResourceClaims sets whether pods using resource claims should be allowed to be evicted
61+
IgnorePodsWithResourceClaims bool
62+
6063
// Tracing specifies the options for tracing.
6164
Tracing TracingConfiguration
6265

pkg/apis/componentconfig/v1alpha1/types.go

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ type DeschedulerConfiguration struct {
5757
// IgnorePVCPods sets whether PVC pods should be allowed to be evicted
5858
IgnorePVCPods bool `json:"ignorePvcPods,omitempty"`
5959

60+
// IgnorePodsWithResourceClaims sets whether pods using resource claims should be allowed to be evicted
61+
IgnorePodsWithResourceClaims bool `json:"ignorePodsWithResourceClaims"`
62+
6063
// Tracing is used to setup the required OTEL tracing configuration
6164
Tracing TracingConfiguration `json:"tracing,omitempty"`
6265

pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/componentconfig/v1alpha1/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/componentconfig/v1alpha1/zz_generated.defaults.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/componentconfig/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/descheduler/policyconfig.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ func setDefaultEvictor(profile api.DeschedulerProfile, client clientset.Interfac
101101
newPluginConfig := api.PluginConfig{
102102
Name: defaultevictor.PluginName,
103103
Args: &defaultevictor.DefaultEvictorArgs{
104-
EvictLocalStoragePods: false,
105-
EvictSystemCriticalPods: false,
106-
IgnorePvcPods: false,
107-
EvictFailedBarePods: false,
108-
IgnorePodsWithoutPDB: false,
104+
EvictLocalStoragePods: false,
105+
EvictSystemCriticalPods: false,
106+
IgnorePvcPods: false,
107+
EvictFailedBarePods: false,
108+
IgnorePodsWithoutPDB: false,
109+
IgnorePodsWithResourceClaims: false,
109110
},
110111
}
111112

pkg/framework/plugins/defaultevictor/defaultevictor.go

+9
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug
209209
})
210210
}
211211

212+
if defaultEvictorArgs.IgnorePodsWithResourceClaims {
213+
ev.constraints = append(ev.constraints, func(pod *v1.Pod) error {
214+
if utils.IsPodWithResourceClaims(pod) {
215+
return fmt.Errorf("pod has a ResourceClaim and descheduler is configured to ignore ResourceClaim pods")
216+
}
217+
return nil
218+
})
219+
}
220+
212221
return ev, nil
213222
}
214223

pkg/framework/plugins/defaultevictor/defaultevictor_test.go

+51-17
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"k8s.io/apimachinery/pkg/util/uuid"
2929
"k8s.io/client-go/informers"
3030
"k8s.io/client-go/kubernetes/fake"
31+
"k8s.io/utils/ptr"
32+
3133
"sigs.k8s.io/descheduler/pkg/api"
3234
podutil "sigs.k8s.io/descheduler/pkg/descheduler/pod"
3335
frameworkfake "sigs.k8s.io/descheduler/pkg/framework/fake"
@@ -37,19 +39,20 @@ import (
3739
)
3840

3941
type testCase struct {
40-
description string
41-
pods []*v1.Pod
42-
nodes []*v1.Node
43-
pdbs []*policyv1.PodDisruptionBudget
44-
evictFailedBarePods bool
45-
evictLocalStoragePods bool
46-
evictSystemCriticalPods bool
47-
priorityThreshold *int32
48-
nodeFit bool
49-
minReplicas uint
50-
minPodAge *metav1.Duration
51-
result bool
52-
ignorePodsWithoutPDB bool
42+
description string
43+
pods []*v1.Pod
44+
nodes []*v1.Node
45+
pdbs []*policyv1.PodDisruptionBudget
46+
evictFailedBarePods bool
47+
evictLocalStoragePods bool
48+
evictSystemCriticalPods bool
49+
priorityThreshold *int32
50+
nodeFit bool
51+
minReplicas uint
52+
minPodAge *metav1.Duration
53+
result bool
54+
ignorePodsWithoutPDB bool
55+
ignorePodsWithResourceClaims bool
5356
}
5457

5558
func TestDefaultEvictorPreEvictionFilter(t *testing.T) {
@@ -769,6 +772,36 @@ func TestDefaultEvictorFilter(t *testing.T) {
769772
},
770773
ignorePodsWithoutPDB: true,
771774
result: true,
775+
}, {
776+
description: "ignorePodsWithResourceClaims, pod withoout ResourceClaims, evicts",
777+
pods: []*v1.Pod{
778+
test.BuildTestPod("p1", 1, 1, n1.Name, func(pod *v1.Pod) {
779+
pod.ObjectMeta.OwnerReferences = test.GetNormalPodOwnerRefList()
780+
pod.Labels = map[string]string{
781+
"app": "foo",
782+
}
783+
}),
784+
},
785+
ignorePodsWithResourceClaims: true,
786+
result: true,
787+
}, {
788+
description: "ignorePodsWithResourceClaims, pod with ResourceClaims, not evicts",
789+
pods: []*v1.Pod{
790+
test.BuildTestPod("p1", 1, 1, n1.Name, func(pod *v1.Pod) {
791+
pod.ObjectMeta.OwnerReferences = test.GetNormalPodOwnerRefList()
792+
pod.Labels = map[string]string{
793+
"app": "foo",
794+
}
795+
pod.Spec.ResourceClaims = []v1.PodResourceClaim{
796+
{
797+
Name: "test-resource-claim",
798+
ResourceClaimName: ptr.To("test-resource-claim"),
799+
},
800+
}
801+
}),
802+
},
803+
ignorePodsWithResourceClaims: true,
804+
result: false,
772805
},
773806
}
774807

@@ -867,10 +900,11 @@ func initializePlugin(ctx context.Context, test testCase) (frameworktypes.Plugin
867900
PriorityThreshold: &api.PriorityThreshold{
868901
Value: test.priorityThreshold,
869902
},
870-
NodeFit: test.nodeFit,
871-
MinReplicas: test.minReplicas,
872-
MinPodAge: test.minPodAge,
873-
IgnorePodsWithoutPDB: test.ignorePodsWithoutPDB,
903+
NodeFit: test.nodeFit,
904+
MinReplicas: test.minReplicas,
905+
MinPodAge: test.minPodAge,
906+
IgnorePodsWithoutPDB: test.ignorePodsWithoutPDB,
907+
IgnorePodsWithResourceClaims: test.ignorePodsWithResourceClaims,
874908
}
875909

876910
evictorPlugin, err := New(

pkg/framework/plugins/defaultevictor/defaults.go

+6
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,10 @@ func SetDefaults_DefaultEvictorArgs(obj runtime.Object) {
5252
if !args.NodeFit {
5353
args.NodeFit = false
5454
}
55+
if !args.IgnorePodsWithoutPDB {
56+
args.IgnorePodsWithoutPDB = false
57+
}
58+
if !args.IgnorePodsWithResourceClaims {
59+
args.IgnorePodsWithResourceClaims = false
60+
}
5561
}

pkg/framework/plugins/defaultevictor/defaults_test.go

+31-28
Original file line numberDiff line numberDiff line change
@@ -33,47 +33,50 @@ func TestSetDefaults_DefaultEvictorArgs(t *testing.T) {
3333
name: "DefaultEvictorArgs empty",
3434
in: &DefaultEvictorArgs{},
3535
want: &DefaultEvictorArgs{
36-
NodeSelector: "",
37-
EvictLocalStoragePods: false,
38-
EvictDaemonSetPods: false,
39-
EvictSystemCriticalPods: false,
40-
IgnorePvcPods: false,
41-
EvictFailedBarePods: false,
42-
LabelSelector: nil,
43-
PriorityThreshold: nil,
44-
NodeFit: false,
45-
IgnorePodsWithoutPDB: false,
36+
NodeSelector: "",
37+
EvictLocalStoragePods: false,
38+
EvictDaemonSetPods: false,
39+
EvictSystemCriticalPods: false,
40+
IgnorePvcPods: false,
41+
EvictFailedBarePods: false,
42+
LabelSelector: nil,
43+
PriorityThreshold: nil,
44+
NodeFit: false,
45+
IgnorePodsWithoutPDB: false,
46+
IgnorePodsWithResourceClaims: false,
4647
},
4748
},
4849
{
4950
name: "DefaultEvictorArgs with value",
5051
in: &DefaultEvictorArgs{
51-
NodeSelector: "NodeSelector",
52-
EvictLocalStoragePods: true,
53-
EvictDaemonSetPods: true,
54-
EvictSystemCriticalPods: true,
55-
IgnorePvcPods: true,
56-
EvictFailedBarePods: true,
57-
LabelSelector: nil,
52+
NodeSelector: "NodeSelector",
53+
EvictLocalStoragePods: true,
54+
EvictDaemonSetPods: true,
55+
EvictSystemCriticalPods: true,
56+
IgnorePvcPods: true,
57+
EvictFailedBarePods: true,
58+
LabelSelector: nil,
59+
NodeFit: true,
60+
IgnorePodsWithoutPDB: true,
61+
IgnorePodsWithResourceClaims: true,
5862
PriorityThreshold: &api.PriorityThreshold{
5963
Value: utilptr.To[int32](800),
6064
},
61-
NodeFit: true,
62-
IgnorePodsWithoutPDB: true,
6365
},
6466
want: &DefaultEvictorArgs{
65-
NodeSelector: "NodeSelector",
66-
EvictLocalStoragePods: true,
67-
EvictDaemonSetPods: true,
68-
EvictSystemCriticalPods: true,
69-
IgnorePvcPods: true,
70-
EvictFailedBarePods: true,
71-
LabelSelector: nil,
67+
NodeSelector: "NodeSelector",
68+
EvictLocalStoragePods: true,
69+
EvictDaemonSetPods: true,
70+
EvictSystemCriticalPods: true,
71+
IgnorePvcPods: true,
72+
EvictFailedBarePods: true,
73+
LabelSelector: nil,
74+
NodeFit: true,
75+
IgnorePodsWithoutPDB: true,
76+
IgnorePodsWithResourceClaims: true,
7277
PriorityThreshold: &api.PriorityThreshold{
7378
Value: utilptr.To[int32](800),
7479
},
75-
NodeFit: true,
76-
IgnorePodsWithoutPDB: true,
7780
},
7881
},
7982
}

pkg/framework/plugins/defaultevictor/types.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ import (
2525
type DefaultEvictorArgs struct {
2626
metav1.TypeMeta `json:",inline"`
2727

28-
NodeSelector string `json:"nodeSelector,omitempty"`
29-
EvictLocalStoragePods bool `json:"evictLocalStoragePods,omitempty"`
30-
EvictDaemonSetPods bool `json:"evictDaemonSetPods,omitempty"`
31-
EvictSystemCriticalPods bool `json:"evictSystemCriticalPods,omitempty"`
32-
IgnorePvcPods bool `json:"ignorePvcPods,omitempty"`
33-
EvictFailedBarePods bool `json:"evictFailedBarePods,omitempty"`
34-
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
35-
PriorityThreshold *api.PriorityThreshold `json:"priorityThreshold,omitempty"`
36-
NodeFit bool `json:"nodeFit,omitempty"`
37-
MinReplicas uint `json:"minReplicas,omitempty"`
38-
MinPodAge *metav1.Duration `json:"minPodAge,omitempty"`
39-
IgnorePodsWithoutPDB bool `json:"ignorePodsWithoutPDB,omitempty"`
28+
NodeSelector string `json:"nodeSelector,omitempty"`
29+
EvictLocalStoragePods bool `json:"evictLocalStoragePods,omitempty"`
30+
EvictDaemonSetPods bool `json:"evictDaemonSetPods,omitempty"`
31+
EvictSystemCriticalPods bool `json:"evictSystemCriticalPods,omitempty"`
32+
IgnorePvcPods bool `json:"ignorePvcPods,omitempty"`
33+
EvictFailedBarePods bool `json:"evictFailedBarePods,omitempty"`
34+
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
35+
PriorityThreshold *api.PriorityThreshold `json:"priorityThreshold,omitempty"`
36+
NodeFit bool `json:"nodeFit,omitempty"`
37+
MinReplicas uint `json:"minReplicas,omitempty"`
38+
MinPodAge *metav1.Duration `json:"minPodAge,omitempty"`
39+
IgnorePodsWithoutPDB bool `json:"ignorePodsWithoutPDB,omitempty"`
40+
IgnorePodsWithResourceClaims bool `json:"ignorePodsWithResourceClaims,omitempty"`
4041
}

pkg/utils/pod.go

+8
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ func IsPodWithPVC(pod *v1.Pod) bool {
120120
return false
121121
}
122122

123+
// IsPodWithResourceClaims returns true if the pod has resource claims.
124+
func IsPodWithResourceClaims(pod *v1.Pod) bool {
125+
if len(pod.Spec.ResourceClaims) != 0 {
126+
return true
127+
}
128+
return false
129+
}
130+
123131
// IsPodCoveredByPDB returns true if the pod is covered by at least one PodDisruptionBudget.
124132
func IsPodCoveredByPDB(pod *v1.Pod, lister policyv1.PodDisruptionBudgetLister) (bool, error) {
125133
// We can't use the GetPodPodDisruptionBudgets expansion method here because it treats no pdb as an error,

0 commit comments

Comments
 (0)