-
Notifications
You must be signed in to change notification settings - Fork 19
/
queue.go
79 lines (63 loc) · 2.51 KB
/
queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2019 Preferred Networks, Inc.
//
// 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.
package queue
import (
"errors"
"fmt"
v1 "k8s.io/api/core/v1"
)
// Metrics represents a metrics of a PodQueue at one time point.
type Metrics struct {
PendingPodsNum int
}
var (
// ErrEmptyQueue is returned from Pop.
ErrEmptyQueue = errors.New("No pod queued")
// ErrDifferentNames is returned from Update.
ErrDifferentNames = errors.New("Original and new pods have different names")
)
// ErrNoMatchingPod is returned from Update.
type ErrNoMatchingPod struct {
key string
}
func (e *ErrNoMatchingPod) Error() string {
return fmt.Sprintf("No pod with key %q", e.key)
}
// PodQueue defines the interface of pod queues.
type PodQueue interface {
// Push pushes the pod to the "end" of this PodQueue.
Push(pod *v1.Pod) error
// Pop pops the pod on the "front" of this PodQueue.
// This method never blocks; Immediately returns ErrEmptyQueue if the queue is empty.
Pop() (*v1.Pod, error)
// Front refers (not pops) the pod on the "front" of this PodQueue.
// This method never bocks; Immediately returns ErrEmptyQueue if the queue is empty.
Front() (*v1.Pod, error)
// Delete deletes the pod from this PodQueue.
// Returns true if the pod is found, or false otherwise.
Delete(podNamespace, podName string) bool
// Update updates the pod to the newPod.
// Returns ErrNoMatchingPod if an original pod is not found.
// The original and new pods must have the same namespace/name; Otherwise ErrDifferentNames is
// returned in the second field.
Update(podNamespace, podName string, newPod *v1.Pod) error
// NominatedPods returns a list of pods for which the node is nominated for scheduling.
NominatedPods(nodeName string) []*v1.Pod
// UpdateNominatedNode updates the node nomination for the pod.
UpdateNominatedNode(pod *v1.Pod, nodeName string) error
// RemoveNominatedNode removes the node nomination for the pod.
RemoveNominatedNode(pod *v1.Pod) error
// Metrics returns a metrics of this PodQueue.
Metrics() Metrics
}