Skip to content

Commit 38ef1d3

Browse files
committed
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 <tobias.giese@mercedes-benz.com>
1 parent 2a790d4 commit 38ef1d3

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

controllers/awsmachine_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,8 @@ func (r *AWSMachineReconciler) reconcileLBAttachment(machineScope *scope.Machine
867867
elbsvc := r.getELBService(elbScope)
868868

869869
// In order to prevent sending request to a "not-ready" control plane machines, it is required to remove the machine
870-
// from the ELB as soon as the machine gets deleted or when the machine is in a not running state.
871-
if !machineScope.AWSMachine.DeletionTimestamp.IsZero() || !machineScope.InstanceIsRunning() {
870+
// from the ELB as soon as the machine or infra machine gets deleted or when the machine is in a not running state.
871+
if machineScope.AWSMachineIsDeleted() || machineScope.MachineIsDeleted() || !machineScope.InstanceIsRunning() {
872872
if elbScope.ControlPlaneLoadBalancer().LoadBalancerType == infrav1.LoadBalancerTypeClassic {
873873
machineScope.Debug("deregistering from classic load balancer")
874874
return r.deregisterInstanceFromClassicLB(machineScope, elbsvc, i)

pkg/cloud/scope/machine.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,16 @@ func (m *MachineScope) InstanceIsInKnownState() bool {
360360
return state != nil && infrav1.InstanceKnownStates.Has(string(*state))
361361
}
362362

363-
// AWSMachineIsDeleted checks if the machine was deleted.
363+
// AWSMachineIsDeleted checks if the AWS machine was deleted.
364364
func (m *MachineScope) AWSMachineIsDeleted() bool {
365365
return !m.AWSMachine.ObjectMeta.DeletionTimestamp.IsZero()
366366
}
367367

368+
// MachineIsDeleted checks if the machine was deleted.
369+
func (m *MachineScope) MachineIsDeleted() bool {
370+
return !m.Machine.ObjectMeta.DeletionTimestamp.IsZero()
371+
}
372+
368373
// IsEKSManaged checks if the machine is EKS managed.
369374
func (m *MachineScope) IsEKSManaged() bool {
370375
return m.InfraCluster.InfraCluster().GetObjectKind().GroupVersionKind().Kind == ekscontrolplanev1.AWSManagedControlPlaneKind

0 commit comments

Comments
 (0)