@@ -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"
@@ -224,7 +225,8 @@ func (r *ReconcileMachineSet) reconcile(ctx context.Context, machineSet *machine
224
225
}
225
226
226
227
// Filter out irrelevant machines (deleting/mismatch labels) and claim orphaned machines.
227
- filteredMachines := make ([]* machinev1beta1.Machine , 0 , len (allMachines .Items ))
228
+ var machineNames []string
229
+ machineSetMachines := make (map [string ]* machinev1beta1.Machine )
228
230
for idx := range allMachines .Items {
229
231
machine := & allMachines .Items [idx ]
230
232
if shouldExcludeMachine (machineSet , machine ) {
@@ -238,8 +240,15 @@ func (r *ReconcileMachineSet) reconcile(ctx context.Context, machineSet *machine
238
240
continue
239
241
}
240
242
}
243
+ machineNames = append (machineNames , machine .Name )
244
+ machineSetMachines [machine .Name ] = machine
245
+ }
246
+ // sort the filteredMachines from the oldest to the youngest
247
+ sort .Strings (machineNames )
241
248
242
- filteredMachines = append (filteredMachines , machine )
249
+ var filteredMachines []* machinev1beta1.Machine
250
+ for _ , machineName := range machineNames {
251
+ filteredMachines = append (filteredMachines , machineSetMachines [machineName ])
243
252
}
244
253
245
254
syncErr := r .syncReplicas (machineSet , filteredMachines )
0 commit comments