@@ -48,12 +48,22 @@ const (
4848 PodGroupNotFound Status = "PodGroup not found"
4949 Success Status = "Success"
5050 Wait Status = "Wait"
51+
52+ permitStateKey = "PermitCoscheduling"
5153)
5254
55+ type PermitState struct {
56+ Activate bool
57+ }
58+
59+ func (s * PermitState ) Clone () framework.StateData {
60+ return & PermitState {Activate : s .Activate }
61+ }
62+
5363// Manager defines the interfaces for PodGroup management.
5464type Manager interface {
5565 PreFilter (context.Context , * corev1.Pod ) error
56- Permit (context.Context , * corev1.Pod ) Status
66+ Permit (context.Context , * framework. CycleState , * corev1.Pod ) Status
5767 GetPodGroup (context.Context , * corev1.Pod ) (string , * v1alpha1.PodGroup )
5868 GetCreationTimestamp (* corev1.Pod , time.Time ) time.Time
5969 DeletePermittedPodGroup (string )
@@ -108,6 +118,13 @@ func (pgMgr *PodGroupManager) ActivateSiblings(pod *corev1.Pod, state *framework
108118 return
109119 }
110120
121+ // Only proceed if it's explicitly requested to activate sibling pods.
122+ if c , err := state .Read (permitStateKey ); err != nil {
123+ return
124+ } else if s , ok := c .(* PermitState ); ! ok || ! s .Activate {
125+ return
126+ }
127+
111128 pods , err := pgMgr .podLister .Pods (pod .Namespace ).List (
112129 labels .SelectorFromSet (labels.Set {v1alpha1 .PodGroupLabel : pgName }),
113130 )
@@ -193,7 +210,7 @@ func (pgMgr *PodGroupManager) PreFilter(ctx context.Context, pod *corev1.Pod) er
193210}
194211
195212// Permit permits a pod to run, if the minMember match, it would send a signal to chan.
196- func (pgMgr * PodGroupManager ) Permit (ctx context.Context , pod * corev1.Pod ) Status {
213+ func (pgMgr * PodGroupManager ) Permit (ctx context.Context , state * framework. CycleState , pod * corev1.Pod ) Status {
197214 pgFullName , pg := pgMgr .GetPodGroup (ctx , pod )
198215 if pgFullName == "" {
199216 return PodGroupNotSpecified
@@ -209,6 +226,19 @@ func (pgMgr *PodGroupManager) Permit(ctx context.Context, pod *corev1.Pod) Statu
209226 if int32 (assigned )+ 1 >= pg .Spec .MinMember {
210227 return Success
211228 }
229+
230+ if assigned == 0 {
231+ // Given we've reached Permit(), it's mean all PreFilter checks (minMember & minResource)
232+ // already pass through, so if assigned == 0, it could be due to:
233+ // - minResource get satisfied
234+ // - new pods added
235+ // In either case, we should and only should use this 0-th pod to trigger activating
236+ // its siblings.
237+ // It'd be in-efficient if we trigger activating siblings unconditionally.
238+ // See https://github.com/kubernetes-sigs/scheduler-plugins/issues/682
239+ state .Write (permitStateKey , & PermitState {Activate : true })
240+ }
241+
212242 return Wait
213243}
214244
0 commit comments