62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
/*
|
|
Copyright 2017 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
// This file contains structures that implement scheduling queue types.
|
|
// Scheduling queues hold pending pods waiting to be scheduled.
|
|
|
|
package core
|
|
|
|
import (
|
|
"k8s.io/client-go/tools/cache"
|
|
)
|
|
|
|
// SchedulingQueue is an interface for a queue to store pods waiting to be scheduled.
|
|
// The interface follows a pattern similar to cache.FIFO and cache.Heap and
|
|
// makes it easy to use those data structures as a SchedulingQueue.
|
|
type SchedulingQueue interface {
|
|
Add(obj interface{}) error
|
|
AddIfNotPresent(obj interface{}) error
|
|
Pop() (interface{}, error)
|
|
Update(obj interface{}) error
|
|
Delete(obj interface{}) error
|
|
List() []interface{}
|
|
ListKeys() []string
|
|
Get(obj interface{}) (item interface{}, exists bool, err error)
|
|
GetByKey(key string) (item interface{}, exists bool, err error)
|
|
}
|
|
|
|
// FIFO is only used to add a Pop() method to cache.FIFO so that it can be
|
|
// used as a SchedulingQueue interface.
|
|
type FIFO struct {
|
|
*cache.FIFO
|
|
}
|
|
|
|
// Pop removes the head of FIFO and returns it.
|
|
// This is just a copy/paste of cache.Pop(queue Queue) from fifo.go that scheduler
|
|
// has always been using. There is a comment in that file saying that this method
|
|
// shouldn't be used in production code, but scheduler has always been using it.
|
|
// This function does minimal error checking.
|
|
func (f *FIFO) Pop() (interface{}, error) {
|
|
var result interface{}
|
|
f.FIFO.Pop(func(obj interface{}) error {
|
|
result = obj
|
|
return nil
|
|
})
|
|
return result, nil
|
|
}
|
|
|
|
var _ = SchedulingQueue(&FIFO{}) // Making sure that FIFO implements SchedulingQueue.
|