volcano.sh/volcano@v1.9.0/pkg/scheduler/api/types.go (about) 1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package api 18 19 import ( 20 k8sframework "k8s.io/kubernetes/pkg/scheduler/framework" 21 ) 22 23 // TaskStatus defines the status of a task/pod. 24 type TaskStatus int 25 26 const ( 27 // Pending means the task is pending in the apiserver. 28 Pending TaskStatus = 1 << iota 29 30 // Allocated means the scheduler assigns a host to it. 31 Allocated 32 33 // Pipelined means the scheduler assigns a host to wait for releasing resource. 34 Pipelined 35 36 // Binding means the scheduler send Bind request to apiserver. 37 Binding 38 39 // Bound means the task/Pod bounds to a host. 40 Bound 41 42 // Running means a task is running on the host. 43 Running 44 45 // Releasing means a task/pod is deleted. 46 Releasing 47 48 // Succeeded means that all containers in the pod have voluntarily terminated 49 // with a container exit code of 0, and the system is not going to restart any of these containers. 50 Succeeded 51 52 // Failed means that all containers in the pod have terminated, and at least one container has 53 // terminated in a failure (exited with a non-zero exit code or was stopped by the system). 54 Failed 55 56 // Unknown means the status of task/pod is unknown to the scheduler. 57 Unknown 58 ) 59 60 func (ts TaskStatus) String() string { 61 switch ts { 62 case Pending: 63 return "Pending" 64 case Allocated: 65 return "Allocated" 66 case Pipelined: 67 return "Pipelined" 68 case Binding: 69 return "Binding" 70 case Bound: 71 return "Bound" 72 case Running: 73 return "Running" 74 case Releasing: 75 return "Releasing" 76 case Succeeded: 77 return "Succeeded" 78 case Failed: 79 return "Failed" 80 default: 81 return "Unknown" 82 } 83 } 84 85 // NodePhase defines the phase of node 86 type NodePhase int 87 88 const ( 89 // Ready means the node is ready for scheduling 90 Ready NodePhase = 1 << iota 91 // NotReady means the node is not ready for scheduling 92 NotReady 93 ) 94 95 func (np NodePhase) String() string { 96 switch np { 97 case Ready: 98 return "Ready" 99 case NotReady: 100 return "NotReady" 101 } 102 103 return "Unknown" 104 } 105 106 // validateStatusUpdate validates whether the status transfer is valid. 107 func validateStatusUpdate(oldStatus, newStatus TaskStatus) error { 108 return nil 109 } 110 111 // LessFn is the func declaration used by sort or priority queue. 112 type LessFn func(interface{}, interface{}) bool 113 114 // CompareFn is the func declaration used by sort or priority queue. 115 type CompareFn func(interface{}, interface{}) int 116 117 // ValidateFn is the func declaration used to check object's status. 118 type ValidateFn func(interface{}) bool 119 120 // ValidateResult is struct to which can used to determine the result 121 type ValidateResult struct { 122 Pass bool 123 Reason string 124 Message string 125 } 126 127 // These are predefined codes used in a Status. 128 const ( 129 // Success means that plugin ran correctly and found pod schedulable. 130 // NOTE: A nil status is also considered as "Success". 131 Success int = iota 132 // Error is used for internal plugin errors, unexpected input, etc. 133 Error 134 // Unschedulable is used when a plugin finds a pod unschedulable. The scheduler might attempt to 135 // preempt other pods to get this pod scheduled. Use UnschedulableAndUnresolvable to make the 136 // scheduler skip preemption. 137 // The accompanying status message should explain why the pod is unschedulable. 138 Unschedulable 139 // UnschedulableAndUnresolvable is used when a plugin finds a pod unschedulable and 140 // preemption would not change anything. Plugins should return Unschedulable if it is possible 141 // that the pod can get scheduled with preemption. 142 // The accompanying status message should explain why the pod is unschedulable. 143 UnschedulableAndUnresolvable 144 // Wait is used when a Permit plugin finds a pod scheduling should wait. 145 Wait 146 // Skip is used when a Bind plugin chooses to skip binding. 147 Skip 148 ) 149 150 type Status struct { 151 Code int 152 Reason string 153 } 154 155 // String represents status string 156 func (s Status) String() string { 157 return s.Reason 158 } 159 160 // ValidateExFn is the func declaration used to validate the result. 161 type ValidateExFn func(interface{}) *ValidateResult 162 163 // VoteFn is the func declaration used to check object's complicated status. 164 type VoteFn func(interface{}) int 165 166 // JobEnqueuedFn is the func declaration used to call after job enqueued. 167 type JobEnqueuedFn func(interface{}) 168 169 // PredicateFn is the func declaration used to predicate node for task. 170 type PredicateFn func(*TaskInfo, *NodeInfo) ([]*Status, error) 171 172 // PrePredicateFn is the func declaration used to pre-predicate node for task. 173 type PrePredicateFn func(*TaskInfo) error 174 175 // BestNodeFn is the func declaration used to return the nodeScores to plugins. 176 type BestNodeFn func(*TaskInfo, map[float64][]*NodeInfo) *NodeInfo 177 178 // EvictableFn is the func declaration used to evict tasks. 179 type EvictableFn func(*TaskInfo, []*TaskInfo) ([]*TaskInfo, int) 180 181 // NodeOrderFn is the func declaration used to get priority score for a node for a particular task. 182 type NodeOrderFn func(*TaskInfo, *NodeInfo) (float64, error) 183 184 // BatchNodeOrderFn is the func declaration used to get priority score for ALL nodes for a particular task. 185 type BatchNodeOrderFn func(*TaskInfo, []*NodeInfo) (map[string]float64, error) 186 187 // NodeMapFn is the func declaration used to get priority score for a node for a particular task. 188 type NodeMapFn func(*TaskInfo, *NodeInfo) (float64, error) 189 190 // NodeReduceFn is the func declaration used to reduce priority score for a node for a particular task. 191 type NodeReduceFn func(*TaskInfo, k8sframework.NodeScoreList) error 192 193 // NodeOrderMapFn is the func declaration used to get priority score of all plugins for a node for a particular task. 194 type NodeOrderMapFn func(*TaskInfo, *NodeInfo) (map[string]float64, float64, error) 195 196 // NodeOrderReduceFn is the func declaration used to reduce priority score of all nodes for a plugin for a particular task. 197 type NodeOrderReduceFn func(*TaskInfo, map[string]k8sframework.NodeScoreList) (map[string]float64, error) 198 199 // TargetJobFn is the func declaration used to select the target job satisfies some conditions 200 type TargetJobFn func([]*JobInfo) *JobInfo 201 202 // ReservedNodesFn is the func declaration used to select the reserved nodes 203 type ReservedNodesFn func() 204 205 // VictimTasksFn is the func declaration used to select victim tasks 206 type VictimTasksFn func([]*TaskInfo) []*TaskInfo 207 208 // AllocatableFn is the func declaration used to check whether the task can be allocated 209 type AllocatableFn func(*QueueInfo, *TaskInfo) bool