@@ -129,6 +129,7 @@ func (rollingUpdateStrategy rollingUpdateStrategy) SelectMachinesToDelete(ctx co
129129 }
130130 }()
131131 log = ctrl .LoggerFrom (ctx ).V (4 )
132+ deleteAnnotatedMachines = order (getDeleteAnnotatedMachines (machinesByProviderID ))
132133 failedMachines = order (getFailedMachines (machinesByProviderID ))
133134 deletingMachines = order (getDeletingMachines (machinesByProviderID ))
134135 readyMachines = order (getReadyMachines (machinesByProviderID ))
@@ -143,23 +144,23 @@ func (rollingUpdateStrategy rollingUpdateStrategy) SelectMachinesToDelete(ctx co
143144 }()
144145 )
145146
146- // Order AzureMachinePoolMachines with the clutserv1.DeleteMachineAnnotation to the front so that they have delete priority.
147- // This allows MachinePool Machines to work with the autoscaler.
148- failedMachines = orderByDeleteMachineAnnotation (failedMachines )
149- deletingMachines = orderByDeleteMachineAnnotation (deletingMachines )
150- readyMachines = orderByDeleteMachineAnnotation (readyMachines )
151- machinesWithoutLatestModel = orderByDeleteMachineAnnotation (machinesWithoutLatestModel )
152-
153147 log .Info ("selecting machines to delete" ,
154148 "readyMachines" , len (readyMachines ),
155149 "desiredReplicaCount" , desiredReplicaCount ,
156150 "maxUnavailable" , maxUnavailable ,
157151 "disruptionBudget" , disruptionBudget ,
158152 "machinesWithoutTheLatestModel" , len (machinesWithoutLatestModel ),
153+ "deleteAnnotatedMachines" , len (deleteAnnotatedMachines ),
159154 "failedMachines" , len (failedMachines ),
160155 "deletingMachines" , len (deletingMachines ),
161156 )
162157
158+ // if we have machines annotated with delete machine, remove them
159+ if len (deleteAnnotatedMachines ) > 0 {
160+ log .Info ("delete annotated machines" , "desiredReplicaCount" , desiredReplicaCount , "maxUnavailable" , maxUnavailable , "deleteAnnotatedMachines" , getProviderIDs (deleteAnnotatedMachines ))
161+ return deleteAnnotatedMachines , nil
162+ }
163+
163164 // if we have failed or deleting machines, remove them
164165 if len (failedMachines ) > 0 || len (deletingMachines ) > 0 {
165166 log .Info ("failed or deleting machines" , "desiredReplicaCount" , desiredReplicaCount , "maxUnavailable" , maxUnavailable , "failedMachines" , getProviderIDs (failedMachines ), "deletingMachines" , getProviderIDs (deletingMachines ))
@@ -224,6 +225,18 @@ func (rollingUpdateStrategy rollingUpdateStrategy) SelectMachinesToDelete(ctx co
224225 return toDelete , nil
225226}
226227
228+ func getDeleteAnnotatedMachines (machinesByProviderID map [string ]infrav1exp.AzureMachinePoolMachine ) []infrav1exp.AzureMachinePoolMachine {
229+ var machines []infrav1exp.AzureMachinePoolMachine
230+ for _ , v := range machinesByProviderID {
231+ if v .Annotations != nil {
232+ if _ , hasDeleteAnnotation := v .Annotations [clusterv1 .DeleteMachineAnnotation ]; hasDeleteAnnotation {
233+ machines = append (machines , v )
234+ }
235+ }
236+ }
237+ return machines
238+ }
239+
227240func getFailedMachines (machinesByProviderID map [string ]infrav1exp.AzureMachinePoolMachine ) []infrav1exp.AzureMachinePoolMachine {
228241 var machines []infrav1exp.AzureMachinePoolMachine
229242 for _ , v := range machinesByProviderID {
@@ -304,18 +317,6 @@ func orderRandom(machines []infrav1exp.AzureMachinePoolMachine) []infrav1exp.Azu
304317 return machines
305318}
306319
307- // orderByDeleteMachineAnnotation will sort AzureMachinePoolMachines with the clusterv1.DeleteMachineAnnotation to the front of the list.
308- // It will preserve the existing order of the list otherwise so that it respects the existing delete priority otherwise.
309- func orderByDeleteMachineAnnotation (machines []infrav1exp.AzureMachinePoolMachine ) []infrav1exp.AzureMachinePoolMachine {
310- sort .SliceStable (machines , func (i , j int ) bool {
311- _ , iHasAnnotation := machines [i ].Annotations [clusterv1 .DeleteMachineAnnotation ]
312-
313- return iHasAnnotation
314- })
315-
316- return machines
317- }
318-
319320func getProviderIDs (machines []infrav1exp.AzureMachinePoolMachine ) []string {
320321 ids := make ([]string , len (machines ))
321322 for i , machine := range machines {
0 commit comments