@@ -407,6 +407,18 @@ func TestMachineOldestDelete(t *testing.T) {
407
407
ObjectMeta : metav1.ObjectMeta {CreationTimestamp : metav1 .NewTime (currentTime .Time .AddDate (0 , 0 , - 10 ))},
408
408
Status : clusterv1.MachineStatus {FailureReason : & statusError , NodeRef : nodeRef },
409
409
}
410
+ mustDeleteMachine := & clusterv1.Machine {
411
+ ObjectMeta : metav1.ObjectMeta {Name : "b" , DeletionTimestamp : & currentTime },
412
+ Status : clusterv1.MachineStatus {NodeRef : nodeRef },
413
+ }
414
+ unhealthyMachineA := & clusterv1.Machine {
415
+ ObjectMeta : metav1.ObjectMeta {Name : "a" , CreationTimestamp : metav1 .NewTime (currentTime .Time .AddDate (0 , 0 , - 10 ))},
416
+ Status : clusterv1.MachineStatus {FailureReason : & statusError , NodeRef : nodeRef },
417
+ }
418
+ unhealthyMachineZ := & clusterv1.Machine {
419
+ ObjectMeta : metav1.ObjectMeta {Name : "z" , CreationTimestamp : metav1 .NewTime (currentTime .Time .AddDate (0 , 0 , - 10 ))},
420
+ Status : clusterv1.MachineStatus {FailureReason : & statusError , NodeRef : nodeRef },
421
+ }
410
422
deleteMachineWithoutNodeRef := & clusterv1.Machine {
411
423
ObjectMeta : metav1.ObjectMeta {CreationTimestamp : metav1 .NewTime (currentTime .Time .AddDate (0 , 0 , - 10 ))},
412
424
}
@@ -513,6 +525,23 @@ func TestMachineOldestDelete(t *testing.T) {
513
525
},
514
526
expect : []* clusterv1.Machine {nodeHealthyConditionUnknownMachine },
515
527
},
528
+ // these two cases ensures the mustDeleteMachine is always picked regardless of the machine names.
529
+ {
530
+ desc : "func=oldestDeletePriority, diff=1 (unhealthyMachineA)" ,
531
+ diff : 1 ,
532
+ machines : []* clusterv1.Machine {
533
+ empty , secondNewest , oldest , secondOldest , newest , mustDeleteMachine , unhealthyMachineA ,
534
+ },
535
+ expect : []* clusterv1.Machine {mustDeleteMachine },
536
+ },
537
+ {
538
+ desc : "func=oldestDeletePriority, diff=1 (unhealthyMachineZ)" ,
539
+ diff : 1 ,
540
+ machines : []* clusterv1.Machine {
541
+ empty , secondNewest , oldest , secondOldest , newest , mustDeleteMachine , unhealthyMachineZ ,
542
+ },
543
+ expect : []* clusterv1.Machine {mustDeleteMachine },
544
+ },
516
545
}
517
546
518
547
for _ , test := range tests {
0 commit comments