scale: sort containers by creation date to remove older ones first (#10571)

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De loof 2023-05-23 19:58:32 +02:00 committed by GitHub
parent 916aac6c27
commit 68c462e607
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -19,6 +19,7 @@ package compose
import (
"context"
"fmt"
"sort"
"strconv"
"strings"
"sync"
@ -172,6 +173,9 @@ func (c *convergence) ensureService(ctx context.Context, project *types.Project,
eg, _ := errgroup.WithContext(ctx)
sort.Slice(containers, func(i, j int) bool {
return containers[i].Created < containers[j].Created
})
for i, container := range containers {
if i >= expected {
// Scale Down