diff --git a/pkg/controller/machine.go b/pkg/controller/machine.go index 11fb8051b..fbe496782 100644 --- a/pkg/controller/machine.go +++ b/pkg/controller/machine.go @@ -599,7 +599,9 @@ func (c *controller) machineDelete(machine *v1alpha1.Machine, driver driver.Driv } } - if machineID != "" { + if machineID != "" && nodeName != "" { + // Begin drain logic only when the nodeName & providerID exist's for the machine + var ( forceDeletePods = false forceDeleteMachine = false diff --git a/pkg/controller/machine_test.go b/pkg/controller/machine_test.go index ff60fa56d..4cd6bce7a 100644 --- a/pkg/controller/machine_test.go +++ b/pkg/controller/machine_test.go @@ -1387,6 +1387,42 @@ var _ = Describe("machine", func() { machineDeleted: false, }, }), + Entry("Allow machine object deletion where nodeName doesn't exist", &data{ + setup: setup{ + secrets: []*corev1.Secret{ + { + ObjectMeta: *newObjectMeta(objMeta, 0), + }, + }, + aws: []*machinev1.AWSMachineClass{ + { + ObjectMeta: *newObjectMeta(objMeta, 0), + Spec: machinev1.AWSMachineClassSpec{ + SecretRef: newSecretReference(objMeta, 0), + }, + }, + }, + machines: newMachines(1, &machinev1.MachineTemplateSpec{ + ObjectMeta: *newObjectMeta(objMeta, 0), + Spec: machinev1.MachineSpec{ + Class: machinev1.ClassSpec{ + Kind: "AWSMachineClass", + Name: "machine-0", + }, + }, + }, nil, nil, nil, nil), + }, + action: action{ + machine: "machine-0", + fakeProviderID: "fakeID-0", + fakeNodeName: "", //NodeName is set to emptyString + fakeError: nil, + }, + expect: expect{ + errOccurred: true, + machineDeleted: true, + }, + }), ) })