1 /* 2 Copyright 2020 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 framework 18 19 import ( 20 v1 "k8s.io/api/core/v1" 21 extenderv1 "k8s.io/kube-scheduler/extender/v1" 22 ) 23 24 // Extender is an interface for external processes to influence scheduling 25 // decisions made by Kubernetes. This is typically needed for resources not directly 26 // managed by Kubernetes. 27 type Extender interface { 28 // Name returns a unique name that identifies the extender. 29 Name() string 30 31 // Filter based on extender-implemented predicate functions. The filtered list is 32 // expected to be a subset of the supplied list. 33 // The failedNodes and failedAndUnresolvableNodes optionally contains the list 34 // of failed nodes and failure reasons, except nodes in the latter are 35 // unresolvable. 36 Filter(pod *v1.Pod, nodes []*NodeInfo) (filteredNodes []*NodeInfo, failedNodesMap extenderv1.FailedNodesMap, failedAndUnresolvable extenderv1.FailedNodesMap, err error) 37 38 // Prioritize based on extender-implemented priority functions. The returned scores & weight 39 // are used to compute the weighted score for an extender. The weighted scores are added to 40 // the scores computed by Kubernetes scheduler. The total scores are used to do the host selection. 41 Prioritize(pod *v1.Pod, nodes []*NodeInfo) (hostPriorities *extenderv1.HostPriorityList, weight int64, err error) 42 43 // Bind delegates the action of binding a pod to a node to the extender. 44 Bind(binding *v1.Binding) error 45 46 // IsBinder returns whether this extender is configured for the Bind method. 47 IsBinder() bool 48 49 // IsInterested returns true if at least one extended resource requested by 50 // this pod is managed by this extender. 51 IsInterested(pod *v1.Pod) bool 52 53 // IsPrioritizer returns whether this extender is configured for the Prioritize method. 54 IsPrioritizer() bool 55 56 // IsFilter returns whether this extender is configured for the Filter method. 57 IsFilter() bool 58 59 // ProcessPreemption returns nodes with their victim pods processed by extender based on 60 // given: 61 // 1. Pod to schedule 62 // 2. Candidate nodes and victim pods (nodeNameToVictims) generated by previous scheduling process. 63 // The possible changes made by extender may include: 64 // 1. Subset of given candidate nodes after preemption phase of extender. 65 // 2. A different set of victim pod for every given candidate node after preemption phase of extender. 66 ProcessPreemption( 67 pod *v1.Pod, 68 nodeNameToVictims map[string]*extenderv1.Victims, 69 nodeInfos NodeInfoLister, 70 ) (map[string]*extenderv1.Victims, error) 71 72 // SupportsPreemption returns if the scheduler extender support preemption or not. 73 SupportsPreemption() bool 74 75 // IsIgnorable returns true indicates scheduling should not fail when this extender 76 // is unavailable. This gives scheduler ability to fail fast and tolerate non-critical extenders as well. 77 // Both Filter and Bind actions are supported. 78 IsIgnorable() bool 79 } 80