@@ -160,12 +160,6 @@ func (rollingUpdateStrategy rollingUpdateStrategy) SelectMachinesToDelete(ctx co
160160 "deletingMachines" , len (deletingMachines ),
161161 )
162162
163- // if we have machines annotated with delete machine, remove them
164- if len (deleteAnnotatedMachines ) > 0 {
165- log .Info ("delete annotated machines" , "desiredReplicaCount" , desiredReplicaCount , "maxUnavailable" , maxUnavailable , "deleteAnnotatedMachines" , getProviderIDs (deleteAnnotatedMachines ))
166- return deleteAnnotatedMachines , nil
167- }
168-
169163 // if we have failed or deleting machines, remove them
170164 if len (failedMachines ) > 0 || len (deletingMachines ) > 0 {
171165 log .Info ("failed or deleting machines" , "desiredReplicaCount" , desiredReplicaCount , "maxUnavailable" , maxUnavailable , "failedMachines" , getProviderIDs (failedMachines ), "deletingMachines" , getProviderIDs (deletingMachines ))
@@ -328,6 +322,18 @@ func orderRandom(machines []infrav1exp.AzureMachinePoolMachine) []infrav1exp.Azu
328322 return machines
329323}
330324
325+ // orderByDeleteMachineAnnotation will sort AzureMachinePoolMachines with the clusterv1.DeleteMachineAnnotation to the front of the list.
326+ // It will preserve the existing order of the list otherwise so that it respects the existing delete priority otherwise.
327+ func orderByDeleteMachineAnnotation (machines []infrav1exp.AzureMachinePoolMachine ) []infrav1exp.AzureMachinePoolMachine {
328+ sort .SliceStable (machines , func (i , j int ) bool {
329+ _ , iHasAnnotation := machines [i ].Annotations [clusterv1 .DeleteMachineAnnotation ]
330+
331+ return iHasAnnotation
332+ })
333+
334+ return machines
335+ }
336+
331337func getProviderIDs (machines []infrav1exp.AzureMachinePoolMachine ) []string {
332338 ids := make ([]string , len (machines ))
333339 for i , machine := range machines {
0 commit comments