Skip to content

Commit 75ac3b7

Browse files
committed
Extract pendingCreationMap operations into helper functions
1 parent 25003d4 commit 75ac3b7

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

pkg/util/provider/machinecontroller/machine.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,9 @@ func (c *controller) triggerCreationFlow(ctx context.Context, createMachineReque
495495
uninitializedMachine = false
496496
addresses = sets.New[corev1.NodeAddress]()
497497
)
498-
machineNamespacedName := getMachineKey(machine)
499-
c.pendingMachineCreationMap.Store(machineNamespacedName, "")
498+
c.markCreationProcessing(machine)
500499
defer func() {
501-
c.pendingMachineCreationMap.Delete(machineNamespacedName)
500+
c.unmarkCreationProcessing(machine)
502501
}()
503502

504503
// This field is only modified during the creation flow. We have to assume that every Address that was added to the
@@ -786,13 +785,12 @@ func (c *controller) initializeMachine(ctx context.Context, machine *v1alpha1.Ma
786785

787786
func (c *controller) triggerDeletionFlow(ctx context.Context, deleteMachineRequest *driver.DeleteMachineRequest) (machineutils.RetryPeriod, error) {
788787
var (
789-
machine = deleteMachineRequest.Machine
790-
finalizers = sets.NewString(machine.Finalizers...)
791-
_, isMachineInCreationFlow = c.pendingMachineCreationMap.Load(getMachineKey(machine))
788+
machine = deleteMachineRequest.Machine
789+
finalizers = sets.NewString(machine.Finalizers...)
792790
)
793791

794792
switch {
795-
case isMachineInCreationFlow:
793+
case c.isCreationProcessing(machine):
796794
err := fmt.Errorf("machine %q is in creation flow. Deletion cannot proceed", machine.Name)
797795
return machineutils.MediumRetry, err
798796

@@ -879,11 +877,20 @@ func getMachineKey(machine *v1alpha1.Machine) string {
879877
}
880878

881879
func (c *controller) shouldMachineBeMovedToTerminatingQueue(machine *v1alpha1.Machine) bool {
882-
_, isMachineInCreationFlow := c.pendingMachineCreationMap.Load(getMachineKey(machine))
883-
884-
if machine.DeletionTimestamp != nil && isMachineInCreationFlow {
885-
klog.Warningf("Cannot delete machine %q, its deletionTimestamp is set but it is currently being processed by the creation flow\n", machine.Name)
880+
if machine.DeletionTimestamp != nil && c.isCreationProcessing(machine) {
881+
klog.Warningf("Cannot delete machine %q, its deletionTimestamp is set but it is currently being processed by the creation flow\n", getMachineKey(machine))
886882
}
887883

888-
return !isMachineInCreationFlow && machine.DeletionTimestamp != nil
884+
return !c.isCreationProcessing(machine) && machine.DeletionTimestamp != nil
885+
}
886+
887+
func (c *controller) markCreationProcessing(machine *v1alpha1.Machine) {
888+
c.pendingMachineCreationMap.Store(getMachineKey(machine), "")
889+
}
890+
func (c *controller) unmarkCreationProcessing(machine *v1alpha1.Machine) {
891+
c.pendingMachineCreationMap.Delete(getMachineKey(machine))
892+
}
893+
func (c *controller) isCreationProcessing(machine *v1alpha1.Machine) bool {
894+
_, isMachineInCreationFlow := c.pendingMachineCreationMap.Load(getMachineKey(machine))
895+
return isMachineInCreationFlow
889896
}

0 commit comments

Comments
 (0)