@@ -166,7 +166,7 @@ func (r *PoolReconciler) reconcilePool(ctx context.Context, pool *sandboxv1alpha
166166 schedulePods := r .filterEvictingPods (ctx , latestPool , pods , allocBeforeSchedule )
167167
168168 // 4. Schedule and allocate
169- podAllocation , pendingSyncs , idlePods , supplySandbox , poolDirty , err := r .scheduleSandbox (ctx , latestPool , batchSandboxes , schedulePods )
169+ podAllocation , pendingSyncs , idlePods , dirtyPods , supplySandbox , poolDirty , err := r .scheduleSandbox (ctx , latestPool , batchSandboxes , schedulePods )
170170 if err != nil {
171171 return err
172172 }
@@ -207,7 +207,7 @@ func (r *PoolReconciler) reconcilePool(ctx context.Context, pool *sandboxv1alpha
207207 if err != nil {
208208 return err
209209 }
210- latestIdlePods , deleteOld , supplyNew := r .updatePool (ctx , latestRevision , schedulePods , idlePods )
210+ latestIdlePods , deleteOld , supplyNew := r .updatePool (ctx , latestRevision , schedulePods , idlePods , dirtyPods )
211211
212212 args := & scaleArgs {
213213 latestRevision : latestRevision ,
@@ -327,7 +327,7 @@ func (r *PoolReconciler) SetupWithManager(mgr ctrl.Manager) error {
327327 Complete (r )
328328}
329329
330- func (r * PoolReconciler ) scheduleSandbox (ctx context.Context , pool * sandboxv1alpha1.Pool , batchSandboxes []* sandboxv1alpha1.BatchSandbox , pods []* corev1.Pod ) (map [string ]string , []SandboxSyncInfo , []string , int32 , bool , error ) {
330+ func (r * PoolReconciler ) scheduleSandbox (ctx context.Context , pool * sandboxv1alpha1.Pool , batchSandboxes []* sandboxv1alpha1.BatchSandbox , pods []* corev1.Pod ) (map [string ]string , []SandboxSyncInfo , []string , [] string , int32 , bool , error ) {
331331 log := logf .FromContext (ctx )
332332 spec := & AllocSpec {
333333 Sandboxes : batchSandboxes ,
@@ -336,7 +336,7 @@ func (r *PoolReconciler) scheduleSandbox(ctx context.Context, pool *sandboxv1alp
336336 }
337337 status , pendingSyncs , poolDirty , err := r .Allocator .Schedule (ctx , spec )
338338 if err != nil {
339- return nil , nil , nil , 0 , false , err
339+ return nil , nil , nil , nil , 0 , false , err
340340 }
341341 idlePods := make ([]string , 0 )
342342 for _ , pod := range pods {
@@ -346,10 +346,10 @@ func (r *PoolReconciler) scheduleSandbox(ctx context.Context, pool *sandboxv1alp
346346 }
347347 log .Info ("Schedule result" , "pool" , pool .Name , "allocated" , len (status .PodAllocation ),
348348 "idlePods" , len (idlePods ), "supplement" , status .PodSupplement , "pendingSyncs" , len (pendingSyncs ), "poolDirty" , poolDirty )
349- return status .PodAllocation , pendingSyncs , idlePods , status .PodSupplement , poolDirty , nil
349+ return status .PodAllocation , pendingSyncs , idlePods , status .DirtyPods , status . PodSupplement , poolDirty , nil
350350}
351351
352- func (r * PoolReconciler ) updatePool (ctx context.Context , latestRevision string , pods []* corev1.Pod , idlePods []string ) ([]string , []string , int32 ) {
352+ func (r * PoolReconciler ) updatePool (ctx context.Context , latestRevision string , pods []* corev1.Pod , idlePods []string , dirtyPods [] string ) ([]string , []string , int32 ) {
353353 podMap := make (map [string ]* corev1.Pod )
354354 for _ , pod := range pods {
355355 podMap [pod .Name ] = pod
@@ -358,7 +358,18 @@ func (r *PoolReconciler) updatePool(ctx context.Context, latestRevision string,
358358 deleteOld := make ([]string , 0 )
359359 supplyNew := int32 (0 )
360360
361+ dirtySet := make (map [string ]bool )
362+ for _ , p := range dirtyPods {
363+ dirtySet [p ] = true
364+ }
365+
361366 for _ , name := range idlePods {
367+ if dirtySet [name ] {
368+ deleteOld = append (deleteOld , name )
369+ // no need to supply, next reconcile will do this job
370+ continue
371+ }
372+
362373 pod , ok := podMap [name ]
363374 if ! ok {
364375 continue
0 commit comments