Skip to content

Commit 0b7bd05

Browse files
takoverflowaaronfern
authored andcommitted
Use fully qualified machine name for pending create map (gardener#1043)
* Use fully qualified machine name for pending create map * Extract pendingCreationMap operations into helper functions
1 parent ae0c4ee commit 0b7bd05

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

pkg/util/provider/machinecontroller/machine.go

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

489487
func (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

786784
func (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
}

pkg/util/provider/machinecontroller/machine_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,7 +3829,6 @@ var _ = Describe("machine", func() {
38293829
},
38303830
isCreation: true,
38313831
testFunc: func(setUp setup, req machineActionRequest) (machineutils.RetryPeriod, error) {
3832-
setUp.controller.pendingMachineCreationMap.Store("machine-0", "")
38333832
return setUp.controller.triggerCreationFlow(context.TODO(), &driver.CreateMachineRequest{
38343833
Machine: req.machine,
38353834
MachineClass: req.machineClass,
@@ -3864,7 +3863,7 @@ var _ = Describe("machine", func() {
38643863
},
38653864
isCreation: false,
38663865
testFunc: func(setUp setup, req machineActionRequest) (machineutils.RetryPeriod, error) {
3867-
setUp.controller.pendingMachineCreationMap.Store("machine-0", "")
3866+
setUp.controller.pendingMachineCreationMap.Store("test/machine-0", "")
38683867
return setUp.controller.triggerDeletionFlow(context.TODO(), &driver.DeleteMachineRequest{
38693868
Machine: req.machine,
38703869
MachineClass: req.machineClass,

0 commit comments

Comments
 (0)