Skip to content

Commit a151682

Browse files
committed
Split scheduler's PodInfo into two types, PodInfo and PodQueueInfo
1 parent 4820b6c commit a151682

File tree

13 files changed

+167
-160
lines changed

13 files changed

+167
-160
lines changed

pkg/scheduler/factory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ func NewPodInformer(client clientset.Interface, resyncPeriod time.Duration) core
456456
}
457457

458458
// MakeDefaultErrorFunc construct a function to handle pod scheduler error
459-
func MakeDefaultErrorFunc(client clientset.Interface, podQueue internalqueue.SchedulingQueue, schedulerCache internalcache.Cache) func(*framework.PodInfo, error) {
460-
return func(podInfo *framework.PodInfo, err error) {
459+
func MakeDefaultErrorFunc(client clientset.Interface, podQueue internalqueue.SchedulingQueue, schedulerCache internalcache.Cache) func(*framework.QueuedPodInfo, error) {
460+
return func(podInfo *framework.QueuedPodInfo, err error) {
461461
pod := podInfo.Pod
462462
if err == core.ErrNoNodesAvailable {
463463
klog.V(2).Infof("Unable to schedule %v/%v: no nodes are registered to the cluster; waiting", pod.Namespace, pod.Name)

pkg/scheduler/factory_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func TestDefaultErrorFunc(t *testing.T) {
328328
&v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "bar"}},
329329
&v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
330330

331-
testPodInfo := &framework.PodInfo{Pod: testPod}
331+
testPodInfo := &framework.QueuedPodInfo{Pod: testPod}
332332
client := fake.NewSimpleClientset(&v1.PodList{Items: []v1.Pod{*testPod}}, &v1.NodeList{Items: []v1.Node{*nodeBar}})
333333
stopCh := make(chan struct{})
334334
defer close(stopCh)

pkg/scheduler/framework/plugins/queuesort/priority_sort.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func (pl *PrioritySort) Name() string {
3737

3838
// Less is the function used by the activeQ heap algorithm to sort pods.
3939
// It sorts pods based on their priority. When priorities are equal, it uses
40-
// PodInfo.timestamp.
41-
func (pl *PrioritySort) Less(pInfo1, pInfo2 *framework.PodInfo) bool {
40+
// PodQueueInfo.timestamp.
41+
func (pl *PrioritySort) Less(pInfo1, pInfo2 *framework.QueuedPodInfo) bool {
4242
p1 := pod.GetPodPriority(pInfo1.Pod)
4343
p2 := pod.GetPodPriority(pInfo2.Pod)
4444
return (p1 > p2) || (p1 == p2 && pInfo1.Timestamp.Before(pInfo2.Timestamp))

pkg/scheduler/framework/plugins/queuesort/priority_sort_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ func TestLess(t *testing.T) {
3131
t2 := t1.Add(time.Second)
3232
for _, tt := range []struct {
3333
name string
34-
p1 *framework.PodInfo
35-
p2 *framework.PodInfo
34+
p1 *framework.QueuedPodInfo
35+
p2 *framework.QueuedPodInfo
3636
expected bool
3737
}{
3838
{
3939
name: "p1.priority less than p2.priority",
40-
p1: &framework.PodInfo{
40+
p1: &framework.QueuedPodInfo{
4141
Pod: &v1.Pod{
4242
Spec: v1.PodSpec{
4343
Priority: &lowPriority,
4444
},
4545
},
4646
},
47-
p2: &framework.PodInfo{
47+
p2: &framework.QueuedPodInfo{
4848
Pod: &v1.Pod{
4949
Spec: v1.PodSpec{
5050
Priority: &highPriority,
@@ -55,14 +55,14 @@ func TestLess(t *testing.T) {
5555
},
5656
{
5757
name: "p1.priority greater than p2.priority",
58-
p1: &framework.PodInfo{
58+
p1: &framework.QueuedPodInfo{
5959
Pod: &v1.Pod{
6060
Spec: v1.PodSpec{
6161
Priority: &highPriority,
6262
},
6363
},
6464
},
65-
p2: &framework.PodInfo{
65+
p2: &framework.QueuedPodInfo{
6666
Pod: &v1.Pod{
6767
Spec: v1.PodSpec{
6868
Priority: &lowPriority,
@@ -73,15 +73,15 @@ func TestLess(t *testing.T) {
7373
},
7474
{
7575
name: "equal priority. p1 is added to schedulingQ earlier than p2",
76-
p1: &framework.PodInfo{
76+
p1: &framework.QueuedPodInfo{
7777
Pod: &v1.Pod{
7878
Spec: v1.PodSpec{
7979
Priority: &highPriority,
8080
},
8181
},
8282
Timestamp: t1,
8383
},
84-
p2: &framework.PodInfo{
84+
p2: &framework.QueuedPodInfo{
8585
Pod: &v1.Pod{
8686
Spec: v1.PodSpec{
8787
Priority: &highPriority,
@@ -93,15 +93,15 @@ func TestLess(t *testing.T) {
9393
},
9494
{
9595
name: "equal priority. p2 is added to schedulingQ earlier than p1",
96-
p1: &framework.PodInfo{
96+
p1: &framework.QueuedPodInfo{
9797
Pod: &v1.Pod{
9898
Spec: v1.PodSpec{
9999
Priority: &highPriority,
100100
},
101101
},
102102
Timestamp: t2,
103103
},
104-
p2: &framework.PodInfo{
104+
p2: &framework.QueuedPodInfo{
105105
Pod: &v1.Pod{
106106
Spec: v1.PodSpec{
107107
Priority: &highPriority,

pkg/scheduler/framework/v1alpha1/framework.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (f *framework) QueueSortFunc() LessFunc {
295295
if f == nil {
296296
// If framework is nil, simply keep their order unchanged.
297297
// NOTE: this is primarily for tests.
298-
return func(_, _ *PodInfo) bool { return false }
298+
return func(_, _ *QueuedPodInfo) bool { return false }
299299
}
300300

301301
if len(f.queueSortPlugins) == 0 {

pkg/scheduler/framework/v1alpha1/framework_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func (pl *TestQueueSortPlugin) Name() string {
288288
return queueSortPlugin
289289
}
290290

291-
func (pl *TestQueueSortPlugin) Less(_, _ *PodInfo) bool {
291+
func (pl *TestQueueSortPlugin) Less(_, _ *QueuedPodInfo) bool {
292292
return false
293293
}
294294

pkg/scheduler/framework/v1alpha1/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,15 @@ type Plugin interface {
211211
}
212212

213213
// LessFunc is the function to sort pod info
214-
type LessFunc func(podInfo1, podInfo2 *PodInfo) bool
214+
type LessFunc func(podInfo1, podInfo2 *QueuedPodInfo) bool
215215

216216
// QueueSortPlugin is an interface that must be implemented by "QueueSort" plugins.
217217
// These plugins are used to sort pods in the scheduling queue. Only one queue sort
218218
// plugin may be enabled at a time.
219219
type QueueSortPlugin interface {
220220
Plugin
221221
// Less are used to sort pods in the scheduling queue.
222-
Less(*PodInfo, *PodInfo) bool
222+
Less(*QueuedPodInfo, *QueuedPodInfo) bool
223223
}
224224

225225
// PreFilterExtensions is an interface that is included in plugins that allow specifying

pkg/scheduler/framework/v1alpha1/types.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ import (
3434

3535
var generation int64
3636

37-
// PodInfo is a wrapper to a Pod with additional information for purposes such as tracking
38-
// the timestamp when it's added to the queue or recording per-pod metrics.
39-
type PodInfo struct {
37+
// QueuedPodInfo is a Pod wrapper with additional information related to
38+
// the pod's status in the scheduling queue, such as the timestamp when
39+
// it's added to the queue.
40+
type QueuedPodInfo struct {
4041
Pod *v1.Pod
4142
// The time pod added to the scheduling queue.
4243
Timestamp time.Time
@@ -50,16 +51,23 @@ type PodInfo struct {
5051
InitialAttemptTimestamp time.Time
5152
}
5253

53-
// DeepCopy returns a deep copy of the PodInfo object.
54-
func (podInfo *PodInfo) DeepCopy() *PodInfo {
55-
return &PodInfo{
56-
Pod: podInfo.Pod.DeepCopy(),
57-
Timestamp: podInfo.Timestamp,
58-
Attempts: podInfo.Attempts,
59-
InitialAttemptTimestamp: podInfo.InitialAttemptTimestamp,
54+
// DeepCopy returns a deep copy of the QueuedPodInfo object.
55+
func (pqi *QueuedPodInfo) DeepCopy() *QueuedPodInfo {
56+
return &QueuedPodInfo{
57+
Pod: pqi.Pod.DeepCopy(),
58+
Timestamp: pqi.Timestamp,
59+
Attempts: pqi.Attempts,
60+
InitialAttemptTimestamp: pqi.InitialAttemptTimestamp,
6061
}
6162
}
6263

64+
// PodInfo is a wrapper to a Pod with additional pre-computed information to
65+
// accelerate processing. This information is typically immutable (e.g., pre-processed
66+
// inter-pod affinity selectors).
67+
type PodInfo struct {
68+
Pod *v1.Pod
69+
}
70+
6371
// NewPodInfo return a new PodInfo
6472
func NewPodInfo(pod *v1.Pod) *PodInfo {
6573
return &PodInfo{
@@ -359,7 +367,6 @@ func (n *NodeInfo) String() string {
359367

360368
// AddPod adds pod information to this NodeInfo.
361369
func (n *NodeInfo) AddPod(pod *v1.Pod) {
362-
// TODO(#89528): AddPod should accept a PodInfo as an input argument.
363370
podInfo := NewPodInfo(pod)
364371
res, non0CPU, non0Mem := calculateResource(pod)
365372
n.Requested.MilliCPU += res.MilliCPU

0 commit comments

Comments
 (0)