Code change:
} func TestDeleteOrEvict(t *testing.T) { <del> for _, evictionSupported := range []bool{true, false} { evictionSupported := evictionSupported t.Run(fmt.Sprintf("evictionSupported=%v", evictionSupported), func(t *testing.T) { h := &Helper{ Out:                os.Stdout, GracePeriodSeconds: 10, } // Create 4 pods, and try to remove the first 2 var expectedEvictions []policyv1beta1.Eviction var create []runtime.Object deletePods := []corev1.Pod{} for i := 1; i <= 4; i++ { pod := &corev1.Pod{} pod.Name = fmt.Sprintf("mypod-%d", i) pod.Namespace = "default" </del> <ins> tests := []struct { description       string evictionSupported bool disableEviction   bool }{ { description:       "eviction supported/enabled", evictionSupported: true, disableEviction:   false, }, { description:       "eviction unsupported/disabled", evictionSupported: false, disableEviction:   false, }, { description:       "eviction supported/disabled", evictionSupported: true, disableEviction:   true, }, { description:       "eviction unsupported/disabled", evictionSupported: false, disableEviction:   false, }, } for _, tc := range tests { t.Run(tc.description, func(t *testing.T) { h := &Helper{ Out:                os.Stdout, GracePeriodSeconds: 10, } </ins> <del> create = append(create, pod) if i <= 2 { deletePods = append(deletePods, *pod) </del> <ins> // Create 4 pods, and try to remove the first 2 var expectedEvictions []policyv1beta1.Eviction var create []runtime.Object deletePods := []corev1.Pod{} for i := 1; i <= 4; i++ { pod := &corev1.Pod{} pod.Name = fmt.Sprintf("mypod-%d", i) pod.Namespace = "default" </ins> <del> if evictionSupported { eviction := policyv1beta1.Eviction{} eviction.Kind = "Eviction" eviction.APIVersion = "policy/v1" eviction.Namespace = pod.Namespace eviction.Name = pod.Name </del> <ins> create = append(create, pod) if i <= 2 { deletePods = append(deletePods, *pod) </ins> <del> gracePeriodSeconds := int64(h.GracePeriodSeconds) eviction.DeleteOptions = &metav1.DeleteOptions{ GracePeriodSeconds: &gracePeriodSeconds, } </del> <ins> if tc.evictionSupported && !tc.disableEviction { eviction := policyv1beta1.Eviction{} eviction.Kind = "Eviction" eviction.APIVersion = "policy/v1" eviction.Namespace = pod.Namespace eviction.Name = pod.Name </ins> <del> expectedEvictions = append(expectedEvictions, eviction) </del> <ins> gracePeriodSeconds := int64(h.GracePeriodSeconds) eviction.DeleteOptions = &metav1.DeleteOptions{ GracePeriodSeconds: &gracePeriodSeconds, </ins> } <ins> expectedEvictions = append(expectedEvictions, eviction) </ins> } } <ins> } </ins> <del> // Build the fake client k := fake.NewSimpleClientset(create...) if evictionSupported { addEvictionSupport(t, k) } h.Client = k </del> <ins> // Build the fake client k := fake.NewSimpleClientset(create...) if tc.evictionSupported { addEvictionSupport(t, k) } h.Client = k h.DisableEviction = tc.disableEviction // Do the eviction if err := h.DeleteOrEvictPods(deletePods); err != nil { t.Fatalf("error from DeleteOrEvictPods: %v", err) } </ins> <del> // Do the eviction if err := h.DeleteOrEvictPods(deletePods); err != nil { t.Fatalf("error from DeleteOrEvictPods: %v", err) </del> <ins> // Test that other pods are still there var remainingPods []string { podList, err := k.CoreV1().Pods("").List(metav1.ListOptions{}) if err != nil { t.Fatalf("error listing pods: %v", err) </ins> } <del> // Test that other pods are still there var remainingPods []string { podList, err := k.CoreV1().Pods("").List(metav1.ListOptions{}) if err != nil { t.Fatalf("error listing pods: %v", err) } for _, pod := range podList.Items { remainingPods = append(remainingPods, pod.Namespace+"/"+pod.Name) } sort.Strings(remainingPods) } expected := []string{"default/mypod-3", "default/mypod-4"} if !reflect.DeepEqual(remainingPods, expected) { t.Errorf("unexpected remaining pods after DeleteOrEvictPods; actual %v; expected %v", remainingPods, expected) </del> <ins> for _, pod := range podList.Items { remainingPods = append(remainingPods, pod.Namespace+"/"+pod.Name) </ins> } <ins> sort.Strings(remainingPods) } expected := []string{"default/mypod-3", "default/mypod-4"} if !reflect.DeepEqual(remainingPods, expected) { t.Errorf("%s: unexpected remaining pods after DeleteOrEvictPods; actual %v; expected %v", tc.description, remainingPods, expected) } </ins> <del> // Test that pods were evicted as expected var actualEvictions []policyv1beta1.Eviction for _, action := range k.Actions() { if action.GetVerb() != "create" || action.GetResource().Resource != "pods" || action.GetSubresource() != "eviction" { continue } eviction := *action.(ktest.CreateAction).GetObject().(*policyv1beta1.Eviction) actualEvictions = append(actualEvictions, eviction) } sort.Slice(actualEvictions, func(i, j int) bool { return actualEvictions[i].Name < actualEvictions[j].Name }) if !reflect.DeepEqual(actualEvictions, expectedEvictions) { t.Errorf("unexpected evictions; actual %v; expected %v", actualEvictions, expectedEvictions) </del> <ins> // Test that pods were evicted as expected var actualEvictions []policyv1beta1.Eviction for _, action := range k.Actions() { if action.GetVerb() != "create" || action.GetResource().Resource != "pods" || action.GetSubresource() != "eviction" { continue </ins> } <ins> eviction := *action.(ktest.CreateAction).GetObject().(*policyv1beta1.Eviction) actualEvictions = append(actualEvictions, eviction) } sort.Slice(actualEvictions, func(i, j int) bool { return actualEvictions[i].Name < actualEvictions[j].Name </ins> }) <ins> if !reflect.DeepEqual(actualEvictions, expectedEvictions) { t.Errorf("%s: unexpected evictions; actual %v; expected %v", tc.description, actualEvictions, expectedEvictions) } }) </ins> } }

Related discussion:
text: I'm going to be performing the calculation of when it's appropriate to evict/delete outside of the drain library, and I suspect most will be as well, so there's not really a great incentive to do it in the drain library itself IMO.
That's all good, I have no issue using the flag as long as does error out and return a non-zero code as expected (there's been a few times where it seems to error out, but still return 0)