From d6cd10b803f5b674e59c99d49ac8a97fd4f4ea6c Mon Sep 17 00:00:00 2001 From: Tobias Giese Date: Mon, 18 Dec 2023 20:18:00 +0100 Subject: [PATCH] Fix deregistering of deleted CAPI Machines We have an issue that there is a gap between the CAPI Machine deletion and the AWSMachine deletion. In this timeframe the kube-apiserver to the to be deleted control plane is no longer possible, but the deregistering of the LB member will be performed only for AWSMachine deletions. This PR fixes the gap and also deregisteres the instance if the CAPI Machine is deleted. Signed-off-by: Tobias Giese --- controllers/awsmachine_controller.go | 4 ++-- pkg/cloud/scope/machine.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/controllers/awsmachine_controller.go b/controllers/awsmachine_controller.go index 2c511093ca..0da9cb1e6d 100644 --- a/controllers/awsmachine_controller.go +++ b/controllers/awsmachine_controller.go @@ -835,8 +835,8 @@ func (r *AWSMachineReconciler) reconcileLBAttachment(machineScope *scope.Machine elbsvc := r.getELBService(elbScope) // In order to prevent sending request to a "not-ready" control plane machines, it is required to remove the machine - // from the ELB as soon as the machine gets deleted or when the machine is in a not running state. - if !machineScope.AWSMachine.DeletionTimestamp.IsZero() || !machineScope.InstanceIsRunning() { + // from the ELB as soon as the machine or infra machine gets deleted or when the machine is in a not running state. + if machineScope.AWSMachineIsDeleted() || machineScope.MachineIsDeleted() || !machineScope.InstanceIsRunning() { if elbScope.ControlPlaneLoadBalancer().LoadBalancerType == infrav1.LoadBalancerTypeClassic { machineScope.Debug("deregistering from classic load balancer") return r.deregisterInstanceFromClassicLB(machineScope, elbsvc, i) diff --git a/pkg/cloud/scope/machine.go b/pkg/cloud/scope/machine.go index 208895d8e3..20ef163058 100644 --- a/pkg/cloud/scope/machine.go +++ b/pkg/cloud/scope/machine.go @@ -360,11 +360,16 @@ func (m *MachineScope) InstanceIsInKnownState() bool { return state != nil && infrav1.InstanceKnownStates.Has(string(*state)) } -// AWSMachineIsDeleted checks if the machine was deleted. +// AWSMachineIsDeleted checks if the AWS machine was deleted. func (m *MachineScope) AWSMachineIsDeleted() bool { return !m.AWSMachine.ObjectMeta.DeletionTimestamp.IsZero() } +// MachineIsDeleted checks if the machine was deleted. +func (m *MachineScope) MachineIsDeleted() bool { + return !m.Machine.ObjectMeta.DeletionTimestamp.IsZero() +} + // IsEKSManaged checks if the machine is EKS managed. func (m *MachineScope) IsEKSManaged() bool { return m.InfraCluster.InfraCluster().GetObjectKind().GroupVersionKind().Kind == ekscontrolplanev1.AWSManagedControlPlaneKind