Skip to content

Commit

Permalink
Scheduler doesn't reschedule vpods that are scheduled on unscehdulabl…
Browse files Browse the repository at this point in the history
…e pods (#6726)

To detect whether scheduling is already done, it uses the
existing placements fields, however, if one or more placements
are for unschedulable pods, it won't reschedule them.

See added unit tests for example scenarios.

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
  • Loading branch information
pierDipi authored Feb 7, 2023
1 parent 40517be commit 1092472
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
9 changes: 9 additions & 0 deletions pkg/scheduler/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ func (s *State) GetPodInfo(podName string) (zoneName string, nodeName string, er
return zoneName, nodeName, nil
}

func (s *State) IsSchedulablePod(ordinal int32) bool {
for _, x := range s.SchedulablePods {
if x == ordinal {
return true
}
}
return false
}

// stateBuilder reconstruct the state from scratch, by listing vpods
type stateBuilder struct {
ctx context.Context
Expand Down
14 changes: 12 additions & 2 deletions pkg/scheduler/statefulset/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,20 @@ func (s *StatefulSetScheduler) scheduleVPod(vpod scheduler.VPod) ([]duckv1alpha1
return nil, err
}

placements := vpod.GetPlacements()
existingPlacements := placements
existingPlacements := vpod.GetPlacements()
var left int32

// Remove unschedulable pods from placements
var placements []duckv1alpha1.Placement
if len(existingPlacements) > 0 {
placements = make([]duckv1alpha1.Placement, 0, len(existingPlacements))
for _, p := range existingPlacements {
if state.IsSchedulablePod(st.OrdinalFromPodName(p.PodName)) {
placements = append(placements, *p.DeepCopy())
}
}
}

// The scheduler when policy type is
// Policy: MAXFILLUP (SchedulerPolicyType == MAXFILLUP)
// - allocates as many vreplicas as possible to the same pod(s)
Expand Down
26 changes: 26 additions & 0 deletions pkg/scheduler/statefulset/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@ func TestStatefulsetScheduler(t *testing.T) {
expected: []duckv1alpha1.Placement{{PodName: "statefulset-name-0", VReplicas: 3}},
schedulerPolicyType: scheduler.MAXFILLUP,
},
{
name: "one replica, 8 vreplicas, already scheduled on unschedulable pod, add replicas",
vreplicas: 8,
replicas: int32(1),
placements: []duckv1alpha1.Placement{
{PodName: "statefulset-name-0", VReplicas: 3},
{PodName: "statefulset-name-2", VReplicas: 5},
},
expected: []duckv1alpha1.Placement{
{PodName: "statefulset-name-0", VReplicas: 8},
},
schedulerPolicyType: scheduler.MAXFILLUP,
},
{
name: "one replica, 1 vreplicas, already scheduled on unschedulable pod, remove replicas",
vreplicas: 1,
replicas: int32(1),
placements: []duckv1alpha1.Placement{
{PodName: "statefulset-name-0", VReplicas: 3},
{PodName: "statefulset-name-2", VReplicas: 5},
},
expected: []duckv1alpha1.Placement{
{PodName: "statefulset-name-0", VReplicas: 1},
},
schedulerPolicyType: scheduler.MAXFILLUP,
},
{
name: "one replica, 15 vreplicas, unschedulable",
vreplicas: 15,
Expand Down

0 comments on commit 1092472

Please sign in to comment.