Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit 12718da

Browse files
authored
Merge pull request #435 from k82cn/automated-cherry-pick-of-#419-#417-release-0.2
Automated cherry pick of #419: Imported golang golint. #417: fix BestEffort Job for overused
2 parents 41cb7da + 6528794 commit 12718da

File tree

4 files changed

+149
-1
lines changed

4 files changed

+149
-1
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ go:
1414
go_import_path: github.com/kubernetes-sigs/kube-batch
1515

1616
install:
17-
- go get -u github.com/golang/lint/golint
17+
- go get -u golang.org/x/lint/golint
1818

1919
before_script:
2020
- export TEST_LOG_LEVEL=4

pkg/scheduler/plugins/priority/priority.go

+32
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"github.com/golang/glog"
2121
"github.com/kubernetes-sigs/kube-batch/pkg/scheduler/api"
2222
"github.com/kubernetes-sigs/kube-batch/pkg/scheduler/framework"
23+
24+
"k8s.io/api/core/v1"
2325
)
2426

2527
type priorityPlugin struct {
@@ -37,6 +39,11 @@ func (pp *priorityPlugin) OnSessionOpen(ssn *framework.Session) {
3739
lv := l.(*api.TaskInfo)
3840
rv := r.(*api.TaskInfo)
3941

42+
// TODO quick fix, enhance it later by other option.
43+
if res := compareQoS(lv.Pod, rv.Pod); res != 0 {
44+
return res
45+
}
46+
4047
glog.V(3).Infof("Priority TaskOrder: <%v/%v> prority is %v, <%v/%v> priority is %v",
4148
lv.Namespace, lv.Name, lv.Priority, rv.Namespace, rv.Name, rv.Priority)
4249

@@ -81,3 +88,28 @@ func (pp *priorityPlugin) OnSessionOpen(ssn *framework.Session) {
8188
}
8289

8390
func (pp *priorityPlugin) OnSessionClose(ssn *framework.Session) {}
91+
92+
// make BestEffort > Burstable/Guarantee
93+
func compareQoS(l, r *v1.Pod) int {
94+
lq := l.Status.QOSClass
95+
rq := r.Status.QOSClass
96+
97+
glog.V(3).Infof("Priority TaskOrder: <%v/%v> QoS is %v, <%v/%v> QoS is %v",
98+
l.Namespace, l.Name, lq, r.Namespace, r.Name, rq)
99+
100+
if lq == rq {
101+
return 0
102+
}
103+
104+
// BestEffort > Burstable/Guarantee
105+
if lq == v1.PodQOSBestEffort {
106+
return -1
107+
}
108+
109+
// Burstable/Guarantee < BestEffort
110+
if rq == v1.PodQOSBestEffort {
111+
return 1
112+
}
113+
114+
return 0
115+
}

test/e2e.go

+15
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,19 @@ var _ = Describe("E2E Test", func() {
221221
err = waitTasksNotReady(context, job.Name, nn)
222222
Expect(err).NotTo(HaveOccurred())
223223
})
224+
225+
It("Schedule BestEffort Job", func() {
226+
context := initTestContext()
227+
defer cleanupTestContext(context)
228+
229+
pgName := "test"
230+
231+
createPodGroup(context, "burstable", pgName, 2)
232+
233+
bestEffort := createJobWithoutPodGroup(context, "besteffort", 1, "busybox", nil, pgName)
234+
burstable := createJobWithoutPodGroup(context, "burstable", 1, "busybox", oneCPU, pgName)
235+
236+
err := waitJobReadyWithPodGroup(context, pgName, bestEffort.Name, burstable.Name)
237+
Expect(err).NotTo(HaveOccurred())
238+
})
224239
})

test/util.go

