-
Notifications
You must be signed in to change notification settings - Fork 136
/
context.go
548 lines (514 loc) · 21.3 KB
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
package context
import (
"fmt"
"strings"
"text/tabwriter"
"time"
"github.com/pkg/errors"
"golang.org/x/exp/maps"
v1 "k8s.io/api/core/v1"
"github.com/armadaproject/armada/internal/armada/configuration"
"github.com/armadaproject/armada/internal/common/armadaerrors"
armadamaps "github.com/armadaproject/armada/internal/common/maps"
armadaslices "github.com/armadaproject/armada/internal/common/slices"
schedulerconfig "github.com/armadaproject/armada/internal/scheduler/configuration"
"github.com/armadaproject/armada/internal/scheduler/interfaces"
"github.com/armadaproject/armada/internal/scheduler/schedulerobjects"
)
// SchedulingContext contains information necessary for scheduling and records what happened in a scheduling round.
type SchedulingContext struct {
// Time at which the scheduling cycle started.
Started time.Time
// Time at which the scheduling cycle finished.
Finished time.Time
// Executor for which we're currently scheduling jobs.
ExecutorId string
// Resource pool of this executor.
Pool string
// Allowed priority classes.
PriorityClasses map[string]configuration.PriorityClass
// Default priority class.
DefaultPriorityClass string
// Weights used when computing total resource usage.
ResourceScarcity map[string]float64
// Per-queue scheduling contexts.
QueueSchedulingContexts map[string]*QueueSchedulingContext
// Total resources across all clusters available at the start of the scheduling cycle.
TotalResources schedulerobjects.ResourceList
// Resources assigned across all queues during this scheduling cycle.
ScheduledResources schedulerobjects.ResourceList
ScheduledResourcesByPriority schedulerobjects.QuantityByPriorityAndResourceType
// Resources evicted across all queues during this scheduling cycle.
EvictedResourcesByPriority schedulerobjects.QuantityByPriorityAndResourceType
// Total number of successfully scheduled jobs.
NumScheduledJobs int
// Total number of successfully scheduled gangs.
NumScheduledGangs int
// Reason for why the scheduling round finished.
TerminationReason string
// Record of job scheduling requirements known to be unfeasible.
// Used to immediately reject new jobs with identical reqirements.
// Maps to the JobSchedulingContext of a previous job attempted to schedule with the same key.
UnfeasibleSchedulingKeys map[schedulerobjects.SchedulingKey]*JobSchedulingContext
}
func NewSchedulingContext(
executorId string,
pool string,
priorityClasses map[string]configuration.PriorityClass,
defaultPriorityClass string,
resourceScarcity map[string]float64,
totalResources schedulerobjects.ResourceList,
) *SchedulingContext {
return &SchedulingContext{
Started: time.Now(),
ExecutorId: executorId,
Pool: pool,
PriorityClasses: priorityClasses,
DefaultPriorityClass: defaultPriorityClass,
ResourceScarcity: resourceScarcity,
QueueSchedulingContexts: make(map[string]*QueueSchedulingContext),
TotalResources: totalResources.DeepCopy(),
ScheduledResources: schedulerobjects.NewResourceListWithDefaultSize(),
ScheduledResourcesByPriority: make(schedulerobjects.QuantityByPriorityAndResourceType),
EvictedResourcesByPriority: make(schedulerobjects.QuantityByPriorityAndResourceType),
UnfeasibleSchedulingKeys: make(map[schedulerobjects.SchedulingKey]*JobSchedulingContext),
}
}
func (sctx *SchedulingContext) ClearUnfeasibleSchedulingKeys() {
sctx.UnfeasibleSchedulingKeys = make(map[schedulerobjects.SchedulingKey]*JobSchedulingContext)
}
func (sctx *SchedulingContext) AddQueueSchedulingContext(queue string, priorityFactor float64, initialAllocatedByPriority schedulerobjects.QuantityByPriorityAndResourceType) error {
if _, ok := sctx.QueueSchedulingContexts[queue]; ok {
return errors.WithStack(&armadaerrors.ErrInvalidArgument{
Name: "queue",
Value: queue,
Message: fmt.Sprintf("there already exists a context for queue %s", queue),
})
}
if initialAllocatedByPriority == nil {
initialAllocatedByPriority = make(schedulerobjects.QuantityByPriorityAndResourceType)
} else {
initialAllocatedByPriority = initialAllocatedByPriority.DeepCopy()
}
qctx := &QueueSchedulingContext{
SchedulingContext: sctx,
Created: time.Now(),
ExecutorId: sctx.ExecutorId,
Queue: queue,
PriorityFactor: priorityFactor,
Allocated: initialAllocatedByPriority.AggregateByResource(),
AllocatedByPriority: initialAllocatedByPriority,
ScheduledResourcesByPriority: make(schedulerobjects.QuantityByPriorityAndResourceType),
EvictedResourcesByPriority: make(schedulerobjects.QuantityByPriorityAndResourceType),
SuccessfulJobSchedulingContexts: make(map[string]*JobSchedulingContext),
UnsuccessfulJobSchedulingContexts: make(map[string]*JobSchedulingContext),
EvictedJobsById: make(map[string]bool),
}
sctx.QueueSchedulingContexts[queue] = qctx
return nil
}
func (sctx *SchedulingContext) String() string {
var sb strings.Builder
w := tabwriter.NewWriter(&sb, 1, 1, 1, ' ', 0)
fmt.Fprintf(w, "Started:\t%s\n", sctx.Started)
fmt.Fprintf(w, "Finished:\t%s\n", sctx.Finished)
fmt.Fprintf(w, "Duration:\t%s\n", sctx.Finished.Sub(sctx.Started))
fmt.Fprintf(w, "Total capacity:\t%s\n", sctx.TotalResources.CompactString())
fmt.Fprintf(w, "Jobs scheduled:\t%d\n", sctx.NumScheduledJobs)
fmt.Fprintf(w, "Total scheduled resources:\t%s\n", sctx.ScheduledResources.CompactString())
fmt.Fprintf(
w, "Scheduled queues:\t%v\n",
maps.Keys(
armadamaps.Filter(
sctx.QueueSchedulingContexts,
func(_ string, qctx *QueueSchedulingContext) bool {
return len(qctx.SuccessfulJobSchedulingContexts) > 0
},
),
),
)
fmt.Fprintf(w, "Termination reason:\t%s\n", sctx.TerminationReason)
w.Flush()
return sb.String()
}
func (sctx *SchedulingContext) AddGangSchedulingContext(gctx *GangSchedulingContext) (bool, error) {
allJobsEvictedInThisRound := true
allJobsSuccessful := true
for _, jctx := range gctx.JobSchedulingContexts {
evictedInThisRound, err := sctx.AddJobSchedulingContext(jctx)
if err != nil {
return false, err
}
allJobsEvictedInThisRound = allJobsEvictedInThisRound && evictedInThisRound
allJobsSuccessful = allJobsSuccessful && jctx.IsSuccessful()
}
if !allJobsEvictedInThisRound && allJobsSuccessful {
sctx.NumScheduledGangs++
}
return allJobsEvictedInThisRound, nil
}
// AddJobSchedulingContext adds a job scheduling context.
// Automatically updates scheduled resources.
func (sctx *SchedulingContext) AddJobSchedulingContext(jctx *JobSchedulingContext) (bool, error) {
qctx, ok := sctx.QueueSchedulingContexts[jctx.Job.GetQueue()]
if !ok {
return false, errors.Errorf("failed adding job %s to scheduling context: no context for queue %s", jctx.JobId, jctx.Job.GetQueue())
}
evictedInThisRound, err := qctx.AddJobSchedulingContext(jctx)
if err != nil {
return false, err
}
if jctx.IsSuccessful() {
if evictedInThisRound {
sctx.EvictedResourcesByPriority.SubV1ResourceList(jctx.Req.Priority, jctx.Req.ResourceRequirements.Requests)
} else {
sctx.ScheduledResources.AddV1ResourceList(jctx.Req.ResourceRequirements.Requests)
sctx.ScheduledResourcesByPriority.AddV1ResourceList(jctx.Req.Priority, jctx.Req.ResourceRequirements.Requests)
sctx.NumScheduledJobs++
}
}
return evictedInThisRound, nil
}
func (sctx *SchedulingContext) EvictGang(jobs []interfaces.LegacySchedulerJob) (bool, error) {
allJobsScheduledInThisRound := true
for _, job := range jobs {
scheduledInThisRound, err := sctx.EvictJob(job)
if err != nil {
return false, err
}
allJobsScheduledInThisRound = allJobsScheduledInThisRound && scheduledInThisRound
}
if allJobsScheduledInThisRound {
sctx.NumScheduledGangs--
}
return allJobsScheduledInThisRound, nil
}
func (sctx *SchedulingContext) EvictJob(job interfaces.LegacySchedulerJob) (bool, error) {
qctx, ok := sctx.QueueSchedulingContexts[job.GetQueue()]
if !ok {
return false, errors.Errorf("failed evicting job %s from scheduling context: no context for queue %s", job.GetId(), job.GetQueue())
}
scheduledInThisRound, err := qctx.EvictJob(job)
if err != nil {
return false, err
}
priority, rl := priorityAndRequestsFromLegacySchedulerJob(job, sctx.PriorityClasses)
if scheduledInThisRound {
sctx.ScheduledResources.SubV1ResourceList(rl)
sctx.ScheduledResourcesByPriority.SubV1ResourceList(priority, rl)
sctx.NumScheduledJobs--
} else {
sctx.EvictedResourcesByPriority.AddV1ResourceList(priority, rl)
}
return scheduledInThisRound, nil
}
// ClearJobSpecs zeroes out job specs to reduce memory usage.
func (sctx *SchedulingContext) ClearJobSpecs() {
for _, qctx := range sctx.QueueSchedulingContexts {
qctx.ClearJobSpecs()
}
}
func (sctx *SchedulingContext) SuccessfulJobSchedulingContexts() []*JobSchedulingContext {
jctxs := make([]*JobSchedulingContext, 0)
for _, qctx := range sctx.QueueSchedulingContexts {
for _, jctx := range qctx.SuccessfulJobSchedulingContexts {
jctxs = append(jctxs, jctx)
}
}
return jctxs
}
// AllocatedByQueueAndPriority returns map from queue name and priority to resources allocated.
func (sctx *SchedulingContext) AllocatedByQueueAndPriority() map[string]schedulerobjects.QuantityByPriorityAndResourceType {
rv := make(
map[string]schedulerobjects.QuantityByPriorityAndResourceType,
len(sctx.QueueSchedulingContexts),
)
for queue, qctx := range sctx.QueueSchedulingContexts {
if len(qctx.AllocatedByPriority) > 0 {
rv[queue] = qctx.AllocatedByPriority.DeepCopy()
}
}
return rv
}
// QueueSchedulingContext captures the decisions made by the scheduler during one invocation
// for a particular queue.
type QueueSchedulingContext struct {
// The scheduling context to which this QueueSchedulingContext belongs.
SchedulingContext *SchedulingContext
// Time at which this context was created.
Created time.Time
// Executor this job was attempted to be assigned to.
ExecutorId string
// Queue name.
Queue string
// These factors influence the fraction of resources assigned to each queue.
PriorityFactor float64
// Total resources assigned to the queue across all clusters by priority class priority.
// Includes jobs scheduled during this invocation of the scheduler.
Allocated schedulerobjects.ResourceList
// Total resources assigned to the queue across all clusters by priority class priority.
// Includes jobs scheduled during this invocation of the scheduler.
AllocatedByPriority schedulerobjects.QuantityByPriorityAndResourceType
// Resources assigned to this queue during this scheduling cycle.
ScheduledResourcesByPriority schedulerobjects.QuantityByPriorityAndResourceType
// Resources evicted from this queue during this scheduling cycle.
EvictedResourcesByPriority schedulerobjects.QuantityByPriorityAndResourceType
// Job scheduling contexts associated with successful scheduling attempts.
SuccessfulJobSchedulingContexts map[string]*JobSchedulingContext
// Job scheduling contexts associated with unsuccessful scheduling attempts.
UnsuccessfulJobSchedulingContexts map[string]*JobSchedulingContext
// Jobs evicted in this round.
EvictedJobsById map[string]bool
}
const maxPrintedJobIdsByReason = 1
// TODO: Update with preemptions.
func (qctx *QueueSchedulingContext) String() string {
var sb strings.Builder
w := tabwriter.NewWriter(&sb, 1, 1, 1, ' ', 0)
fmt.Fprintf(w, "Time:\t%s\n", qctx.Created)
fmt.Fprintf(w, "Queue:\t%s\n", qctx.Queue)
fmt.Fprintf(w, "Total allocated resources after scheduling:\t%s\n", qctx.AllocatedByPriority.AggregateByResource().CompactString())
fmt.Fprintf(w, "Total allocated resources after scheduling (by priority):\t%s\n", qctx.AllocatedByPriority.String())
fmt.Fprintf(w, "Scheduled resources:\t%s\n", qctx.ScheduledResourcesByPriority.AggregateByResource().CompactString())
fmt.Fprintf(w, "Scheduled resources (by priority):\t%s\n", qctx.ScheduledResourcesByPriority.String())
fmt.Fprintf(w, "Number of jobs scheduled:\t%d\n", len(qctx.SuccessfulJobSchedulingContexts))
fmt.Fprintf(w, "Number of jobs that could not be scheduled:\t%d\n", len(qctx.UnsuccessfulJobSchedulingContexts))
if len(qctx.SuccessfulJobSchedulingContexts) > 0 {
jobIdsToPrint := maps.Keys(qctx.SuccessfulJobSchedulingContexts)
if len(jobIdsToPrint) > maxPrintedJobIdsByReason {
jobIdsToPrint = jobIdsToPrint[0:maxPrintedJobIdsByReason]
}
fmt.Fprintf(w, "Scheduled jobs:\t%v", jobIdsToPrint)
if len(jobIdsToPrint) != len(qctx.SuccessfulJobSchedulingContexts) {
fmt.Fprintf(w, " (and %d others not shown)\n", len(qctx.SuccessfulJobSchedulingContexts)-len(jobIdsToPrint))
} else {
fmt.Fprint(w, "\n")
}
}
if len(qctx.UnsuccessfulJobSchedulingContexts) > 0 {
fmt.Fprint(w, "Unschedulable jobs:\n")
for reason, jobIds := range armadaslices.MapAndGroupByFuncs(
maps.Values(qctx.UnsuccessfulJobSchedulingContexts),
func(jctx *JobSchedulingContext) string {
return jctx.UnschedulableReason
},
func(jctx *JobSchedulingContext) string {
return jctx.JobId
},
) {
jobIdsToPrint := jobIds
if len(jobIdsToPrint) > maxPrintedJobIdsByReason {
jobIdsToPrint = jobIds[0:maxPrintedJobIdsByReason]
}
fmt.Fprintf(w, "\t%d:\t%s jobs\t%v", len(qctx.UnsuccessfulJobSchedulingContexts), reason, jobIdsToPrint)
if len(jobIdsToPrint) != len(jobIds) {
fmt.Fprintf(w, " (and %d others not shown)\n", len(jobIds)-len(jobIdsToPrint))
} else {
fmt.Fprint(w, "\n")
}
}
}
w.Flush()
return sb.String()
}
func (qctx *QueueSchedulingContext) AddGangSchedulingContext(gctx *GangSchedulingContext) error {
for _, jctx := range gctx.JobSchedulingContexts {
if _, err := qctx.AddJobSchedulingContext(jctx); err != nil {
return err
}
}
return nil
}
// AddJobSchedulingContext adds a job scheduling context.
// Automatically updates scheduled resources.
func (qctx *QueueSchedulingContext) AddJobSchedulingContext(jctx *JobSchedulingContext) (bool, error) {
if _, ok := qctx.SuccessfulJobSchedulingContexts[jctx.JobId]; ok {
return false, errors.Errorf("failed adding job %s to queue: job already marked successful", jctx.JobId)
}
if _, ok := qctx.UnsuccessfulJobSchedulingContexts[jctx.JobId]; ok {
return false, errors.Errorf("failed adding job %s to queue: job already marked unsuccessful", jctx.JobId)
}
_, evictedInThisRound := qctx.EvictedJobsById[jctx.JobId]
if jctx.IsSuccessful() {
if jctx.Req == nil {
return false, errors.Errorf("failed adding job %s to queue: job requirements are missing", jctx.JobId)
}
// Always update ResourcesByPriority.
// Since ResourcesByPriority is used to order queues by fraction of fair share.
qctx.Allocated.AddV1ResourceList(jctx.Req.ResourceRequirements.Requests)
qctx.AllocatedByPriority.AddV1ResourceList(jctx.Req.Priority, jctx.Req.ResourceRequirements.Requests)
// Only if the job is not evicted, update ScheduledResourcesByPriority.
// Since ScheduledResourcesByPriority is used to control per-round scheduling constraints.
if evictedInThisRound {
delete(qctx.EvictedJobsById, jctx.JobId)
qctx.EvictedResourcesByPriority.SubV1ResourceList(jctx.Req.Priority, jctx.Req.ResourceRequirements.Requests)
} else {
qctx.SuccessfulJobSchedulingContexts[jctx.JobId] = jctx
qctx.ScheduledResourcesByPriority.AddV1ResourceList(jctx.Req.Priority, jctx.Req.ResourceRequirements.Requests)
}
} else {
qctx.UnsuccessfulJobSchedulingContexts[jctx.JobId] = jctx
}
return evictedInThisRound, nil
}
func (qctx *QueueSchedulingContext) EvictJob(job interfaces.LegacySchedulerJob) (bool, error) {
jobId := job.GetId()
priority, rl := priorityAndRequestsFromLegacySchedulerJob(job, qctx.SchedulingContext.PriorityClasses)
if _, ok := qctx.UnsuccessfulJobSchedulingContexts[jobId]; ok {
return false, errors.Errorf("failed evicting job %s from queue: job already marked unsuccessful", jobId)
}
if _, ok := qctx.EvictedJobsById[jobId]; ok {
return false, errors.Errorf("failed evicting job %s from queue: job already marked evicted", jobId)
}
_, scheduledInThisRound := qctx.SuccessfulJobSchedulingContexts[jobId]
if scheduledInThisRound {
qctx.ScheduledResourcesByPriority.SubV1ResourceList(priority, rl)
delete(qctx.SuccessfulJobSchedulingContexts, jobId)
} else {
qctx.EvictedResourcesByPriority.AddV1ResourceList(priority, rl)
qctx.EvictedJobsById[jobId] = true
}
qctx.Allocated.SubV1ResourceList(rl)
qctx.AllocatedByPriority.SubV1ResourceList(priority, rl)
return scheduledInThisRound, nil
}
func priorityAndRequestsFromLegacySchedulerJob(job interfaces.LegacySchedulerJob, priorityClasses map[string]configuration.PriorityClass) (int32, v1.ResourceList) {
req := job.GetRequirements(priorityClasses)
for _, r := range req.ObjectRequirements {
podReqs := r.GetPodRequirements()
if podReqs == nil {
continue
}
return podReqs.Priority, podReqs.ResourceRequirements.Requests
}
return 0, nil
}
// ClearJobSpecs zeroes out job specs to reduce memory usage.
func (qctx *QueueSchedulingContext) ClearJobSpecs() {
for _, jctx := range qctx.SuccessfulJobSchedulingContexts {
jctx.Job = nil
}
for _, jctx := range qctx.UnsuccessfulJobSchedulingContexts {
jctx.Job = nil
}
}
type GangSchedulingContext struct {
Created time.Time
Queue string
PriorityClassName string
JobSchedulingContexts []*JobSchedulingContext
TotalResourceRequests schedulerobjects.ResourceList
AllJobsEvicted bool
}
func NewGangSchedulingContext(jctxs []*JobSchedulingContext) *GangSchedulingContext {
// We assume that all jobs in a gang are in the same queue and have the same priority class
// (which we enforce at job submission).
queue := ""
priorityClassName := ""
if len(jctxs) > 0 {
queue = jctxs[0].Job.GetQueue()
priorityClassName = jctxs[0].Job.GetPriorityClassName()
}
allJobsEvicted := true
totalResourceRequests := schedulerobjects.NewResourceList(4)
for _, jctx := range jctxs {
allJobsEvicted = allJobsEvicted && isEvictedJob(jctx.Job)
totalResourceRequests.AddV1ResourceList(jctx.Req.ResourceRequirements.Requests)
}
return &GangSchedulingContext{
Created: time.Now(),
Queue: queue,
PriorityClassName: priorityClassName,
JobSchedulingContexts: jctxs,
TotalResourceRequests: totalResourceRequests,
AllJobsEvicted: allJobsEvicted,
}
}
func (gctx GangSchedulingContext) PodRequirements() []*schedulerobjects.PodRequirements {
rv := make([]*schedulerobjects.PodRequirements, len(gctx.JobSchedulingContexts))
for i, jctx := range gctx.JobSchedulingContexts {
rv[i] = jctx.Req
}
return rv
}
func isEvictedJob(job interfaces.LegacySchedulerJob) bool {
return job.GetAnnotations()[schedulerconfig.IsEvictedAnnotation] == "true"
}
// JobSchedulingContext is created by the scheduler and contains information
// about the decision made by the scheduler for a particular job.
type JobSchedulingContext struct {
// Time at which this context was created.
Created time.Time
// Executor this job was attempted to be assigned to.
ExecutorId string
// Total number of nodes in the cluster when trying to schedule.
NumNodes int
// Id of the job this pod corresponds to.
JobId string
// Job spec.
Job interfaces.LegacySchedulerJob
// Scheduling requirements of this job.
// We currently require that each job contains exactly one pod spec.
Req *schedulerobjects.PodRequirements
// Reason for why the job could not be scheduled.
// Empty if the job was scheduled successfully.
UnschedulableReason string
// Pod scheduling contexts for the individual pods that make up the job.
PodSchedulingContext *PodSchedulingContext
}
func (jctx *JobSchedulingContext) String() string {
var sb strings.Builder
w := tabwriter.NewWriter(&sb, 1, 1, 1, ' ', 0)
fmt.Fprintf(w, "Time:\t%s\n", jctx.Created)
fmt.Fprintf(w, "Job id:\t%s\n", jctx.JobId)
fmt.Fprintf(w, "Number of nodes in cluster:\t%d\n", jctx.NumNodes)
if jctx.UnschedulableReason != "" {
fmt.Fprintf(w, "UnschedulableReason:\t%s\n", jctx.UnschedulableReason)
} else {
fmt.Fprint(w, "UnschedulableReason:\tnone\n")
}
if jctx.PodSchedulingContext != nil {
fmt.Fprint(w, jctx.PodSchedulingContext.String())
}
w.Flush()
return sb.String()
}
func (jctx *JobSchedulingContext) IsSuccessful() bool {
return jctx.UnschedulableReason == ""
}
// PodSchedulingContext is returned by SelectAndBindNodeToPod and
// contains detailed information on the scheduling decision made for this pod.
type PodSchedulingContext struct {
// Time at which this context was created.
Created time.Time
// Node the pod was assigned to.
// If nil, the pod could not be assigned to any node.
Node *schedulerobjects.Node
// Score indicates how well the pod fits on the selected node.
Score int
// Node types on which this pod could be scheduled.
MatchingNodeTypes []*schedulerobjects.NodeType
// Total number of nodes in the cluster when trying to schedule.
NumNodes int
// Number of nodes excluded by reason.
NumExcludedNodesByReason map[string]int
}
func (pctx *PodSchedulingContext) String() string {
var sb strings.Builder
w := tabwriter.NewWriter(&sb, 1, 1, 1, ' ', 0)
if pctx.Node != nil {
fmt.Fprintf(w, "Node:\t%s\n", pctx.Node.Id)
} else {
fmt.Fprint(w, "Node:\tnone\n")
}
if len(pctx.NumExcludedNodesByReason) == 0 {
fmt.Fprint(w, "Excluded nodes:\tnone\n")
} else {
fmt.Fprint(w, "Excluded nodes:\n")
for reason, count := range pctx.NumExcludedNodesByReason {
fmt.Fprintf(w, "\t%d:\t%s\n", count, reason)
}
}
w.Flush()
return sb.String()
}