@@ -48,12 +48,22 @@ const (
48
48
PodGroupNotFound Status = "PodGroup not found"
49
49
Success Status = "Success"
50
50
Wait Status = "Wait"
51
+
52
+ permitStateKey = "PermitCoscheduling"
51
53
)
52
54
55
+ type PermitState struct {
56
+ Activate bool
57
+ }
58
+
59
+ func (s * PermitState ) Clone () framework.StateData {
60
+ return & PermitState {Activate : s .Activate }
61
+ }
62
+
53
63
// Manager defines the interfaces for PodGroup management.
54
64
type Manager interface {
55
65
PreFilter (context.Context , * corev1.Pod ) error
56
- Permit (context.Context , * corev1.Pod ) Status
66
+ Permit (context.Context , * framework. CycleState , * corev1.Pod ) Status
57
67
GetPodGroup (context.Context , * corev1.Pod ) (string , * v1alpha1.PodGroup )
58
68
GetCreationTimestamp (* corev1.Pod , time.Time ) time.Time
59
69
DeletePermittedPodGroup (string )
@@ -108,6 +118,13 @@ func (pgMgr *PodGroupManager) ActivateSiblings(pod *corev1.Pod, state *framework
108
118
return
109
119
}
110
120
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
+
111
128
pods , err := pgMgr .podLister .Pods (pod .Namespace ).List (
112
129
labels .SelectorFromSet (labels.Set {v1alpha1 .PodGroupLabel : pgName }),
113
130
)
@@ -193,7 +210,7 @@ func (pgMgr *PodGroupManager) PreFilter(ctx context.Context, pod *corev1.Pod) er
193
210
}
194
211
195
212
// 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 {
197
214
pgFullName , pg := pgMgr .GetPodGroup (ctx , pod )
198
215
if pgFullName == "" {
199
216
return PodGroupNotSpecified
@@ -209,6 +226,19 @@ func (pgMgr *PodGroupManager) Permit(ctx context.Context, pod *corev1.Pod) Statu
209
226
if int32 (assigned )+ 1 >= pg .Spec .MinMember {
210
227
return Success
211
228
}
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
+
212
242
return Wait
213
243
}
214
244
0 commit comments