Cleanup the default_preemption_test by indexing the potential victim pods

This commit is contained in:
Michal Wozniak 2022-11-09 10:26:08 +01:00
parent 818e180300
commit b3e9d8ef4c

View File

@ -328,21 +328,18 @@ func TestPostFilter(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cs := clientsetfake.NewSimpleClientset()
// index the potential victim pods in the fake client so that the victims deletion logic does not fail
podItems := []v1.Pod{}
for _, pod := range tt.pods {
podItems = append(podItems, *pod)
}
cs := clientsetfake.NewSimpleClientset(&v1.PodList{Items: podItems})
informerFactory := informers.NewSharedInformerFactory(cs, 0)
podInformer := informerFactory.Core().V1().Pods().Informer()
podInformer.GetStore().Add(tt.pod)
for i := range tt.pods {
podInformer.GetStore().Add(tt.pods[i])
}
// As we use a bare clientset above, it's needed to add a reactor here
// to not fail Victims deletion logic.
cs.PrependReactor("patch", "pods", func(action clienttesting.Action) (bool, runtime.Object, error) {
return true, nil, nil
})
cs.PrependReactor("delete", "pods", func(action clienttesting.Action) (bool, runtime.Object, error) {
return true, nil, nil
})
// Register NodeResourceFit as the Filter & PreFilter plugin.
registeredPlugins := []st.RegisterPluginFunc{
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),