in pkg/coscheduling/coscheduling.go [153:196]
func (cs *Coscheduling) PostFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod,
filteredNodeStatusMap framework.NodeToStatusMap) (*framework.PostFilterResult, *framework.Status) {
// Check if the failure comes from PreFilter or not.
_, err := state.Read(cs.getStateKey())
if err == nil {
state.Delete(cs.getStateKey())
return &framework.PostFilterResult{}, framework.NewStatus(framework.Unschedulable)
}
pgName, pg := cs.pgMgr.GetPodGroup(pod)
if pg == nil {
klog.V(4).Info("Pod does not belong to any group")
return &framework.PostFilterResult{}, framework.NewStatus(framework.Unschedulable, "can not find pod group")
}
// This indicates there are already enough Pods satisfying the PodGroup,
// so don't bother to reject the whole PodGroup.
assigned := cs.pgMgr.CalculateAssignedPods(pg.Name, pod.Namespace)
if assigned >= int(pg.Spec.MinMember) {
klog.V(4).Infof("%v pods of %v assigned", assigned, pgName)
return &framework.PostFilterResult{}, framework.NewStatus(framework.Unschedulable)
}
// If the gap is less than/equal 10%, we may want to try subsequent Pods
// to see they can satisfy the PodGroup
notAssiginedPercentage := float32(int(pg.Spec.MinMember)-assigned) / float32(pg.Spec.MinMember)
if notAssiginedPercentage <= 0.1 {
klog.V(4).Infof("%.2f/100 pods of group %v have not assigned", float32(assigned*100), pgName)
return &framework.PostFilterResult{}, framework.NewStatus(framework.Unschedulable)
}
// It's based on an implicit assumption: if the nth Pod failed,
// it's inferrable other Pods belonging to the same PodGroup would be very likely to fail.
cs.frameworkHandler.IterateOverWaitingPods(func(waitingPod framework.WaitingPod) {
if waitingPod.GetPod().Namespace == pod.Namespace && waitingPod.GetPod().Labels[util.PodGroupLabel] == pg.Name {
klog.V(3).Infof("PostFilter rejects the pod: %v/%v", pgName, waitingPod.GetPod().Name)
waitingPod.Reject(cs.Name(), "optimistic rejection in PostFilter")
}
})
cs.pgMgr.AddDeniedPodGroup(pgName)
cs.pgMgr.DeletePermittedPodGroup(pgName)
return &framework.PostFilterResult{}, framework.NewStatus(framework.Unschedulable,
fmt.Sprintf("PodGroup %v gets rejected due to Pod %v is unschedulable even after PostFilter", pgName, pod.Name))
}