Skip to content

Commit 8a7680a

Browse files
Merge pull request #654 from hzxuzhonghu/pdb
Remove pdb support
2 parents 10f61a6 + db1e557 commit 8a7680a

File tree

6 files changed

+4
-225
lines changed

6 files changed

+4
-225
lines changed

pkg/scheduler/api/helpers.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,5 @@ func MergeErrors(errs ...error) error {
100100

101101
// JobTerminated checks whether job was terminated.
102102
func JobTerminated(job *JobInfo) bool {
103-
return job.PodGroup == nil &&
104-
job.PDB == nil &&
105-
len(job.Tasks) == 0
103+
return job.PodGroup == nil && len(job.Tasks) == 0
106104
}

pkg/scheduler/api/job_info.go

-23
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ import (
2222
"strings"
2323

2424
"k8s.io/api/core/v1"
25-
policyv1 "k8s.io/api/policy/v1beta1"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2726
"k8s.io/apimachinery/pkg/types"
28-
"k8s.io/apimachinery/pkg/util/intstr"
2927

3028
"volcano.sh/volcano/pkg/apis/scheduling"
3129
"volcano.sh/volcano/pkg/apis/scheduling/v1alpha2"
@@ -150,9 +148,6 @@ type JobInfo struct {
150148

151149
CreationTimestamp metav1.Time
152150
PodGroup *PodGroup
153-
154-
// TODO(k82cn): keep backward compatibility, removed it when v1alpha1 finalized.
155-
PDB *policyv1.PodDisruptionBudget
156151
}
157152

158153
// NewJobInfo creates a new jobInfo for set of tasks
@@ -194,23 +189,6 @@ func (ji *JobInfo) SetPodGroup(pg *PodGroup) {
194189
ji.PodGroup = pg
195190
}
196191

197-
// SetPDB sets PDB to a job
198-
func (ji *JobInfo) SetPDB(pdb *policyv1.PodDisruptionBudget) {
199-
ji.Name = pdb.Name
200-
defaultMinAvailable := intstr.IntOrString{Type: intstr.Int, IntVal: int32(0)}
201-
minAvailable := pdb.Spec.MinAvailable
202-
ji.MinAvailable = int32(intstr.ValueOrDefault(minAvailable, defaultMinAvailable).IntValue())
203-
ji.Namespace = pdb.Namespace
204-
205-
ji.CreationTimestamp = pdb.GetCreationTimestamp()
206-
ji.PDB = pdb
207-
}
208-
209-
// UnsetPDB removes PDB info of a job
210-
func (ji *JobInfo) UnsetPDB() {
211-
ji.PDB = nil
212-
}
213-
214192
func (ji *JobInfo) addTaskIndex(ti *TaskInfo) {
215193
if _, found := ji.TaskStatusIndex[ti.Status]; !found {
216194
ji.TaskStatusIndex[ti.Status] = tasksMap{}
@@ -292,7 +270,6 @@ func (ji *JobInfo) Clone() *JobInfo {
292270

293271
NodesFitErrors: make(map[TaskID]*FitErrors),
294272

295-
PDB: ji.PDB,
296273
PodGroup: ji.PodGroup,
297274

298275
TaskStatusIndex: map[TaskStatus]tasksMap{},

pkg/scheduler/api/job_info_test.go

-23
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import (
2121
"testing"
2222

2323
v1 "k8s.io/api/core/v1"
24-
policyv1 "k8s.io/api/policy/v1beta1"
2524
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26-
"k8s.io/apimachinery/pkg/util/intstr"
2725
)
2826

2927
func jobInfoEqual(l, r *JobInfo) bool {
@@ -200,24 +198,3 @@ func TestDeleteTaskInfo(t *testing.T) {
200198
}
201199
}
202200
}
203-
204-
func TestJobInfo_SetPDB(t *testing.T) {
205-
206-
info := &JobInfo{}
207-
// case1
208-
//intOrString := &intstr.IntOrString{Type:intstr.Int, IntVal:1}
209-
//spec := policyv1.PodDisruptionBudgetSpec{MinAvailable:intOrString}
210-
// case2
211-
//spec := policyv1.PodDisruptionBudgetSpec{}
212-
// case3
213-
//intOrString := &intstr.IntOrString{}
214-
//spec := policyv1.PodDisruptionBudgetSpec{MinAvailable:intOrString}
215-
// case4
216-
intOrString := &intstr.IntOrString{Type: intstr.String, StrVal: "1"}
217-
spec := policyv1.PodDisruptionBudgetSpec{MinAvailable: intOrString}
218-
219-
pdb := &policyv1.PodDisruptionBudget{
220-
Spec: spec,
221-
}
222-
info.SetPDB(pdb)
223-
}

pkg/scheduler/api/test_utils.go

-47
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,13 @@ package api
1818

1919
import (
2020
"fmt"
21-
"reflect"
2221

2322
v1 "k8s.io/api/core/v1"
24-
"k8s.io/api/policy/v1beta1"
2523
"k8s.io/apimachinery/pkg/api/resource"
2624
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2725
"k8s.io/apimachinery/pkg/types"
28-
"k8s.io/apimachinery/pkg/util/intstr"
2926
)
3027

31-
func nodesEqual(l, r map[string]*NodeInfo) bool {
32-
if len(l) != len(r) {
33-
return false
34-
}
35-
36-
for k, n := range l {
37-
if !reflect.DeepEqual(n, r[k]) {
38-
return false
39-
}
40-
}
41-
42-
return true
43-
}
44-
45-
func podsEqual(l, r map[string]*TaskInfo) bool {
46-
if len(l) != len(r) {
47-
return false
48-
}
49-
50-
for k, p := range l {
51-
if !reflect.DeepEqual(p, r[k]) {
52-
return false
53-
}
54-
}
55-
56-
return true
57-
}
58-
5928
func buildNode(name string, alloc v1.ResourceList) *v1.Node {
6029
return &v1.Node{
6130
ObjectMeta: metav1.ObjectMeta{
@@ -93,22 +62,6 @@ func buildPod(ns, n, nn string, p v1.PodPhase, req v1.ResourceList, owner []meta
9362
}
9463
}
9564

96-
func buildPdb(n string, min int, selectorMap map[string]string) *v1beta1.PodDisruptionBudget {
97-
selector := &metav1.LabelSelector{
98-
MatchLabels: selectorMap,
99-
}
100-
minAvailable := intstr.FromInt(min)
101-
return &v1beta1.PodDisruptionBudget{
102-
ObjectMeta: metav1.ObjectMeta{
103-
Name: n,
104-
},
105-
Spec: v1beta1.PodDisruptionBudgetSpec{
106-
Selector: selector,
107-
MinAvailable: &minAvailable,
108-
},
109-
}
110-
}
111-
11265
func buildResourceList(cpu string, memory string) v1.ResourceList {
11366
return v1.ResourceList{
11467
v1.ResourceCPU: resource.MustParse(cpu),

pkg/scheduler/cache/cache.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"k8s.io/apimachinery/pkg/util/wait"
3131
"k8s.io/client-go/informers"
3232
infov1 "k8s.io/client-go/informers/core/v1"
33-
policyv1 "k8s.io/client-go/informers/policy/v1beta1"
3433
schedv1 "k8s.io/client-go/informers/scheduling/v1beta1"
3534
storagev1 "k8s.io/client-go/informers/storage/v1"
3635
"k8s.io/client-go/kubernetes"
@@ -82,7 +81,6 @@ type SchedulerCache struct {
8281

8382
podInformer infov1.PodInformer
8483
nodeInformer infov1.NodeInformer
85-
pdbInformer policyv1.PodDisruptionBudgetInformer
8684
nsInformer infov1.NamespaceInformer
8785
podGroupInformerV1alpha1 vcinformerv1.PodGroupInformer
8886
podGroupInformerV1alpha2 vcinformerv2.PodGroupInformer
@@ -369,13 +367,6 @@ func newSchedulerCache(config *rest.Config, schedulerName string, defaultQueue s
369367
},
370368
})
371369

372-
sc.pdbInformer = informerFactory.Policy().V1beta1().PodDisruptionBudgets()
373-
sc.pdbInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
374-
AddFunc: sc.AddPDB,
375-
UpdateFunc: sc.UpdatePDB,
376-
DeleteFunc: sc.DeletePDB,
377-
})
378-
379370
sc.pcInformer = informerFactory.Scheduling().V1beta1().PriorityClasses()
380371
sc.pcInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
381372
AddFunc: sc.AddPriorityClass,
@@ -428,7 +419,6 @@ func newSchedulerCache(config *rest.Config, schedulerName string, defaultQueue s
428419

429420
// Run starts the schedulerCache
430421
func (sc *SchedulerCache) Run(stopCh <-chan struct{}) {
431-
go sc.pdbInformer.Informer().Run(stopCh)
432422
go sc.podInformer.Informer().Run(stopCh)
433423
go sc.nodeInformer.Informer().Run(stopCh)
434424
go sc.podGroupInformerV1alpha1.Informer().Run(stopCh)
@@ -457,7 +447,6 @@ func (sc *SchedulerCache) WaitForCacheSync(stopCh <-chan struct{}) bool {
457447
return cache.WaitForCacheSync(stopCh,
458448
func() []cache.InformerSynced {
459449
informerSynced := []cache.InformerSynced{
460-
sc.pdbInformer.Informer().HasSynced,
461450
sc.podInformer.Informer().HasSynced,
462451
sc.podGroupInformerV1alpha1.Informer().HasSynced,
463452
sc.podGroupInformerV1alpha2.Informer().HasSynced,
@@ -736,6 +725,7 @@ func (sc *SchedulerCache) Snapshot() *schedulingapi.ClusterInfo {
736725
var wg sync.WaitGroup
737726

738727
cloneJob := func(value *schedulingapi.JobInfo) {
728+
defer wg.Done()
739729
if value.PodGroup != nil {
740730
value.Priority = sc.defaultPriority
741731

@@ -753,7 +743,6 @@ func (sc *SchedulerCache) Snapshot() *schedulingapi.ClusterInfo {
753743
cloneJobLock.Lock()
754744
snapshot.Jobs[value.UID] = clonedJob
755745
cloneJobLock.Unlock()
756-
wg.Done()
757746
}
758747

759748
for _, value := range sc.NamespaceCollection {
@@ -765,7 +754,7 @@ func (sc *SchedulerCache) Snapshot() *schedulingapi.ClusterInfo {
765754

766755
for _, value := range sc.Jobs {
767756
// If no scheduling spec, does not handle it.
768-
if value.PodGroup == nil && value.PDB == nil {
757+
if value.PodGroup == nil {
769758
klog.V(4).Infof("The scheduling spec of Job <%v:%s/%s> is nil, ignore it.",
770759
value.UID, value.Namespace, value.Name)
771760

@@ -840,10 +829,9 @@ func (sc *SchedulerCache) RecordJobStatusEvent(job *schedulingapi.JobInfo) {
840829
(job.PodGroup.Status.Phase == scheduling.PodGroupUnknown ||
841830
job.PodGroup.Status.Phase == scheduling.PodGroupPending ||
842831
job.PodGroup.Status.Phase == scheduling.PodGroupInqueue)
843-
pdbUnschedulabe := job.PDB != nil && len(job.TaskStatusIndex[schedulingapi.Pending]) != 0
844832

845833
// If pending or unschedulable, record unschedulable event.
846-
if pgUnschedulable || pdbUnschedulabe {
834+
if pgUnschedulable {
847835
msg := fmt.Sprintf("%v/%v tasks in gang unschedulable: %v",
848836
len(job.TaskStatusIndex[schedulingapi.Pending]),
849837
len(job.Tasks),

pkg/scheduler/cache/event_handlers.go

-114
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121

2222
"k8s.io/api/core/v1"
23-
policyv1 "k8s.io/api/policy/v1beta1"
2423
"k8s.io/api/scheduling/v1beta1"
2524
"k8s.io/apimachinery/pkg/api/errors"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -579,119 +578,6 @@ func (sc *SchedulerCache) DeletePodGroupV1alpha2(obj interface{}) {
579578
return
580579
}
581580

582-
// Assumes that lock is already acquired.
583-
func (sc *SchedulerCache) setPDB(pdb *policyv1.PodDisruptionBudget) error {
584-
job := schedulingapi.JobID(utils.GetController(pdb))
585-
586-
if len(job) == 0 {
587-
return fmt.Errorf("the controller of PodDisruptionBudget is empty")
588-
}
589-
590-
if _, found := sc.Jobs[job]; !found {
591-
sc.Jobs[job] = schedulingapi.NewJobInfo(job)
592-
}
593-
594-
sc.Jobs[job].SetPDB(pdb)
595-
// Set it to default queue, as PDB did not support queue right now.
596-
sc.Jobs[job].Queue = schedulingapi.QueueID(sc.defaultQueue)
597-
598-
return nil
599-
}
600-
601-
// Assumes that lock is already acquired.
602-
func (sc *SchedulerCache) updatePDB(oldPDB, newPDB *policyv1.PodDisruptionBudget) error {
603-
return sc.setPDB(newPDB)
604-
}
605-
606-
// Assumes that lock is already acquired.
607-
func (sc *SchedulerCache) deletePDB(pdb *policyv1.PodDisruptionBudget) error {
608-
jobID := schedulingapi.JobID(utils.GetController(pdb))
609-
610-
job, found := sc.Jobs[jobID]
611-
if !found {
612-
return fmt.Errorf("can not found job %v:%v/%v", jobID, pdb.Namespace, pdb.Name)
613-
}
614-
615-
// Unset SchedulingSpec
616-
job.UnsetPDB()
617-
618-
sc.deleteJob(job)
619-
620-
return nil
621-
}
622-
623-
// AddPDB add pdb to scheduler cache
624-
func (sc *SchedulerCache) AddPDB(obj interface{}) {
625-
pdb, ok := obj.(*policyv1.PodDisruptionBudget)
626-
if !ok {
627-
klog.Errorf("Cannot convert to *policyv1.PodDisruptionBudget: %v", obj)
628-
return
629-
}
630-
631-
sc.Mutex.Lock()
632-
defer sc.Mutex.Unlock()
633-
634-
err := sc.setPDB(pdb)
635-
if err != nil {
636-
klog.Errorf("Failed to add PodDisruptionBudget %s into cache: %v", pdb.Name, err)
637-
return
638-
}
639-
return
640-
}
641-
642-
//UpdatePDB update pdb to scheduler cache
643-
func (sc *SchedulerCache) UpdatePDB(oldObj, newObj interface{}) {
644-
oldPDB, ok := oldObj.(*policyv1.PodDisruptionBudget)
645-
if !ok {
646-
klog.Errorf("Cannot convert oldObj to *policyv1.PodDisruptionBudget: %v", oldObj)
647-
return
648-
}
649-
newPDB, ok := newObj.(*policyv1.PodDisruptionBudget)
650-
if !ok {
651-
klog.Errorf("Cannot convert newObj to *policyv1.PodDisruptionBudget: %v", newObj)
652-
return
653-
}
654-
655-
sc.Mutex.Lock()
656-
defer sc.Mutex.Unlock()
657-
658-
err := sc.updatePDB(oldPDB, newPDB)
659-
if err != nil {
660-
klog.Errorf("Failed to update PodDisruptionBudget %s into cache: %v", oldPDB.Name, err)
661-
return
662-
}
663-
return
664-
}
665-
666-
//DeletePDB delete pdb from scheduler cache
667-
func (sc *SchedulerCache) DeletePDB(obj interface{}) {
668-
var pdb *policyv1.PodDisruptionBudget
669-
switch t := obj.(type) {
670-
case *policyv1.PodDisruptionBudget:
671-
pdb = t
672-
case cache.DeletedFinalStateUnknown:
673-
var ok bool
674-
pdb, ok = t.Obj.(*policyv1.PodDisruptionBudget)
675-
if !ok {
676-
klog.Errorf("Cannot convert to *policyv1.PodDisruptionBudget: %v", t.Obj)
677-
return
678-
}
679-
default:
680-
klog.Errorf("Cannot convert to *policyv1.PodDisruptionBudget: %v", t)
681-
return
682-
}
683-
684-
sc.Mutex.Lock()
685-
defer sc.Mutex.Unlock()
686-
687-
err := sc.deletePDB(pdb)
688-
if err != nil {
689-
klog.Errorf("Failed to delete PodDisruptionBudget %s from cache: %v", pdb.Name, err)
690-
return
691-
}
692-
return
693-
}
694-
695581
// AddQueueV1alpha1 add queue to scheduler cache
696582
func (sc *SchedulerCache) AddQueueV1alpha1(obj interface{}) {
697583
ss, ok := obj.(*schedulingv1.Queue)

0 commit comments

Comments
 (0)