Refactor scheduler preempt interface
- replace error with NodeToStatusMap in Preempt() signature - eliminate podPreemptor interface and expose its functions statelessly - move logic in scheduler.go#preempt to generic_scheduler.go#Preempt()
This commit is contained in:
@@ -23,6 +23,9 @@ import (
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
clientsetfake "k8s.io/client-go/kubernetes/fake"
|
||||
clienttesting "k8s.io/client-go/testing"
|
||||
extenderv1 "k8s.io/kube-scheduler/extender/v1"
|
||||
)
|
||||
|
||||
@@ -114,3 +117,57 @@ func TestMoreImportantPod(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveNominatedNodeName(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
currentNominatedNodeName string
|
||||
newNominatedNodeName string
|
||||
expectedPatchRequests int
|
||||
expectedPatchData string
|
||||
}{
|
||||
{
|
||||
name: "Should make patch request to clear node name",
|
||||
currentNominatedNodeName: "node1",
|
||||
expectedPatchRequests: 1,
|
||||
expectedPatchData: `{"status":{"nominatedNodeName":null}}`,
|
||||
},
|
||||
{
|
||||
name: "Should not make patch request if nominated node is already cleared",
|
||||
currentNominatedNodeName: "",
|
||||
expectedPatchRequests: 0,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
actualPatchRequests := 0
|
||||
var actualPatchData string
|
||||
cs := &clientsetfake.Clientset{}
|
||||
cs.AddReactor("patch", "pods", func(action clienttesting.Action) (bool, runtime.Object, error) {
|
||||
actualPatchRequests++
|
||||
patch := action.(clienttesting.PatchAction)
|
||||
actualPatchData = string(patch.GetPatch())
|
||||
// For this test, we don't care about the result of the patched pod, just that we got the expected
|
||||
// patch request, so just returning &v1.Pod{} here is OK because scheduler doesn't use the response.
|
||||
return true, &v1.Pod{}, nil
|
||||
})
|
||||
|
||||
pod := &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
|
||||
Status: v1.PodStatus{NominatedNodeName: test.currentNominatedNodeName},
|
||||
}
|
||||
|
||||
if err := ClearNominatedNodeName(cs, pod); err != nil {
|
||||
t.Fatalf("Error calling removeNominatedNodeName: %v", err)
|
||||
}
|
||||
|
||||
if actualPatchRequests != test.expectedPatchRequests {
|
||||
t.Fatalf("Actual patch requests (%d) dos not equal expected patch requests (%d)", actualPatchRequests, test.expectedPatchRequests)
|
||||
}
|
||||
|
||||
if test.expectedPatchRequests > 0 && actualPatchData != test.expectedPatchData {
|
||||
t.Fatalf("Patch data mismatch: Actual was %v, but expected %v", actualPatchData, test.expectedPatchData)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user