Skip to content

Commit c592c59

Browse files
Change method signature to not use interface{}
1 parent 5bf172b commit c592c59

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

pkg/controller/queuejob/heap.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,24 @@ import (
1919
"container/heap"
2020
"fmt"
2121
"k8s.io/client-go/tools/cache"
22+
arbv1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
2223
)
2324

2425
// Below is the implementation of the a heap. The logic is pretty much the same
2526
// as cache.heap, however, this heap does not perform synchronization. It leaves
2627
// synchronization to the SchedulingQueue.
2728

28-
type LessFunc func(interface{}, interface{}) bool
29+
type LessFunc func(qj1, qj2 *arbv1.AppWrapper) bool
2930
type KeyFunc func(obj interface{}) (string, error)
3031

3132
type heapItem struct {
32-
obj interface{} // The object which is stored in the heap.
33+
obj *arbv1.AppWrapper // The object which is stored in the heap.
3334
index int // The index of the object's key in the Heap.queue.
3435
}
3536

3637
type itemKeyValue struct {
3738
key string
38-
obj interface{}
39+
obj *arbv1.AppWrapper
3940
}
4041

4142
// heapData is an internal struct that implements the standard heap interface
@@ -121,7 +122,7 @@ type Heap struct {
121122

122123
// Add inserts an item, and puts it in the queue. The item is updated if it
123124
// already exists.
124-
func (h *Heap) Add(obj interface{}) error {
125+
func (h *Heap) Add(obj *arbv1.AppWrapper) error {
125126
key, err := h.data.keyFunc(obj)
126127
if err != nil {
127128
return cache.KeyError{Obj: obj, Err: err}
@@ -136,7 +137,7 @@ func (h *Heap) Add(obj interface{}) error {
136137
}
137138

138139
// BulkAdd adds all the items in the list to the queue.
139-
func (h *Heap) BulkAdd(list []interface{}) error {
140+
func (h *Heap) BulkAdd(list []*arbv1.AppWrapper) error {
140141
for _, obj := range list {
141142
key, err := h.data.keyFunc(obj)
142143
if err != nil {
@@ -154,7 +155,7 @@ func (h *Heap) BulkAdd(list []interface{}) error {
154155

155156
// AddIfNotPresent inserts an item, and puts it in the queue. If an item with
156157
// the key is present in the map, no changes is made to the item.
157-
func (h *Heap) AddIfNotPresent(obj interface{}) error {
158+
func (h *Heap) AddIfNotPresent(obj *arbv1.AppWrapper) error {
158159
key, err := h.data.keyFunc(obj)
159160
if err != nil {
160161
return cache.KeyError{Obj: obj, Err: err}
@@ -167,7 +168,7 @@ func (h *Heap) AddIfNotPresent(obj interface{}) error {
167168

168169
// Update is the same as Add in this implementation. When the item does not
169170
// exist, it is added.
170-
func (h *Heap) Update(obj interface{}) error {
171+
func (h *Heap) Update(obj *arbv1.AppWrapper) error {
171172
return h.Add(obj)
172173
}
173174

pkg/controller/queuejob/queuejob_controller_ex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ func (qjm *XController) ScheduleNext() {
976976
pq := qjm.qjqueue.(*PriorityQueue)
977977
if qjm.qjqueue.Length() > 0 {
978978
for key, element := range pq.activeQ.data.items {
979-
qjtemp := element.obj.(*arbv1.AppWrapper)
979+
qjtemp := element.obj
980980
klog.V(4).Infof("[ScheduleNext] AfterCalc: qjqLength=%d Key=%s index=%d Priority=%.1f SystemPriority=%.1f QueueJobState=%s",
981981
qjm.qjqueue.Length(), key, element.index, float64(qjtemp.Spec.Priority), qjtemp.Status.SystemPriority, qjtemp.Status.QueueJobState)
982982
}

pkg/controller/queuejob/scheduling_queue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"reflect"
4646
"sync"
4747

48+
arbv1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
4849
qjobv1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
4950
"k8s.io/client-go/tools/cache"
5051
"k8s.io/klog/v2"
@@ -320,7 +321,7 @@ func (p *PriorityQueue) Delete(qj *qjobv1.AppWrapper) error {
320321
func (p *PriorityQueue) MoveAllToActiveQueue() {
321322
p.lock.Lock()
322323
defer p.lock.Unlock()
323-
var unschedulableQJs []interface{}
324+
var unschedulableQJs []*arbv1.AppWrapper
324325
for _, qj := range p.unschedulableQ.pods {
325326
unschedulableQJs = append(unschedulableQJs, qj)
326327
}

pkg/controller/queuejob/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func GetXQJFullName(qj *arbv1.AppWrapper) string {
3333
return qj.Name + "_" + qj.Namespace
3434
}
3535

36-
func HigherSystemPriorityQJ(qj1, qj2 interface{}) bool {
37-
return qj1.(*arbv1.AppWrapper).Status.SystemPriority > qj2.(*arbv1.AppWrapper).Status.SystemPriority
36+
func HigherSystemPriorityQJ(qj1, qj2 *arbv1.AppWrapper) bool {
37+
return qj1.Status.SystemPriority > qj2.Status.SystemPriority
3838
}
3939

4040
func createAppWrapperKind(config *rest.Config) error {

0 commit comments

Comments
 (0)