@@ -19,6 +19,7 @@ package machineset
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "sort"
22
23
"strings"
23
24
"sync"
24
25
"time"
@@ -225,7 +226,8 @@ func (r *ReconcileMachineSet) reconcile(ctx context.Context, machineSet *machine
225
226
}
226
227
227
228
// Filter out irrelevant machines (deleting/mismatch labels) and claim orphaned machines.
228
- filteredMachines := make ([]* machinev1beta1.Machine , 0 , len (allMachines .Items ))
229
+ var machineNames []string
230
+ machineSetMachines := make (map [string ]* machinev1beta1.Machine )
229
231
for idx := range allMachines .Items {
230
232
machine := & allMachines .Items [idx ]
231
233
if shouldExcludeMachine (machineSet , machine ) {
@@ -239,8 +241,15 @@ func (r *ReconcileMachineSet) reconcile(ctx context.Context, machineSet *machine
239
241
continue
240
242
}
241
243
}
244
+ machineNames = append (machineNames , machine .Name )
245
+ machineSetMachines [machine .Name ] = machine
246
+ }
247
+ // sort the filteredMachines from the oldest to the youngest
248
+ sort .Strings (machineNames )
242
249
243
- filteredMachines = append (filteredMachines , machine )
250
+ var filteredMachines []* machinev1beta1.Machine
251
+ for _ , machineName := range machineNames {
252
+ filteredMachines = append (filteredMachines , machineSetMachines [machineName ])
244
253
}
245
254
246
255
syncErr := r .syncReplicas (machineSet , filteredMachines )
0 commit comments