@@ -780,10 +780,16 @@ func podName(pod *v1.Pod) string {
780
780
return pod .Namespace + "/" + pod .Name
781
781
}
782
782
783
- // PodFitsResources checks if a node has sufficient resources, such as cpu, memory, gpu, opaque int resources etc to run a pod.
783
+ // PodFitsResources is a wrapper around PodFitsResourcesPredicate that implements FitPredicate interface.
784
+ // TODO(#85822): remove this function once predicate registration logic is deleted.
785
+ func PodFitsResources (pod * v1.Pod , _ Metadata , nodeInfo * schedulernodeinfo.NodeInfo ) (bool , []PredicateFailureReason , error ) {
786
+ return PodFitsResourcesPredicate (pod , nil , nil , nodeInfo )
787
+ }
788
+
789
+ // PodFitsResourcesPredicate checks if a node has sufficient resources, such as cpu, memory, gpu, opaque int resources etc to run a pod.
784
790
// First return value indicates whether a node has sufficient resources to run a pod while the second return value indicates the
785
- // predicate failure reasons if the node has insufficient resources to run the pod.
786
- func PodFitsResources (pod * v1.Pod , meta Metadata , nodeInfo * schedulernodeinfo.NodeInfo ) (bool , []PredicateFailureReason , error ) {
791
+ // predicate failure reasons if the node has insufficient resources to run the pod
792
+ func PodFitsResourcesPredicate (pod * v1.Pod , podRequest * schedulernodeinfo. Resource , ignoredExtendedResources sets. String , nodeInfo * schedulernodeinfo.NodeInfo ) (bool , []PredicateFailureReason , error ) {
787
793
node := nodeInfo .Node ()
788
794
if node == nil {
789
795
return false , nil , fmt .Errorf ("node not found" )
@@ -795,17 +801,11 @@ func PodFitsResources(pod *v1.Pod, meta Metadata, nodeInfo *schedulernodeinfo.No
795
801
predicateFails = append (predicateFails , NewInsufficientResourceError (v1 .ResourcePods , 1 , int64 (len (nodeInfo .Pods ())), int64 (allowedPodNumber )))
796
802
}
797
803
798
- // No extended resources should be ignored by default.
799
- ignoredExtendedResources := sets .NewString ()
804
+ if ignoredExtendedResources == nil {
805
+ ignoredExtendedResources = sets .NewString ()
806
+ }
800
807
801
- var podRequest * schedulernodeinfo.Resource
802
- if predicateMeta , ok := meta .(* predicateMetadata ); ok && predicateMeta .podFitsResourcesMetadata != nil {
803
- podRequest = predicateMeta .podFitsResourcesMetadata .podRequest
804
- if predicateMeta .podFitsResourcesMetadata .ignoredExtendedResources != nil {
805
- ignoredExtendedResources = predicateMeta .podFitsResourcesMetadata .ignoredExtendedResources
806
- }
807
- } else {
808
- // We couldn't parse metadata - fallback to computing it.
808
+ if podRequest == nil {
809
809
podRequest = GetResourceRequest (pod )
810
810
}
811
811
if podRequest .MilliCPU == 0 &&
@@ -839,13 +839,11 @@ func PodFitsResources(pod *v1.Pod, meta Metadata, nodeInfo *schedulernodeinfo.No
839
839
}
840
840
}
841
841
842
- if klog .V (10 ) {
843
- if len (predicateFails ) == 0 {
844
- // We explicitly don't do klog.V(10).Infof() to avoid computing all the parameters if this is
845
- // not logged. There is visible performance gain from it.
846
- klog .Infof ("Schedule Pod %+v on Node %+v is allowed, Node is running only %v out of %v Pods." ,
847
- podName (pod ), node .Name , len (nodeInfo .Pods ()), allowedPodNumber )
848
- }
842
+ if klog .V (10 ) && len (predicateFails ) == 0 {
843
+ // We explicitly don't do klog.V(10).Infof() to avoid computing all the parameters if this is
844
+ // not logged. There is visible performance gain from it.
845
+ klog .Infof ("Schedule Pod %+v on Node %+v is allowed, Node is running only %v out of %v Pods." ,
846
+ podName (pod ), node .Name , len (nodeInfo .Pods ()), allowedPodNumber )
849
847
}
850
848
return len (predicateFails ) == 0 , predicateFails , nil
851
849
}
@@ -1144,43 +1142,11 @@ func haveOverlap(a1, a2 []string) bool {
1144
1142
return false
1145
1143
}
1146
1144
1147
- // GeneralPredicates checks whether noncriticalPredicates and EssentialPredicates pass. noncriticalPredicates are the predicates
1148
- // that only non-critical pods need and EssentialPredicates are the predicates that all pods, including critical pods, need .
1145
+ // GeneralPredicates checks a group of predicates that the kubelet cares about.
1146
+ // DEPRECATED: this exist only because kubelet uses it. We should change kubelet to execute the individual predicates it requires .
1149
1147
func GeneralPredicates (pod * v1.Pod , meta Metadata , nodeInfo * schedulernodeinfo.NodeInfo ) (bool , []PredicateFailureReason , error ) {
1150
1148
var predicateFails []PredicateFailureReason
1151
- for _ , predicate := range []FitPredicate {noncriticalPredicates , EssentialPredicates } {
1152
- fit , reasons , err := predicate (pod , meta , nodeInfo )
1153
- if err != nil {
1154
- return false , predicateFails , err
1155
- }
1156
- if ! fit {
1157
- predicateFails = append (predicateFails , reasons ... )
1158
- }
1159
- }
1160
-
1161
- return len (predicateFails ) == 0 , predicateFails , nil
1162
- }
1163
-
1164
- // noncriticalPredicates are the predicates that only non-critical pods need.
1165
- func noncriticalPredicates (pod * v1.Pod , meta Metadata , nodeInfo * schedulernodeinfo.NodeInfo ) (bool , []PredicateFailureReason , error ) {
1166
- var predicateFails []PredicateFailureReason
1167
- fit , reasons , err := PodFitsResources (pod , meta , nodeInfo )
1168
- if err != nil {
1169
- return false , predicateFails , err
1170
- }
1171
- if ! fit {
1172
- predicateFails = append (predicateFails , reasons ... )
1173
- }
1174
-
1175
- return len (predicateFails ) == 0 , predicateFails , nil
1176
- }
1177
-
1178
- // EssentialPredicates are the predicates that all pods, including critical pods, need.
1179
- func EssentialPredicates (pod * v1.Pod , meta Metadata , nodeInfo * schedulernodeinfo.NodeInfo ) (bool , []PredicateFailureReason , error ) {
1180
- var predicateFails []PredicateFailureReason
1181
- // TODO: PodFitsHostPorts is essential for now, but kubelet should ideally
1182
- // preempt pods to free up host ports too
1183
- for _ , predicate := range []FitPredicate {PodFitsHost , PodFitsHostPorts , PodMatchNodeSelector } {
1149
+ for _ , predicate := range []FitPredicate {PodFitsResources , PodFitsHost , PodFitsHostPorts , PodMatchNodeSelector } {
1184
1150
fit , reasons , err := predicate (pod , meta , nodeInfo )
1185
1151
if err != nil {
1186
1152
return false , predicateFails , err
0 commit comments