Skip to content

Commit

Permalink
Merge pull request #4704 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…4701-to-release-2.3

[release-2.3] 🐛 Fix deregistering of deleted CAPI Machines
  • Loading branch information
k8s-ci-robot authored Dec 19, 2023
2 parents baabf33 + d8af861 commit ca3cc2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions controllers/awsmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,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)
Expand Down
7 changes: 6 additions & 1 deletion pkg/cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ca3cc2d

Please sign in to comment.