@@ -238,8 +238,6 @@ func (c *controller) reconcileClusterMachine(ctx context.Context, machine *v1alp
238238 }
239239
240240 if machine .Spec .ProviderID == "" || machine .Status .CurrentStatus .Phase == "" || machine .Status .CurrentStatus .Phase == v1alpha1 .MachineCrashLoopBackOff {
241- c .pendingMachineCreationMap .Store (machine .Name , "" )
242-
243241 return c .triggerCreationFlow (
244242 ctx ,
245243 & driver.CreateMachineRequest {
@@ -487,10 +485,6 @@ func addedOrRemovedEssentialTaints(oldNode, node *corev1.Node, taintKeys []strin
487485*/
488486
489487func (c * controller ) triggerCreationFlow (ctx context.Context , createMachineRequest * driver.CreateMachineRequest ) (machineutils.RetryPeriod , error ) {
490- defer func () {
491- c .pendingMachineCreationMap .Delete (createMachineRequest .Machine .Name )
492- }()
493-
494488 var (
495489 // Declarations
496490 nodeName , providerID string
@@ -501,6 +495,10 @@ func (c *controller) triggerCreationFlow(ctx context.Context, createMachineReque
501495 uninitializedMachine = false
502496 addresses = sets .New [corev1.NodeAddress ]()
503497 )
498+ c .markCreationProcessing (machine )
499+ defer func () {
500+ c .unmarkCreationProcessing (machine )
501+ }()
504502
505503 // This field is only modified during the creation flow. We have to assume that every Address that was added to the
506504 // status in the past remains valid, otherwise we have no way of keeping the addresses that might be only returned
@@ -785,13 +783,12 @@ func (c *controller) initializeMachine(ctx context.Context, machine *v1alpha1.Ma
785783
786784func (c * controller ) triggerDeletionFlow (ctx context.Context , deleteMachineRequest * driver.DeleteMachineRequest ) (machineutils.RetryPeriod , error ) {
787785 var (
788- machine = deleteMachineRequest .Machine
789- finalizers = sets .NewString (machine .Finalizers ... )
790- _ , isMachineInCreationFlow = c .pendingMachineCreationMap .Load (machine .Name )
786+ machine = deleteMachineRequest .Machine
787+ finalizers = sets .NewString (machine .Finalizers ... )
791788 )
792789
793790 switch {
794- case isMachineInCreationFlow :
791+ case c . isCreationProcessing ( machine ) :
795792 err := fmt .Errorf ("machine %q is in creation flow. Deletion cannot proceed" , machine .Name )
796793 return machineutils .MediumRetry , err
797794
@@ -868,12 +865,30 @@ func buildAddressStatus(addresses sets.Set[corev1.NodeAddress], nodeName string)
868865 return res
869866}
870867
871- func (c * controller ) shouldMachineBeMovedToTerminatingQueue (machine * v1alpha1.Machine ) bool {
872- _ , isMachineInCreationFlow := c .pendingMachineCreationMap .Load (machine .Name )
868+ func getMachineKey (machine * v1alpha1.Machine ) string {
869+ machineNamespacedName , err := cache .MetaNamespaceKeyFunc (machine )
870+ if err != nil {
871+ machineNamespacedName = fmt .Sprintf ("%s/%s" , machine .Namespace , machine .Name )
872+ klog .Errorf ("couldn't get key for machine %q, using %q instead: %v" , machine .Name , machineNamespacedName , err )
873+ }
874+ return machineNamespacedName
875+ }
873876
874- if machine .DeletionTimestamp != nil && isMachineInCreationFlow {
875- klog .Warningf ("Cannot delete machine %q, its deletionTimestamp is set but it is currently being processed by the creation flow\n " , machine .Name )
877+ func (c * controller ) shouldMachineBeMovedToTerminatingQueue (machine * v1alpha1.Machine ) bool {
878+ if machine .DeletionTimestamp != nil && c .isCreationProcessing (machine ) {
879+ klog .Warningf ("Cannot delete machine %q, its deletionTimestamp is set but it is currently being processed by the creation flow\n " , getMachineKey (machine ))
876880 }
877881
878- return ! isMachineInCreationFlow && machine .DeletionTimestamp != nil
882+ return ! c .isCreationProcessing (machine ) && machine .DeletionTimestamp != nil
883+ }
884+
885+ func (c * controller ) markCreationProcessing (machine * v1alpha1.Machine ) {
886+ c .pendingMachineCreationMap .Store (getMachineKey (machine ), "" )
887+ }
888+ func (c * controller ) unmarkCreationProcessing (machine * v1alpha1.Machine ) {
889+ c .pendingMachineCreationMap .Delete (getMachineKey (machine ))
890+ }
891+ func (c * controller ) isCreationProcessing (machine * v1alpha1.Machine ) bool {
892+ _ , isMachineInCreationFlow := c .pendingMachineCreationMap .Load (getMachineKey (machine ))
893+ return isMachineInCreationFlow
879894}
0 commit comments