+101
Original file line numberDiff line numberDiff line change
@@ -620,3 +620,104 @@ func getPodOfJob(ctx *context, jobName string) []*v1.Pod {
620620

621621
return qjpod
622622
}
623+
624+
func createPodGroup(
625+
context *context,
626+
jobName, name string,
627+
min int32,
628+
) {
629+
jns, _, _ := splictJobName(context, jobName)
630+
631+
pg := &arbv1.PodGroup{
632+
ObjectMeta: metav1.ObjectMeta{
633+
Name: name,
634+
Namespace: jns,
635+
},
636+
Spec: arbv1.PodGroupSpec{
637+
MinMember: min,
638+
},
639+
}
640+
641+
pg, err := context.karclient.Scheduling().PodGroups(jns).Create(pg)
642+
Expect(err).NotTo(HaveOccurred())
643+
}
644+
645+
func createJobWithoutPodGroup(
646+
context *context,
647+
name string,
648+
rep int32,
649+
img string,
650+
req v1.ResourceList,
651+
pg string,
652+
) *batchv1.Job {
653+
containers := createContainers(img, req, 0)
654+
jns, jn, _ := splictJobName(context, name)
655+
656+
job := &batchv1.Job{
657+
ObjectMeta: metav1.ObjectMeta{
658+
Name: jn,
659+
Namespace: jns,
660+
},
661+
Spec: batchv1.JobSpec{
662+
Parallelism: &rep,
663+
Completions: &rep,
664+
Template: v1.PodTemplateSpec{
665+
ObjectMeta: metav1.ObjectMeta{
666+
Annotations: map[string]string{arbv1.GroupNameAnnotationKey: pg},
667+
},
668+
Spec: v1.PodSpec{
669+
SchedulerName: "kube-batch",
670+
RestartPolicy: v1.RestartPolicyNever,
671+
Containers: containers,
672+
},
673+
},
674+
},
675+
}
676+
677+
job, err := context.kubeclient.BatchV1().Jobs(job.Namespace).Create(job)
678+
Expect(err).NotTo(HaveOccurred())
679+
680+
return job
681+
}
682+
683+
func waitJobReadyWithPodGroup(ctx *context, pgName string, jobNames ...string) error {
684+
return wait.Poll(100*time.Millisecond, oneMinute, taskReadyWithPodGroup(ctx, -1, pgName, jobNames))
685+
}
686+
687+
func taskReadyWithPodGroup(ctx *context, taskNum int, pgName string, jobNames []string) wait.ConditionFunc {
688+
689+
return func() (bool, error) {
690+
pg := &arbv1.PodGroup{}
691+
692+
readyTaskNum := 0
693+
for _, name := range jobNames {
694+
jns, jn, _ := splictJobName(ctx, name)
695+
696+
queueJob, err := ctx.kubeclient.BatchV1().Jobs(jns).Get(jn, metav1.GetOptions{})
697+
Expect(err).NotTo(HaveOccurred())
698+
699+
pods, err := ctx.kubeclient.CoreV1().Pods(jns).List(metav1.ListOptions{})
700+
Expect(err).NotTo(HaveOccurred())
701+
702+
for _, pod := range pods.Items {
703+
labelSelector := labels.SelectorFromSet(queueJob.Spec.Selector.MatchLabels)
704+
if !labelSelector.Matches(labels.Set(pod.Labels)) ||
705+
!metav1.IsControlledBy(&pod, queueJob) {
706+
continue
707+
}
708+
if pod.Status.Phase == v1.PodRunning || pod.Status.Phase == v1.PodSucceeded {
709+
readyTaskNum++
710+
}
711+
}
712+
713+
pg, err = ctx.karclient.Scheduling().PodGroups(jns).Get(pgName, metav1.GetOptions{})
714+
Expect(err).NotTo(HaveOccurred())
715+
}
716+
717+
if taskNum < 0 {
718+
taskNum = int(pg.Spec.MinMember)
719+
}
720+
721+
return taskNum <= readyTaskNum, nil
722+
}
723+
}

0 commit comments

Comments
 (0)