@@ -65,6 +65,11 @@ type Helper struct {
65
65
// won't drain otherwise
66
66
SkipWaitForDeleteTimeoutSeconds int
67
67
68
+ // AdditionalFilters are applied sequentially after base drain filters to
69
+ // exclude pods using custom logic. Any filter that returns PodDeleteStatus
70
+ // with Delete == false will immediately stop execution of further filters.
71
+ AdditionalFilters []PodFilter
72
+
68
73
Out io.Writer
69
74
ErrOut io.Writer
70
75
@@ -172,7 +177,7 @@ func (d *Helper) EvictPod(pod corev1.Pod, policyGroupVersion string) error {
172
177
// or error if it cannot list pods. All pods that are ready to be deleted can be obtained with .Pods(),
173
178
// and string with all warning can be obtained with .Warnings(), and .Errors() for all errors that
174
179
// occurred during deletion.
175
- func (d * Helper ) GetPodsForDeletion (nodeName string ) (* podDeleteList , []error ) {
180
+ func (d * Helper ) GetPodsForDeletion (nodeName string ) (* PodDeleteList , []error ) {
176
181
labelSelector , err := labels .Parse (d .PodSelector )
177
182
if err != nil {
178
183
return nil , []error {err }
@@ -185,35 +190,37 @@ func (d *Helper) GetPodsForDeletion(nodeName string) (*podDeleteList, []error) {
185
190
return nil , []error {err }
186
191
}
187
192
188
- pods := []podDelete {}
193
+ list := filterPods (podList , d .makeFilters ())
194
+ if errs := list .errors (); len (errs ) > 0 {
195
+ return list , errs
196
+ }
197
+
198
+ return list , nil
199
+ }
189
200
201
+ func filterPods (podList * corev1.PodList , filters []PodFilter ) * PodDeleteList {
202
+ pods := []PodDelete {}
190
203
for _ , pod := range podList .Items {
191
- var status podDeleteStatus
192
- for _ , filter := range d . makeFilters () {
204
+ var status PodDeleteStatus
205
+ for _ , filter := range filters {
193
206
status = filter (pod )
194
- if ! status .delete {
207
+ if ! status .Delete {
195
208
// short-circuit as soon as pod is filtered out
196
209
// at that point, there is no reason to run pod
197
210
// through any additional filters
198
211
break
199
212
}
200
213
}
201
- // Add the pod to podDeleteList no matter what podDeleteStatus is,
202
- // those pods whose podDeleteStatus is false like DaemonSet will
214
+ // Add the pod to PodDeleteList no matter what PodDeleteStatus is,
215
+ // those pods whose PodDeleteStatus is false like DaemonSet will
203
216
// be catched by list.errors()
204
- pods = append (pods , podDelete {
205
- pod : pod ,
206
- status : status ,
217
+ pods = append (pods , PodDelete {
218
+ Pod : pod ,
219
+ Status : status ,
207
220
})
208
221
}
209
-
210
- list := & podDeleteList {items : pods }
211
-
212
- if errs := list .errors (); len (errs ) > 0 {
213
- return list , errs
214
- }
215
-
216
- return list , nil
222
+ list := & PodDeleteList {items : pods }
223
+ return list
217
224
}
218
225
219
226
// DeleteOrEvictPods deletes or evicts the pods on the api server
0 commit comments