diff --git a/pkg/scheduler/plugins/reservation/nominator_test.go b/pkg/scheduler/plugins/reservation/nominator_test.go index fdd92c0e1..b76cb8e9b 100644 --- a/pkg/scheduler/plugins/reservation/nominator_test.go +++ b/pkg/scheduler/plugins/reservation/nominator_test.go @@ -289,9 +289,11 @@ func TestNominateReservation(t *testing.T) { cycleState := framework.NewCycleState() requests := apiresource.PodRequests(tt.pod, apiresource.PodResourcesOptions{}) state := &stateData{ - nodeReservationStates: map[string]nodeReservationState{}, - podRequests: requests, - podRequestsResources: framework.NewResource(requests), + schedulingStateData: schedulingStateData{ + nodeReservationStates: map[string]nodeReservationState{}, + podRequests: requests, + podRequestsResources: framework.NewResource(requests), + }, } for _, reservation := range tt.reservations { rInfo := frameworkext.NewReservationInfo(reservation) diff --git a/pkg/scheduler/plugins/reservation/plugin.go b/pkg/scheduler/plugins/reservation/plugin.go index b36ddf065..d3b632d21 100644 --- a/pkg/scheduler/plugins/reservation/plugin.go +++ b/pkg/scheduler/plugins/reservation/plugin.go @@ -149,6 +149,19 @@ func (pl *Plugin) EventsToRegister() []framework.ClusterEventWithHint { var _ framework.StateData = &stateData{} type stateData struct { + // scheduling cycle data + schedulingStateData + + // all cycle data + // NOTE: The part of data is kept during both the scheduling cycle and the binding cycle. In case too many + // binding goroutines reference the data causing OOM issues, the memory overhead of this part should be + // small and its space complexity should be no more than O(1) for pods, reservations and nodes. + assumed *frameworkext.ReservationInfo +} + +// schedulingStateData is the data only kept in the scheduling cycle. It could be cleaned up +// before entering the binding cycle to reduce memory cost. +type schedulingStateData struct { preemptLock sync.RWMutex hasAffinity bool podRequests corev1.ResourceList @@ -159,7 +172,6 @@ type stateData struct { nodeReservationStates map[string]nodeReservationState nodeReservationDiagnosis map[string]*nodeDiagnosisState preferredNode string - assumed *frameworkext.ReservationInfo } type nodeReservationState struct { @@ -183,13 +195,15 @@ type nodeDiagnosisState struct { func (s *stateData) Clone() framework.StateData { ns := &stateData{ - hasAffinity: s.hasAffinity, - podRequests: s.podRequests, - podRequestsResources: s.podRequestsResources, - nodeReservationStates: s.nodeReservationStates, - nodeReservationDiagnosis: s.nodeReservationDiagnosis, - preferredNode: s.preferredNode, - assumed: s.assumed, + schedulingStateData: schedulingStateData{ + hasAffinity: s.hasAffinity, + podRequests: s.podRequests, + podRequestsResources: s.podRequestsResources, + nodeReservationStates: s.nodeReservationStates, + nodeReservationDiagnosis: s.nodeReservationDiagnosis, + preferredNode: s.preferredNode, + }, + assumed: s.assumed, } s.preemptLock.RLock() @@ -217,6 +231,12 @@ func (s *stateData) Clone() framework.StateData { return ns } +// CleanSchedulingData clears the scheduling cycle data in the stateData to reduce memory cost before entering +// the binding cycle. +func (s *stateData) CleanSchedulingData() { + s.schedulingStateData = schedulingStateData{} +} + func getStateData(cycleState *framework.CycleState) *stateData { v, err := cycleState.Read(stateKey) if err != nil { @@ -669,6 +689,8 @@ func (pl *Plugin) Reserve(ctx context.Context, cycleState *framework.CycleState, return framework.NewStatus(framework.Unschedulable, ErrReasonReservationAffinity) } klog.V(5).Infof("Skip reserve with reservation since there are no matched reservations, pod %v, node: %v", klog.KObj(pod), nodeName) + // clean scheduling cycle to avoid unnecessary memory cost before entering the binding + state.CleanSchedulingData() return nil } pl.handle.GetReservationNominator().AddNominatedReservation(pod, nodeName, nominatedReservation) @@ -680,6 +702,8 @@ func (pl *Plugin) Reserve(ctx context.Context, cycleState *framework.CycleState, return framework.AsStatus(err) } state.assumed = nominatedReservation.Clone() + // clean scheduling cycle to avoid unnecessary memory cost before entering the binding + state.CleanSchedulingData() klog.V(4).InfoS("Reserve pod to node with reservations", "pod", klog.KObj(pod), "node", nodeName, "assumed", klog.KObj(nominatedReservation)) return nil } diff --git a/pkg/scheduler/plugins/reservation/plugin_test.go b/pkg/scheduler/plugins/reservation/plugin_test.go index f6a0503e4..fecd89f21 100644 --- a/pkg/scheduler/plugins/reservation/plugin_test.go +++ b/pkg/scheduler/plugins/reservation/plugin_test.go @@ -314,8 +314,10 @@ func TestPreFilter(t *testing.T) { assert.NoError(t, err) cycleState := framework.NewCycleState() cycleState.Write(stateKey, &stateData{ - hasAffinity: reservationAffinity != nil, - nodeReservationStates: tt.nodeReservationStates, + schedulingStateData: schedulingStateData{ + hasAffinity: reservationAffinity != nil, + nodeReservationStates: tt.nodeReservationStates, + }, }) preRes, got := pl.PreFilter(context.TODO(), cycleState, tt.pod) assert.Equal(t, tt.wantStatus, got) @@ -524,7 +526,9 @@ func TestFilter(t *testing.T) { pod: &corev1.Pod{}, nodeInfo: testNodeInfo, stateData: &stateData{ - hasAffinity: true, + schedulingStateData: schedulingStateData{ + hasAffinity: true, + }, }, want: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonReservationAffinity), }, @@ -545,11 +549,13 @@ func TestFilter(t *testing.T) { }, nodeInfo: testNodeInfo, stateData: &stateData{ - hasAffinity: true, - nodeReservationStates: map[string]nodeReservationState{ - testNode.Name: { - matched: []*frameworkext.ReservationInfo{ - frameworkext.NewReservationInfo(reservation), + schedulingStateData: schedulingStateData{ + hasAffinity: true, + nodeReservationStates: map[string]nodeReservationState{ + testNode.Name: { + matched: []*frameworkext.ReservationInfo{ + frameworkext.NewReservationInfo(reservation), + }, }, }, }, @@ -602,18 +608,20 @@ func TestFilterWithPreemption(t *testing.T) { { name: "successfully filter non-reservations with preemption", stateData: &stateData{ - podRequestsResources: &framework.Resource{ - MilliCPU: 4 * 1000, - }, - preemptible: map[string]corev1.ResourceList{ - node.Name: { - corev1.ResourceCPU: resource.MustParse("4"), + schedulingStateData: schedulingStateData{ + podRequestsResources: &framework.Resource{ + MilliCPU: 4 * 1000, }, - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 32 * 1000, + preemptible: map[string]corev1.ResourceList{ + node.Name: { + corev1.ResourceCPU: resource.MustParse("4"), + }, + }, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 32 * 1000, + }, }, }, }, @@ -623,18 +631,20 @@ func TestFilterWithPreemption(t *testing.T) { { name: "failed to filter non-reservations with preemption", stateData: &stateData{ - podRequestsResources: &framework.Resource{ - MilliCPU: 4 * 1000, - }, - preemptible: map[string]corev1.ResourceList{ - node.Name: { - corev1.ResourceCPU: resource.MustParse("2"), + schedulingStateData: schedulingStateData{ + podRequestsResources: &framework.Resource{ + MilliCPU: 4 * 1000, }, - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 32 * 1000, + preemptible: map[string]corev1.ResourceList{ + node.Name: { + corev1.ResourceCPU: resource.MustParse("2"), + }, + }, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 32 * 1000, + }, }, }, }, @@ -644,14 +654,16 @@ func TestFilterWithPreemption(t *testing.T) { { name: "filter non-reservations with preemption but no preemptible resources", stateData: &stateData{ - podRequestsResources: &framework.Resource{ - MilliCPU: 4 * 1000, - }, - preemptible: map[string]corev1.ResourceList{}, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 32 * 1000, + schedulingStateData: schedulingStateData{ + podRequestsResources: &framework.Resource{ + MilliCPU: 4 * 1000, + }, + preemptible: map[string]corev1.ResourceList{}, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 32 * 1000, + }, }, }, }, @@ -697,41 +709,43 @@ func Test_filterWithReservations(t *testing.T) { { name: "filter aligned reservation with nodeInfo", stateData: &stateData{ - podRequests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("8"), - corev1.ResourceMemory: resource.MustParse("8Gi"), - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 30 * 1000, - Memory: 24 * 1024 * 1024 * 1024, - }, - rAllocated: &framework.Resource{ - MilliCPU: 0, - }, - matched: []*frameworkext.ReservationInfo{ - frameworkext.NewReservationInfo(&schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyAligned, - Template: &corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), + schedulingStateData: schedulingStateData{ + podRequests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("8"), + corev1.ResourceMemory: resource.MustParse("8Gi"), + }, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 30 * 1000, + Memory: 24 * 1024 * 1024 * 1024, + }, + rAllocated: &framework.Resource{ + MilliCPU: 0, + }, + matched: []*frameworkext.ReservationInfo{ + frameworkext.NewReservationInfo(&schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyAligned, + Template: &corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, }, }, }, }, }, }, - }, - }), + }), + }, }, }, }, @@ -741,42 +755,44 @@ func Test_filterWithReservations(t *testing.T) { { name: "failed to filter aligned reservation with nodeInfo", stateData: &stateData{ - hasAffinity: true, - podRequests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("8"), - corev1.ResourceMemory: resource.MustParse("8Gi"), - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 32 * 1000, // no remaining resources - Memory: 24 * 1024 * 1024 * 1024, - }, - rAllocated: &framework.Resource{ - MilliCPU: 0, - }, - matched: []*frameworkext.ReservationInfo{ - frameworkext.NewReservationInfo(&schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyAligned, - Template: &corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), + schedulingStateData: schedulingStateData{ + hasAffinity: true, + podRequests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("8"), + corev1.ResourceMemory: resource.MustParse("8Gi"), + }, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 32 * 1000, // no remaining resources + Memory: 24 * 1024 * 1024 * 1024, + }, + rAllocated: &framework.Resource{ + MilliCPU: 0, + }, + matched: []*frameworkext.ReservationInfo{ + frameworkext.NewReservationInfo(&schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyAligned, + Template: &corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, }, }, }, }, }, }, - }, - }), + }), + }, }, }, }, @@ -786,41 +802,43 @@ func Test_filterWithReservations(t *testing.T) { { name: "filter restricted reservation with nodeInfo", stateData: &stateData{ - podRequests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - corev1.ResourceMemory: resource.MustParse("8Gi"), - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 30 * 1000, - Memory: 24 * 1024 * 1024 * 1024, - }, - rAllocated: &framework.Resource{ - MilliCPU: 0, - }, - matched: []*frameworkext.ReservationInfo{ - frameworkext.NewReservationInfo(&schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, - Template: &corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), + schedulingStateData: schedulingStateData{ + podRequests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + corev1.ResourceMemory: resource.MustParse("8Gi"), + }, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 30 * 1000, + Memory: 24 * 1024 * 1024 * 1024, + }, + rAllocated: &framework.Resource{ + MilliCPU: 0, + }, + matched: []*frameworkext.ReservationInfo{ + frameworkext.NewReservationInfo(&schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + Template: &corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, }, }, }, }, }, }, - }, - }), + }), + }, }, }, }, @@ -830,42 +848,44 @@ func Test_filterWithReservations(t *testing.T) { { name: "failed to filter restricted reservation with nodeInfo", stateData: &stateData{ - hasAffinity: true, - podRequests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("8"), - corev1.ResourceMemory: resource.MustParse("8Gi"), - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 30 * 1000, - Memory: 24 * 1024 * 1024 * 1024, - }, - rAllocated: &framework.Resource{ - MilliCPU: 0, - }, - matched: []*frameworkext.ReservationInfo{ - frameworkext.NewReservationInfo(&schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, - Template: &corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), + schedulingStateData: schedulingStateData{ + hasAffinity: true, + podRequests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("8"), + corev1.ResourceMemory: resource.MustParse("8Gi"), + }, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 30 * 1000, + Memory: 24 * 1024 * 1024 * 1024, + }, + rAllocated: &framework.Resource{ + MilliCPU: 0, + }, + matched: []*frameworkext.ReservationInfo{ + frameworkext.NewReservationInfo(&schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + Template: &corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, }, }, }, }, }, }, - }, - }), + }), + }, }, }, }, @@ -875,40 +895,42 @@ func Test_filterWithReservations(t *testing.T) { { name: "filter default reservations with preemption", stateData: &stateData{ - podRequestsResources: &framework.Resource{ - MilliCPU: 4 * 1000, - }, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ - node.Name: { - "123456": { - corev1.ResourceCPU: resource.MustParse("4"), + schedulingStateData: schedulingStateData{ + podRequestsResources: &framework.Resource{ + MilliCPU: 4 * 1000, + }, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ + node.Name: { + "123456": { + corev1.ResourceCPU: resource.MustParse("4"), + }, }, }, - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 36 * 1000, - }, - rAllocated: &framework.Resource{ - MilliCPU: 6000, - }, - matched: []*frameworkext.ReservationInfo{ - { - Reservation: &schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - UID: "123456", + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 36 * 1000, + }, + rAllocated: &framework.Resource{ + MilliCPU: 6000, + }, + matched: []*frameworkext.ReservationInfo{ + { + Reservation: &schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + UID: "123456", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyDefault, + }, }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyDefault, + Allocatable: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, + Allocated: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), }, - }, - Allocatable: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - }, - Allocated: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), }, }, }, @@ -920,45 +942,47 @@ func Test_filterWithReservations(t *testing.T) { { name: "filter default reservations with preempt from reservation and node", stateData: &stateData{ - podRequestsResources: &framework.Resource{ - MilliCPU: 4 * 1000, - }, - preemptible: map[string]corev1.ResourceList{ - node.Name: { - corev1.ResourceCPU: resource.MustParse("2"), + schedulingStateData: schedulingStateData{ + podRequestsResources: &framework.Resource{ + MilliCPU: 4 * 1000, }, - }, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ - node.Name: { - "123456": { + preemptible: map[string]corev1.ResourceList{ + node.Name: { corev1.ResourceCPU: resource.MustParse("2"), }, }, - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 38 * 1000, - }, - rAllocated: &framework.Resource{ - MilliCPU: 6000, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ + node.Name: { + "123456": { + corev1.ResourceCPU: resource.MustParse("2"), + }, }, - matched: []*frameworkext.ReservationInfo{ - { - Reservation: &schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - UID: "123456", + }, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 38 * 1000, + }, + rAllocated: &framework.Resource{ + MilliCPU: 6000, + }, + matched: []*frameworkext.ReservationInfo{ + { + Reservation: &schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + UID: "123456", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyDefault, + }, }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyDefault, + Allocatable: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, + Allocated: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), }, - }, - Allocatable: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - }, - Allocated: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), }, }, }, @@ -970,45 +994,47 @@ func Test_filterWithReservations(t *testing.T) { { name: "failed to filter default reservations with preempt from reservation", stateData: &stateData{ - hasAffinity: true, - podRequests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("4"), - }, - podRequestsResources: &framework.Resource{ - MilliCPU: 4 * 1000, - }, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ - node.Name: { - "123456": { - corev1.ResourceCPU: resource.MustParse("2"), - }, + schedulingStateData: schedulingStateData{ + hasAffinity: true, + podRequests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("4"), }, - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 38 * 1000, - }, - rAllocated: &framework.Resource{ - MilliCPU: 6000, + podRequestsResources: &framework.Resource{ + MilliCPU: 4 * 1000, + }, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ + node.Name: { + "123456": { + corev1.ResourceCPU: resource.MustParse("2"), + }, }, - matched: []*frameworkext.ReservationInfo{ - { - Reservation: &schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - UID: "123456", + }, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 38 * 1000, + }, + rAllocated: &framework.Resource{ + MilliCPU: 6000, + }, + matched: []*frameworkext.ReservationInfo{ + { + Reservation: &schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + UID: "123456", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyDefault, + }, }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyDefault, + ResourceNames: []corev1.ResourceName{corev1.ResourceCPU}, + Allocatable: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, + Allocated: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), }, - }, - ResourceNames: []corev1.ResourceName{corev1.ResourceCPU}, - Allocatable: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - }, - Allocated: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), }, }, }, @@ -1020,43 +1046,45 @@ func Test_filterWithReservations(t *testing.T) { { name: "failed to filter default reservations with preempt from node", stateData: &stateData{ - hasAffinity: true, - podRequests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("4"), - }, - podRequestsResources: &framework.Resource{ - MilliCPU: 4 * 1000, - }, - preemptible: map[string]corev1.ResourceList{ - node.Name: { - corev1.ResourceCPU: resource.MustParse("2"), + schedulingStateData: schedulingStateData{ + hasAffinity: true, + podRequests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("4"), }, - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 38 * 1000, - }, - rAllocated: &framework.Resource{ - MilliCPU: 6000, + podRequestsResources: &framework.Resource{ + MilliCPU: 4 * 1000, + }, + preemptible: map[string]corev1.ResourceList{ + node.Name: { + corev1.ResourceCPU: resource.MustParse("2"), }, - matched: []*frameworkext.ReservationInfo{ - { - Reservation: &schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - UID: "123456", + }, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 38 * 1000, + }, + rAllocated: &framework.Resource{ + MilliCPU: 6000, + }, + matched: []*frameworkext.ReservationInfo{ + { + Reservation: &schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + UID: "123456", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyDefault, + }, }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyDefault, + ResourceNames: []corev1.ResourceName{corev1.ResourceCPU}, + Allocatable: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, + Allocated: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), }, - }, - ResourceNames: []corev1.ResourceName{corev1.ResourceCPU}, - Allocatable: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - }, - Allocated: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), }, }, }, @@ -1068,43 +1096,45 @@ func Test_filterWithReservations(t *testing.T) { { name: "filter restricted reservations with preempt from reservation", stateData: &stateData{ - podRequests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("4"), - }, - podRequestsResources: &framework.Resource{ - MilliCPU: 4 * 1000, - }, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ - node.Name: { - "123456": { - corev1.ResourceCPU: resource.MustParse("4"), - }, + schedulingStateData: schedulingStateData{ + podRequests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("4"), }, - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 38 * 1000, - }, - rAllocated: &framework.Resource{ - MilliCPU: 6000, + podRequestsResources: &framework.Resource{ + MilliCPU: 4 * 1000, + }, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ + node.Name: { + "123456": { + corev1.ResourceCPU: resource.MustParse("4"), + }, }, - matched: []*frameworkext.ReservationInfo{ - { - Reservation: &schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - UID: "123456", + }, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 38 * 1000, + }, + rAllocated: &framework.Resource{ + MilliCPU: 6000, + }, + matched: []*frameworkext.ReservationInfo{ + { + Reservation: &schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + UID: "123456", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + }, }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + Allocatable: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, + Allocated: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), }, - }, - Allocatable: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - }, - Allocated: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), }, }, }, @@ -1116,44 +1146,46 @@ func Test_filterWithReservations(t *testing.T) { { name: "failed to filter restricted reservations with preempt from node", stateData: &stateData{ - hasAffinity: true, - podRequests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("4"), - }, - podRequestsResources: &framework.Resource{ - MilliCPU: 4 * 1000, - }, - preemptible: map[string]corev1.ResourceList{ - node.Name: { + schedulingStateData: schedulingStateData{ + hasAffinity: true, + podRequests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("4"), }, - }, - preemptibleInRRs: nil, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 38 * 1000, - }, - rAllocated: &framework.Resource{ - MilliCPU: 6000, + podRequestsResources: &framework.Resource{ + MilliCPU: 4 * 1000, + }, + preemptible: map[string]corev1.ResourceList{ + node.Name: { + corev1.ResourceCPU: resource.MustParse("4"), }, - matched: []*frameworkext.ReservationInfo{ - { - Reservation: &schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - UID: "123456", + }, + preemptibleInRRs: nil, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 38 * 1000, + }, + rAllocated: &framework.Resource{ + MilliCPU: 6000, + }, + matched: []*frameworkext.ReservationInfo{ + { + Reservation: &schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + UID: "123456", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + }, }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + ResourceNames: []corev1.ResourceName{corev1.ResourceCPU}, + Allocatable: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, + Allocated: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), }, - }, - ResourceNames: []corev1.ResourceName{corev1.ResourceCPU}, - Allocatable: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - }, - Allocated: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), }, }, }, @@ -1165,62 +1197,64 @@ func Test_filterWithReservations(t *testing.T) { { name: "failed to filter multiple restricted reservations with preempt from node", stateData: &stateData{ - hasAffinity: true, - podRequests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("4"), - }, - podRequestsResources: &framework.Resource{ - MilliCPU: 4 * 1000, - }, - preemptible: map[string]corev1.ResourceList{ - node.Name: { + schedulingStateData: schedulingStateData{ + hasAffinity: true, + podRequests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("4"), }, - }, - preemptibleInRRs: nil, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 38 * 1000, - }, - rAllocated: &framework.Resource{ - MilliCPU: 10000, + podRequestsResources: &framework.Resource{ + MilliCPU: 4 * 1000, + }, + preemptible: map[string]corev1.ResourceList{ + node.Name: { + corev1.ResourceCPU: resource.MustParse("4"), }, - matched: []*frameworkext.ReservationInfo{ - { - Reservation: &schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - UID: "123456", + }, + preemptibleInRRs: nil, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 38 * 1000, + }, + rAllocated: &framework.Resource{ + MilliCPU: 10000, + }, + matched: []*frameworkext.ReservationInfo{ + { + Reservation: &schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + UID: "123456", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + }, }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + ResourceNames: []corev1.ResourceName{corev1.ResourceCPU}, + Allocatable: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, + Allocated: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), }, }, - ResourceNames: []corev1.ResourceName{corev1.ResourceCPU}, - Allocatable: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - }, - Allocated: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - }, - }, - { - Reservation: &schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r-1", - UID: "7891011", + { + Reservation: &schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r-1", + UID: "7891011", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + }, }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + ResourceNames: []corev1.ResourceName{corev1.ResourceCPU}, + Allocatable: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("4"), + }, + Allocated: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("1"), }, - }, - ResourceNames: []corev1.ResourceName{corev1.ResourceCPU}, - Allocatable: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("4"), - }, - Allocated: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("1"), }, }, }, @@ -1232,52 +1266,54 @@ func Test_filterWithReservations(t *testing.T) { { name: "failed to filter restricted reservations with preempt from reservation and node", stateData: &stateData{ - hasAffinity: true, - podRequests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("4"), - }, - podRequestsResources: &framework.Resource{ - MilliCPU: 4 * 1000, - }, - preemptible: map[string]corev1.ResourceList{ - node.Name: { - corev1.ResourceCPU: resource.MustParse("2"), + schedulingStateData: schedulingStateData{ + hasAffinity: true, + podRequests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("4"), }, - }, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ - node.Name: { - "123456": { + podRequestsResources: &framework.Resource{ + MilliCPU: 4 * 1000, + }, + preemptible: map[string]corev1.ResourceList{ + node.Name: { corev1.ResourceCPU: resource.MustParse("2"), }, }, - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 38 * 1000, - }, - rAllocated: &framework.Resource{ - MilliCPU: 6000, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ + node.Name: { + "123456": { + corev1.ResourceCPU: resource.MustParse("2"), + }, }, - matched: []*frameworkext.ReservationInfo{ - { - Reservation: &schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - UID: "123456", + }, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 38 * 1000, + }, + rAllocated: &framework.Resource{ + MilliCPU: 6000, + }, + matched: []*frameworkext.ReservationInfo{ + { + Reservation: &schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + UID: "123456", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + }, }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + Allocatable: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, + Allocated: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, + ResourceNames: []corev1.ResourceName{ + corev1.ResourceCPU, }, - }, - Allocatable: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - }, - Allocated: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - }, - ResourceNames: []corev1.ResourceName{ - corev1.ResourceCPU, }, }, }, @@ -1289,53 +1325,55 @@ func Test_filterWithReservations(t *testing.T) { { name: "filter restricted reservations with preempt from reservation and node", stateData: &stateData{ - podRequests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("4"), - corev1.ResourceMemory: resource.MustParse("4Gi"), - }, - podRequestsResources: &framework.Resource{ - MilliCPU: 4 * 1000, - Memory: 4 * 1024 * 1024 * 1024, - }, - preemptible: map[string]corev1.ResourceList{ - node.Name: { - corev1.ResourceMemory: resource.MustParse("32Gi"), + schedulingStateData: schedulingStateData{ + podRequests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("4"), + corev1.ResourceMemory: resource.MustParse("4Gi"), }, - }, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ - node.Name: { - "123456": { - corev1.ResourceCPU: resource.MustParse("4"), - }, + podRequestsResources: &framework.Resource{ + MilliCPU: 4 * 1000, + Memory: 4 * 1024 * 1024 * 1024, }, - }, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - podRequested: &framework.Resource{ - MilliCPU: 38 * 1000, + preemptible: map[string]corev1.ResourceList{ + node.Name: { + corev1.ResourceMemory: resource.MustParse("32Gi"), }, - rAllocated: &framework.Resource{ - MilliCPU: 6000, + }, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ + node.Name: { + "123456": { + corev1.ResourceCPU: resource.MustParse("4"), + }, }, - matched: []*frameworkext.ReservationInfo{ - { - Reservation: &schedulingv1alpha1.Reservation{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-r", - UID: "123456", + }, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + podRequested: &framework.Resource{ + MilliCPU: 38 * 1000, + }, + rAllocated: &framework.Resource{ + MilliCPU: 6000, + }, + matched: []*frameworkext.ReservationInfo{ + { + Reservation: &schedulingv1alpha1.Reservation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-r", + UID: "123456", + }, + Spec: schedulingv1alpha1.ReservationSpec{ + AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + }, }, - Spec: schedulingv1alpha1.ReservationSpec{ - AllocatePolicy: schedulingv1alpha1.ReservationAllocatePolicyRestricted, + Allocatable: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, + Allocated: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("6"), + }, + ResourceNames: []corev1.ResourceName{ + corev1.ResourceCPU, }, - }, - Allocatable: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - }, - Allocated: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("6"), - }, - ResourceNames: []corev1.ResourceName{ - corev1.ResourceCPU, }, }, }, @@ -1380,8 +1418,10 @@ func TestPreFilterExtensionAddPod(t *testing.T) { name: "with BestEffort Pod", pod: &corev1.Pod{}, state: &stateData{ - preemptible: map[string]corev1.ResourceList{}, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, + schedulingStateData: schedulingStateData{ + preemptible: map[string]corev1.ResourceList{}, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, + }, }, wantPreemptible: map[string]corev1.ResourceList{}, wantPreemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, @@ -1407,12 +1447,14 @@ func TestPreFilterExtensionAddPod(t *testing.T) { }, }, state: &stateData{ - preemptible: map[string]corev1.ResourceList{ - node.Name: { - corev1.ResourceCPU: resource.MustParse("4"), + schedulingStateData: schedulingStateData{ + preemptible: map[string]corev1.ResourceList{ + node.Name: { + corev1.ResourceCPU: resource.MustParse("4"), + }, }, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, }, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, }, wantPreemptible: map[string]corev1.ResourceList{ "test-node": { @@ -1443,11 +1485,13 @@ func TestPreFilterExtensionAddPod(t *testing.T) { }, withR: true, state: &stateData{ - preemptible: map[string]corev1.ResourceList{}, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ - node.Name: { - "123456": { - corev1.ResourceCPU: resource.MustParse("4"), + schedulingStateData: schedulingStateData{ + preemptible: map[string]corev1.ResourceList{}, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ + node.Name: { + "123456": { + corev1.ResourceCPU: resource.MustParse("4"), + }, }, }, }, @@ -1483,8 +1527,10 @@ func TestPreFilterExtensionAddPod(t *testing.T) { }, withR: true, state: &stateData{ - preemptible: map[string]corev1.ResourceList{}, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, + schedulingStateData: schedulingStateData{ + preemptible: map[string]corev1.ResourceList{}, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, + }, }, wantPreemptible: map[string]corev1.ResourceList{}, wantPreemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{ @@ -1614,8 +1660,10 @@ func TestPreFilterExtensionRemovePod(t *testing.T) { pl := p.(*Plugin) cycleState := framework.NewCycleState() cycleState.Write(stateKey, &stateData{ - preemptible: map[string]corev1.ResourceList{}, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, + schedulingStateData: schedulingStateData{ + preemptible: map[string]corev1.ResourceList{}, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, + }, }) if tt.withR { reservation := &schedulingv1alpha1.Reservation{ @@ -1808,9 +1856,11 @@ func TestFilterReservation(t *testing.T) { } state := &stateData{ - nodeReservationStates: map[string]nodeReservationState{}, - podRequests: tt.podRequests, - podRequestsResources: framework.NewResource(tt.podRequests), + schedulingStateData: schedulingStateData{ + nodeReservationStates: map[string]nodeReservationState{}, + podRequests: tt.podRequests, + podRequestsResources: framework.NewResource(tt.podRequests), + }, } for _, v := range tt.reservations { pl.reservationCache.updateReservation(v) @@ -2043,8 +2093,10 @@ func TestPostFilter(t *testing.T) { cycleState := framework.NewCycleState() if tt.args.hasStateData { cycleState.Write(stateKey, &stateData{ - hasAffinity: tt.args.hasAffinity, - nodeReservationDiagnosis: tt.args.nodeReservationDiagnosis, + schedulingStateData: schedulingStateData{ + hasAffinity: tt.args.hasAffinity, + nodeReservationDiagnosis: tt.args.nodeReservationDiagnosis, + }, }) } got, got1 := pl.PostFilter(context.TODO(), cycleState, nil, tt.args.filteredNodeStatusMap) @@ -2184,6 +2236,7 @@ func TestReserve(t *testing.T) { if tt.reservation != nil { rInfo := pl.reservationCache.getReservationInfoByUID(tt.reservation.UID) assert.Equal(t, tt.wantPods, rInfo.AssignedPods) + assert.Equal(t, &schedulingStateData{}, &state.schedulingStateData) } }) } diff --git a/pkg/scheduler/plugins/reservation/scoring_test.go b/pkg/scheduler/plugins/reservation/scoring_test.go index b432fb479..564c74627 100644 --- a/pkg/scheduler/plugins/reservation/scoring_test.go +++ b/pkg/scheduler/plugins/reservation/scoring_test.go @@ -219,7 +219,9 @@ func TestScore(t *testing.T) { cycleState := framework.NewCycleState() state := &stateData{ - nodeReservationStates: map[string]nodeReservationState{}, + schedulingStateData: schedulingStateData{ + nodeReservationStates: map[string]nodeReservationState{}, + }, } state.podRequests = apiresource.PodRequests(tt.pod, apiresource.PodResourcesOptions{}) state.podRequestsResources = framework.NewResource(state.podRequests) @@ -321,7 +323,9 @@ func TestScoreWithOrder(t *testing.T) { pl := p.(*Plugin) state := &stateData{ - nodeReservationStates: map[string]nodeReservationState{}, + schedulingStateData: schedulingStateData{ + nodeReservationStates: map[string]nodeReservationState{}, + }, } state.podRequests = apiresource.PodRequests(normalPod, apiresource.PodResourcesOptions{}) state.podRequestsResources = framework.NewResource(state.podRequests) @@ -692,7 +696,9 @@ func TestPreScoreWithNominateReservation(t *testing.T) { pl := plugin.(*Plugin) cycleState := framework.NewCycleState() state := &stateData{ - nodeReservationStates: map[string]nodeReservationState{}, + schedulingStateData: schedulingStateData{ + nodeReservationStates: map[string]nodeReservationState{}, + }, } state.podRequests = apiresource.PodRequests(tt.pod, apiresource.PodResourcesOptions{}) state.podRequestsResources = framework.NewResource(state.podRequests) diff --git a/pkg/scheduler/plugins/reservation/transformer.go b/pkg/scheduler/plugins/reservation/transformer.go index 22862ea04..b481e893f 100644 --- a/pkg/scheduler/plugins/reservation/transformer.go +++ b/pkg/scheduler/plugins/reservation/transformer.go @@ -238,13 +238,15 @@ func (pl *Plugin) prepareMatchReservationState(ctx context.Context, cycleState * allNodeDiagnosisStates = allNodeDiagnosisStates[:diagnosisIndex] podRequestResources := framework.NewResource(podRequests) state := &stateData{ - hasAffinity: reservationAffinity != nil, - podRequests: podRequests, - podRequestsResources: podRequestResources, - preemptible: map[string]corev1.ResourceList{}, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, - nodeReservationStates: map[string]nodeReservationState{}, - nodeReservationDiagnosis: map[string]*nodeDiagnosisState{}, + schedulingStateData: schedulingStateData{ + hasAffinity: reservationAffinity != nil, + podRequests: podRequests, + podRequestsResources: podRequestResources, + preemptible: map[string]corev1.ResourceList{}, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, + nodeReservationStates: map[string]nodeReservationState{}, + nodeReservationDiagnosis: map[string]*nodeDiagnosisState{}, + }, } pluginToNodeReservationRestoreState := frameworkext.PluginToNodeReservationRestoreStates{} for index := range allNodeReservationStates { diff --git a/pkg/scheduler/plugins/reservation/transformer_test.go b/pkg/scheduler/plugins/reservation/transformer_test.go index e78099f3f..2767ee6c7 100644 --- a/pkg/scheduler/plugins/reservation/transformer_test.go +++ b/pkg/scheduler/plugins/reservation/transformer_test.go @@ -307,27 +307,29 @@ func TestRestoreReservation(t *testing.T) { matchRInfo := pl.reservationCache.getReservationInfoByUID(matchedReservation.UID) expectedStat := &stateData{ - podRequests: corev1.ResourceList{}, - podRequestsResources: framework.NewResource(nil), - preemptible: map[string]corev1.ResourceList{}, - preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, - nodeReservationStates: map[string]nodeReservationState{ - node.Name: { - nodeName: node.Name, - matched: []*frameworkext.ReservationInfo{matchRInfo}, - podRequested: &framework.Resource{ - MilliCPU: 32000, - Memory: 68719476736, - }, - rAllocated: framework.NewResource(nil), - }, - }, - nodeReservationDiagnosis: map[string]*nodeDiagnosisState{ - node.Name: { - nodeName: node.Name, - ownerMatched: 1, - affinityUnmatched: 0, - isUnschedulableUnmatched: 0, + schedulingStateData: schedulingStateData{ + podRequests: corev1.ResourceList{}, + podRequestsResources: framework.NewResource(nil), + preemptible: map[string]corev1.ResourceList{}, + preemptibleInRRs: map[string]map[types.UID]corev1.ResourceList{}, + nodeReservationStates: map[string]nodeReservationState{ + node.Name: { + nodeName: node.Name, + matched: []*frameworkext.ReservationInfo{matchRInfo}, + podRequested: &framework.Resource{ + MilliCPU: 32000, + Memory: 68719476736, + }, + rAllocated: framework.NewResource(nil), + }, + }, + nodeReservationDiagnosis: map[string]*nodeDiagnosisState{ + node.Name: { + nodeName: node.Name, + ownerMatched: 1, + affinityUnmatched: 0, + isUnschedulableUnmatched: 0, + }, }, }, }