Skip to content

Commit 083abc0

Browse files
authored
Merge pull request kubernetes-retired#618 from k82cn/kb_261_1
Added JobPriority e2e.
2 parents 07034f2 + 86e781d commit 083abc0

File tree

8 files changed

+88
-34
lines changed

8 files changed

+88
-34
lines changed

pkg/scheduler/api/job_info.go

+1
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ func (ji *JobInfo) Clone() *JobInfo {
275275
Name: ji.Name,
276276
Namespace: ji.Namespace,
277277
Queue: ji.Queue,
278+
Priority: ji.Priority,
278279

279280
MinAvailable: ji.MinAvailable,
280281
NodeSelector: map[string]string{},

pkg/scheduler/cache/cache.go

+3
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ func (sc *SchedulerCache) Snapshot() *kbapi.ClusterInfo {
550550
if priorityClass, found := sc.PriorityClasses[priName]; found {
551551
value.Priority = priorityClass.Value
552552
}
553+
554+
glog.V(4).Infof("The priority of job <%s/%s> is <%s/%d>",
555+
value.Namespace, value.Name, priName, value.Priority)
553556
}
554557

555558
snapshot.Jobs[value.UID] = value.Clone()

pkg/scheduler/cache/event_handlers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ package cache
1818

1919
import (
2020
"fmt"
21-
"k8s.io/api/scheduling/v1beta1"
2221
"reflect"
2322

2423
"github.com/golang/glog"
2524

2625
"k8s.io/api/core/v1"
2726
policyv1 "k8s.io/api/policy/v1beta1"
27+
"k8s.io/api/scheduling/v1beta1"
2828
"k8s.io/apimachinery/pkg/api/errors"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/client-go/tools/cache"

test/e2e/job.go

+65-17
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var _ = Describe("Job E2E Test", func() {
2929
defer cleanupTestContext(context)
3030
rep := clusterSize(context, oneCPU)
3131

32-
_, pg := createJobEx(context, &jobSpec{
32+
_, pg := createJob(context, &jobSpec{
3333
name: "qj-1",
3434
tasks: []taskSpec{
3535
{
@@ -63,11 +63,11 @@ var _ = Describe("Job E2E Test", func() {
6363
}
6464

6565
job.name = "mqj-1"
66-
_, pg1 := createJobEx(context, job)
66+
_, pg1 := createJob(context, job)
6767
job.name = "mqj-2"
68-
_, pg2 := createJobEx(context, job)
68+
_, pg2 := createJob(context, job)
6969
job.name = "mqj-3"
70-
_, pg3 := createJobEx(context, job)
70+
_, pg3 := createJob(context, job)
7171

7272
err := waitPodGroupReady(context, pg1)
7373
checkError(context, err)
@@ -101,7 +101,7 @@ var _ = Describe("Job E2E Test", func() {
101101
},
102102
}
103103

104-
_, pg := createJobEx(context, job)
104+
_, pg := createJob(context, job)
105105
err = waitPodGroupPending(context, pg)
106106
checkError(context, err)
107107

@@ -133,12 +133,12 @@ var _ = Describe("Job E2E Test", func() {
133133
}
134134

135135
job.name = "gang-fq-qj1"
136-
_, pg1 := createJobEx(context, job)
136+
_, pg1 := createJob(context, job)
137137
err := waitPodGroupReady(context, pg1)
138138
checkError(context, err)
139139

140140
job.name = "gang-fq-qj2"
141-
_, pg2 := createJobEx(context, job)
141+
_, pg2 := createJob(context, job)
142142
err = waitPodGroupPending(context, pg2)
143143
checkError(context, err)
144144

@@ -165,12 +165,12 @@ var _ = Describe("Job E2E Test", func() {
165165
}
166166

167167
job.name = "preemptee-qj"
168-
_, pg1 := createJobEx(context, job)
168+
_, pg1 := createJob(context, job)
169169
err := waitTasksReady(context, pg1, int(rep))
170170
checkError(context, err)
171171

172172
job.name = "preemptor-qj"
173-
_, pg2 := createJobEx(context, job)
173+
_, pg2 := createJob(context, job)
174174
err = waitTasksReady(context, pg1, int(rep)/2)
175175
checkError(context, err)
176176

@@ -197,16 +197,16 @@ var _ = Describe("Job E2E Test", func() {
197197
}
198198

199199
job.name = "preemptee-qj"
200-
_, pg1 := createJobEx(context, job)
200+
_, pg1 := createJob(context, job)
201201
err := waitTasksReady(context, pg1, int(rep))
202202
checkError(context, err)
203203

204204
job.name = "preemptor-qj1"
205-
_, pg2 := createJobEx(context, job)
205+
_, pg2 := createJob(context, job)
206206
checkError(context, err)
207207

208208
job.name = "preemptor-qj2"
209-
_, pg3 := createJobEx(context, job)
209+
_, pg3 := createJob(context, job)
210210
checkError(context, err)
211211

212212
err = waitTasksReady(context, pg1, int(rep)/3)
@@ -243,7 +243,7 @@ var _ = Describe("Job E2E Test", func() {
243243
},
244244
}
245245

246-
_, pg := createJobEx(context, job)
246+
_, pg := createJob(context, job)
247247

248248
err := waitPodGroupReady(context, pg)
249249
checkError(context, err)
@@ -269,14 +269,14 @@ var _ = Describe("Job E2E Test", func() {
269269
}
270270

271271
job.name = "st-qj-1"
272-
_, pg1 := createJobEx(context, job)
272+
_, pg1 := createJob(context, job)
273273
err := waitPodGroupReady(context, pg1)
274274
checkError(context, err)
275275

276276
now := time.Now()
277277

278278
job.name = "st-qj-2"
279-
_, pg2 := createJobEx(context, job)
279+
_, pg2 := createJob(context, job)
280280
err = waitPodGroupUnschedulable(context, pg2)
281281
checkError(context, err)
282282

@@ -297,7 +297,7 @@ var _ = Describe("Job E2E Test", func() {
297297
err := waitReplicaSetReady(context, replicaset.Name)
298298
checkError(context, err)
299299

300-
_, pg := createJobEx(context, &jobSpec{
300+
_, pg := createJob(context, &jobSpec{
301301
name: "multi-pod-job",
302302
tasks: []taskSpec{
303303
{
@@ -338,7 +338,7 @@ var _ = Describe("Job E2E Test", func() {
338338
err := waitReplicaSetReady(context, replicaset.Name)
339339
checkError(context, err)
340340

341-
_, pg := createJobEx(context, &jobSpec{
341+
_, pg := createJob(context, &jobSpec{
342342
name: "multi-task-diff-resource-job",
343343
tasks: []taskSpec{
344344
{
@@ -366,4 +366,52 @@ var _ = Describe("Job E2E Test", func() {
366366
err = waitTasksReady(context, pg, int(minMemberOverride))
367367
checkError(context, err)
368368
})
369+
370+
It("Job Priority", func() {
371+
context := initTestContext()
372+
defer cleanupTestContext(context)
373+
374+
slot := oneCPU
375+
rep := clusterSize(context, slot)
376+
377+
replicaset := createReplicaSet(context, "rs-1", rep, "nginx", slot)
378+
err := waitReplicaSetReady(context, replicaset.Name)
379+
checkError(context, err)
380+
381+
job1 := &jobSpec{
382+
name: "pri-job-1",
383+
pri: workerPriority,
384+
tasks: []taskSpec{
385+
{
386+
img: "nginx",
387+
req: oneCPU,
388+
min: rep/2 + 1,
389+
rep: rep,
390+
},
391+
},
392+
}
393+
394+
job2 := &jobSpec{
395+
name: "pri-job-2",
396+
pri: masterPriority,
397+
tasks: []taskSpec{
398+
{
399+
img: "nginx",
400+
req: oneCPU,
401+
min: rep/2 + 1,
402+
rep: rep,
403+
},
404+
},
405+
}
406+
407+
createJob(context, job1)
408+
_, pg2 := createJob(context, job2)
409+
410+
// Delete ReplicaSet
411+
err = deleteReplicaSet(context, replicaset.Name)
412+
checkError(context, err)
413+
414+
err = waitPodGroupReady(context, pg2)
415+
checkError(context, err)
416+
})
369417
})

test/e2e/predicates.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var _ = Describe("Predicates E2E Test", func() {
6565
},
6666
}
6767

68-
_, pg := createJobEx(context, job)
68+
_, pg := createJob(context, job)
6969
err := waitPodGroupReady(context, pg)
7070
checkError(context, err)
7171

@@ -94,7 +94,7 @@ var _ = Describe("Predicates E2E Test", func() {
9494
},
9595
}
9696

97-
_, pg := createJobEx(context, job)
97+
_, pg := createJob(context, job)
9898

9999
err := waitTasksReady(context, pg, nn)
100100
checkError(context, err)
@@ -140,7 +140,7 @@ var _ = Describe("Predicates E2E Test", func() {
140140
},
141141
}
142142

143-
_, pg := createJobEx(context, job)
143+
_, pg := createJob(context, job)
144144
err := waitPodGroupReady(context, pg)
145145
checkError(context, err)
146146

@@ -179,7 +179,7 @@ var _ = Describe("Predicates E2E Test", func() {
179179
},
180180
}
181181

182-
_, pg := createJobEx(context, job)
182+
_, pg := createJob(context, job)
183183
err = waitPodGroupPending(context, pg)
184184
checkError(context, err)
185185

test/e2e/prioritize.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var _ = Describe("Prioritize E2E Test", func() {
6060
},
6161
}
6262

63-
_, pg := createJobEx(context, job)
63+
_, pg := createJob(context, job)
6464
err := waitPodGroupReady(context, pg)
6565
checkError(context, err)
6666

@@ -98,7 +98,7 @@ var _ = Describe("Prioritize E2E Test", func() {
9898
},
9999
}
100100

101-
_, pg1 := createJobEx(context, job1)
101+
_, pg1 := createJob(context, job1)
102102
err := waitPodGroupReady(context, pg1)
103103
checkError(context, err)
104104

@@ -124,7 +124,7 @@ var _ = Describe("Prioritize E2E Test", func() {
124124
},
125125
}
126126

127-
_, pg2 := createJobEx(context, job2)
127+
_, pg2 := createJob(context, job2)
128128
err = waitPodGroupReady(context, pg2)
129129
checkError(context, err)
130130

@@ -172,7 +172,7 @@ var _ = Describe("Prioritize E2E Test", func() {
172172
}
173173

174174
//Schedule Job in first Node
175-
_, pg1 := createJobEx(context, job1)
175+
_, pg1 := createJob(context, job1)
176176
err := waitPodGroupReady(context, pg1)
177177
checkError(context, err)
178178

@@ -208,7 +208,7 @@ var _ = Describe("Prioritize E2E Test", func() {
208208
}
209209

210210
//Schedule Job in Second Node
211-
_, pg2 := createJobEx(context, job2)
211+
_, pg2 := createJob(context, job2)
212212
err = waitPodGroupReady(context, pg2)
213213
checkError(context, err)
214214

@@ -225,7 +225,7 @@ var _ = Describe("Prioritize E2E Test", func() {
225225
}
226226

227227
//This job should be scheduled in third node
228-
_, pg3 := createJobEx(context, testJob)
228+
_, pg3 := createJob(context, testJob)
229229
err = waitPodGroupReady(context, pg3)
230230
checkError(context, err)
231231

test/e2e/queue.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var _ = Describe("Queue E2E Test", func() {
4646

4747
job.name = "q1-qj-1"
4848
job.queue = "q1"
49-
_, pg1 := createJobEx(context, job)
49+
_, pg1 := createJob(context, job)
5050
err := waitPodGroupReady(context, pg1)
5151
checkError(context, err)
5252

@@ -61,7 +61,7 @@ var _ = Describe("Queue E2E Test", func() {
6161

6262
job.name = "q2-qj-2"
6363
job.queue = "q2"
64-
_, pg2 := createJobEx(context, job)
64+
_, pg2 := createJob(context, job)
6565
err = waitTasksReady(context, pg2, expected)
6666
checkError(context, err)
6767

test/e2e/util.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ type jobSpec struct {
264264
name string
265265
namespace string
266266
queue string
267+
pri string
267268
tasks []taskSpec
268269
minMember *int32
269270
}
@@ -276,7 +277,7 @@ func getNS(context *context, job *jobSpec) string {
276277
return context.namespace
277278
}
278279

279-
func createJobEx(context *context, job *jobSpec) ([]*batchv1.Job, *kbv1.PodGroup) {
280+
func createJob(context *context, job *jobSpec) ([]*batchv1.Job, *kbv1.PodGroup) {
280281
var jobs []*batchv1.Job
281282
var podgroup *kbv1.PodGroup
282283
var min int32
@@ -324,16 +325,17 @@ func createJobEx(context *context, job *jobSpec) ([]*batchv1.Job, *kbv1.PodGroup
324325
Namespace: ns,
325326
},
326327
Spec: kbv1.PodGroupSpec{
327-
MinMember: min,
328-
Queue: job.queue,
328+
MinMember: min,
329+
Queue: job.queue,
330+
PriorityClassName: job.pri,
329331
},
330332
}
331333

332334
if job.minMember != nil {
333335
pg.Spec.MinMember = *job.minMember
334336
}
335337

336-
podgroup, err := context.kbclient.Scheduling().PodGroups(pg.Namespace).Create(pg)
338+
podgroup, err := context.kbclient.SchedulingV1alpha1().PodGroups(pg.Namespace).Create(pg)
337339
checkError(context, err)
338340

339341
return jobs, podgroup

0 commit comments

Comments
 (0)