@@ -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
@@ -169,7 +174,7 @@ func (d *Helper) EvictPod(pod corev1.Pod, policyGroupVersion string) error {
169
174
// or error if it cannot list pods. All pods that are ready to be deleted can be obtained with .Pods(),
170
175
// and string with all warning can be obtained with .Warnings(), and .Errors() for all errors that
171
176
// occurred during deletion.
172
- func (d * Helper ) GetPodsForDeletion (nodeName string ) (* podDeleteList , []error ) {
177
+ func (d * Helper ) GetPodsForDeletion (nodeName string ) (* PodDeleteList , []error ) {
173
178
labelSelector , err := labels .Parse (d .PodSelector )
174
179
if err != nil {
175
180
return nil , []error {err }
@@ -182,35 +187,37 @@ func (d *Helper) GetPodsForDeletion(nodeName string) (*podDeleteList, []error) {
182
187
return nil , []error {err }
183
188
}
184
189
185
- pods := []podDelete {}
190
+ list := filterPods (podList , d .makeFilters ())
191
+ if errs := list .errors (); len (errs ) > 0 {
192
+ return list , errs
193
+ }
194
+
195
+ return list , nil
196
+ }
186
197
198
+ func filterPods (podList * corev1.PodList , filters []PodFilter ) * PodDeleteList {
199
+ pods := []PodDelete {}
187
200
for _ , pod := range podList .Items {
188
- var status podDeleteStatus
189
- for _ , filter := range d . makeFilters () {
201
+ var status PodDeleteStatus
202
+ for _ , filter := range filters {
190
203
status = filter (pod )
191
- if ! status .delete {
204
+ if ! status .Delete {
192
205
// short-circuit as soon as pod is filtered out
193
206
// at that point, there is no reason to run pod
194
207
// through any additional filters
195
208
break
196
209
}
197
210
}
198
- // Add the pod to podDeleteList no matter what podDeleteStatus is,
199
- // those pods whose podDeleteStatus is false like DaemonSet will
211
+ // Add the pod to PodDeleteList no matter what PodDeleteStatus is,
212
+ // those pods whose PodDeleteStatus is false like DaemonSet will
200
213
// be catched by list.errors()
201
- pods = append (pods , podDelete {
202
- pod : pod ,
203
- status : status ,
214
+ pods = append (pods , PodDelete {
215
+ Pod : pod ,
216
+ Status : status ,
204
217
})
205
218
}
206
-
207
- list := & podDeleteList {items : pods }
208
-
209
- if errs := list .errors (); len (errs ) > 0 {
210
- return list , errs
211
- }
212
-
213
- return list , nil
219
+ list := & PodDeleteList {items : pods }
220
+ return list
214
221
}
215
222
216
223
// DeleteOrEvictPods deletes or evicts the pods on the api server
0 commit comments