Skip to content

Commit 9d319ed

Browse files
committed
propagate deleteMachine annotation
1 parent cf395af commit 9d319ed

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

azure/scope/machinepool.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,24 @@ func (m *MachinePoolScope) applyAzureMachinePoolMachines(ctx context.Context) er
406406
}
407407

408408
existingMachinesByProviderID := make(map[string]infrav1exp.AzureMachinePoolMachine, len(ampms))
409-
for _, machine := range ampms {
410-
existingMachinesByProviderID[machine.Spec.ProviderID] = machine
409+
for _, ampm := range ampms {
410+
existingMachinesByProviderID[ampm.Spec.ProviderID] = ampm
411+
412+
// propagate Machine delete annotation from owner machine to AzureMachinePoolMachine
413+
// this ensures setting a deleteMachine annotation on the Machine has an effect on the AzureMachinePoolMachine
414+
// and the deployment strategy.
415+
machine, err := util.GetOwnerMachine(ctx, m.client, ampm.ObjectMeta)
416+
if err != nil {
417+
// TODO(mw): which verbosity? info or error?
418+
log.V(4).Info("failed to get owner machine", "machine", ampm.Spec.ProviderID)
419+
continue
420+
}
421+
if machine != nil && machine.Annotations != nil {
422+
if _, hasDeleteAnnotation := machine.Annotations[clusterv1.DeleteMachineAnnotation]; hasDeleteAnnotation {
423+
log.V(4).Info("propagating DeleteMachineAnnotation", "machine", ampm.Spec.ProviderID)
424+
existingMachinesByProviderID[ampm.Spec.ProviderID].Annotations[clusterv1.DeleteMachineAnnotation] = machine.Annotations[clusterv1.DeleteMachineAnnotation]
425+
}
426+
}
411427
}
412428

413429
// determine which machines need to be created to reflect the current state in Azure
@@ -472,11 +488,6 @@ func (m *MachinePoolScope) applyAzureMachinePoolMachines(ctx context.Context) er
472488
return errors.Wrap(err, "failed selecting AzureMachinePoolMachine(s) to delete")
473489
}
474490

475-
if val, ok := m.MachinePool.Annotations["cluster.x-k8s.io/capi-autoscaler"]; len(toDelete) > 0 && ok && val == "true" {
476-
log.Info("exiting early due to capi-autoscaler handling scale down", "wouldDelete", len(toDelete))
477-
return nil
478-
}
479-
480491
// Delete MachinePool Machines as a part of scaling down
481492
for i := range toDelete {
482493
ampm := toDelete[i]

0 commit comments

Comments
 (0)