@@ -87,6 +87,7 @@ type AWSMachineReconciler struct {
8787	Endpoints                     []scope.ServiceEndpoint 
8888	WatchFilterValue              string 
8989	TagUnmanagedNetworkResources  bool 
90+ 	MaxWaitActiveUpdateDelete     time.Duration 
9091}
9192
9293const  (
@@ -330,7 +331,7 @@ func (r *AWSMachineReconciler) reconcileDelete(ctx context.Context, machineScope
330331
331332	machineScope .Debug ("EC2 instance found matching deleted AWSMachine" , "instance-id" , instance .ID )
332333
333- 	if  err  :=  r .reconcileLBAttachment (machineScope , elbScope , instance ); err  !=  nil  {
334+ 	if  err  :=  r .reconcileLBAttachment (ctx ,  machineScope , elbScope , instance ); err  !=  nil  {
334335		// We are tolerating AccessDenied error, so this won't block for users with older version of IAM; 
335336		// all the other errors are blocking. 
336337		// Because we are reconciling all load balancers, attempt to treat the error as a list of errors. 
@@ -641,7 +642,7 @@ func (r *AWSMachineReconciler) reconcileNormal(ctx context.Context, machineScope
641642			r .ensureStorageTags (ec2svc , instance , machineScope .AWSMachine , machineScope .AdditionalTags ())
642643		}
643644
644- 		if  err  :=  r .reconcileLBAttachment (machineScope , elbScope , instance ); err  !=  nil  {
645+ 		if  err  :=  r .reconcileLBAttachment (ctx ,  machineScope , elbScope , instance ); err  !=  nil  {
645646			// We are tolerating InstanceNotRunning error, so we don't report it as an error condition. 
646647			// Because we are reconciling all load balancers, attempt to treat the error as a list of errors. 
647648			if  err  :=  kerrors .FilterOut (err , elb .IsInstanceNotRunning ); err  !=  nil  {
@@ -954,7 +955,7 @@ func (r *AWSMachineReconciler) deleteIgnitionBootstrapDataFromS3(ctx context.Con
954955
955956// reconcileLBAttachment reconciles attachment to _all_ defined load balancers. 
956957// Callers are expected to filter out known-good errors out of the aggregate error list. 
957- func  (r  * AWSMachineReconciler ) reconcileLBAttachment (machineScope  * scope.MachineScope , elbScope  scope.ELBScope , i  * infrav1.Instance ) error  {
958+ func  (r  * AWSMachineReconciler ) reconcileLBAttachment (ctx  context. Context ,  machineScope  * scope.MachineScope , elbScope  scope.ELBScope , i  * infrav1.Instance ) error  {
958959	if  ! machineScope .IsControlPlane () {
959960		return  nil 
960961	}
@@ -971,36 +972,36 @@ func (r *AWSMachineReconciler) reconcileLBAttachment(machineScope *scope.Machine
971972		if  machineScope .AWSMachineIsDeleted () ||  machineScope .MachineIsDeleted () ||  ! machineScope .InstanceIsRunning () {
972973			if  lbSpec .LoadBalancerType  ==  infrav1 .LoadBalancerTypeClassic  {
973974				machineScope .Debug ("deregistering from classic load balancer" )
974- 				return  r .deregisterInstanceFromClassicLB (machineScope , elbsvc , i )
975+ 				return  r .deregisterInstanceFromClassicLB (ctx ,  machineScope , elbsvc , i )
975976			}
976977			machineScope .Debug ("deregistering from v2 load balancer" )
977- 			errs  =  append (errs , r .deregisterInstanceFromV2LB (machineScope , elbsvc , i , lbSpec ))
978+ 			errs  =  append (errs , r .deregisterInstanceFromV2LB (ctx ,  machineScope , elbsvc , i , lbSpec ))
978979			continue 
979980		}
980981
981- 		if  err  :=  r .registerInstanceToLBs (machineScope , elbsvc , i , lbSpec ); err  !=  nil  {
982+ 		if  err  :=  r .registerInstanceToLBs (ctx ,  machineScope , elbsvc , i , lbSpec ); err  !=  nil  {
982983			errs  =  append (errs , errors .Wrapf (err , "could not register machine to load balancer" ))
983984		}
984985	}
985986
986987	return  kerrors .NewAggregate (errs )
987988}
988989
989- func  (r  * AWSMachineReconciler ) registerInstanceToLBs (machineScope  * scope.MachineScope , elbsvc  services.ELBInterface , i  * infrav1.Instance , lb  * infrav1.AWSLoadBalancerSpec ) error  {
990+ func  (r  * AWSMachineReconciler ) registerInstanceToLBs (ctx  context. Context ,  machineScope  * scope.MachineScope , elbsvc  services.ELBInterface , i  * infrav1.Instance , lb  * infrav1.AWSLoadBalancerSpec ) error  {
990991	switch  lb .LoadBalancerType  {
991992	case  infrav1 .LoadBalancerTypeClassic , "" :
992993		machineScope .Debug ("registering to classic load balancer" )
993- 		return  r .registerInstanceToClassicLB (machineScope , elbsvc , i )
994+ 		return  r .registerInstanceToClassicLB (ctx ,  machineScope , elbsvc , i )
994995	case  infrav1 .LoadBalancerTypeELB , infrav1 .LoadBalancerTypeALB , infrav1 .LoadBalancerTypeNLB :
995996		machineScope .Debug ("registering to v2 load balancer" )
996- 		return  r .registerInstanceToV2LB (machineScope , elbsvc , i , lb )
997+ 		return  r .registerInstanceToV2LB (ctx ,  machineScope , elbsvc , i , lb )
997998	}
998999
9991000	return  errors .Errorf ("unknown load balancer type %q" , lb .LoadBalancerType )
10001001}
10011002
1002- func  (r  * AWSMachineReconciler ) registerInstanceToClassicLB (machineScope  * scope.MachineScope , elbsvc  services.ELBInterface , i  * infrav1.Instance ) error  {
1003- 	registered , err  :=  elbsvc .IsInstanceRegisteredWithAPIServerELB (i )
1003+ func  (r  * AWSMachineReconciler ) registerInstanceToClassicLB (ctx  context. Context ,  machineScope  * scope.MachineScope , elbsvc  services.ELBInterface , i  * infrav1.Instance ) error  {
1004+ 	registered , err  :=  elbsvc .IsInstanceRegisteredWithAPIServerELB (ctx ,  i )
10041005	if  err  !=  nil  {
10051006		r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedAttachControlPlaneELB" ,
10061007			"Failed to register control plane instance %q with classic load balancer: failed to determine registration status: %v" , i .ID , err )
@@ -1011,7 +1012,7 @@ func (r *AWSMachineReconciler) registerInstanceToClassicLB(machineScope *scope.M
10111012		return  nil 
10121013	}
10131014
1014- 	if  err  :=  elbsvc .RegisterInstanceWithAPIServerELB (i ); err  !=  nil  {
1015+ 	if  err  :=  elbsvc .RegisterInstanceWithAPIServerELB (ctx ,  i ); err  !=  nil  {
10151016		r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedAttachControlPlaneELB" ,
10161017			"Failed to register control plane instance %q with classic load balancer: %v" , i .ID , err )
10171018		conditions .MarkFalse (machineScope .AWSMachine , infrav1 .ELBAttachedCondition , infrav1 .ELBAttachFailedReason , clusterv1 .ConditionSeverityError , "%s" , err .Error ())
@@ -1023,8 +1024,8 @@ func (r *AWSMachineReconciler) registerInstanceToClassicLB(machineScope *scope.M
10231024	return  nil 
10241025}
10251026
1026- func  (r  * AWSMachineReconciler ) registerInstanceToV2LB (machineScope  * scope.MachineScope , elbsvc  services.ELBInterface , instance  * infrav1.Instance , lb  * infrav1.AWSLoadBalancerSpec ) error  {
1027- 	_ , registered , err  :=  elbsvc .IsInstanceRegisteredWithAPIServerLB (instance , lb )
1027+ func  (r  * AWSMachineReconciler ) registerInstanceToV2LB (ctx  context. Context ,  machineScope  * scope.MachineScope , elbsvc  services.ELBInterface , instance  * infrav1.Instance , lb  * infrav1.AWSLoadBalancerSpec ) error  {
1028+ 	_ , registered , err  :=  elbsvc .IsInstanceRegisteredWithAPIServerLB (ctx ,  instance , lb )
10281029	if  err  !=  nil  {
10291030		r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedAttachControlPlaneELB" ,
10301031			"Failed to register control plane instance %q with load balancer: failed to determine registration status: %v" , instance .ID , err )
@@ -1043,7 +1044,7 @@ func (r *AWSMachineReconciler) registerInstanceToV2LB(machineScope *scope.Machin
10431044		return  elb .NewInstanceNotRunning ("instance is not running" )
10441045	}
10451046
1046- 	if  err  :=  elbsvc .RegisterInstanceWithAPIServerLB (instance , lb ); err  !=  nil  {
1047+ 	if  err  :=  elbsvc .RegisterInstanceWithAPIServerLB (ctx ,  instance , lb ); err  !=  nil  {
10471048		r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedAttachControlPlaneELB" ,
10481049			"Failed to register control plane instance %q with load balancer: %v" , instance .ID , err )
10491050		conditions .MarkFalse (machineScope .AWSMachine , infrav1 .ELBAttachedCondition , infrav1 .ELBAttachFailedReason , clusterv1 .ConditionSeverityError , "%s" , err .Error ())
@@ -1055,8 +1056,8 @@ func (r *AWSMachineReconciler) registerInstanceToV2LB(machineScope *scope.Machin
10551056	return  nil 
10561057}
10571058
1058- func  (r  * AWSMachineReconciler ) deregisterInstanceFromClassicLB (machineScope  * scope.MachineScope , elbsvc  services.ELBInterface , instance  * infrav1.Instance ) error  {
1059- 	registered , err  :=  elbsvc .IsInstanceRegisteredWithAPIServerELB (instance )
1059+ func  (r  * AWSMachineReconciler ) deregisterInstanceFromClassicLB (ctx  context. Context ,  machineScope  * scope.MachineScope , elbsvc  services.ELBInterface , instance  * infrav1.Instance ) error  {
1060+ 	registered , err  :=  elbsvc .IsInstanceRegisteredWithAPIServerELB (ctx ,  instance )
10601061	if  err  !=  nil  {
10611062		r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedDetachControlPlaneELB" ,
10621063			"Failed to deregister control plane instance %q from load balancer: failed to determine registration status: %v" , instance .ID , err )
@@ -1067,7 +1068,7 @@ func (r *AWSMachineReconciler) deregisterInstanceFromClassicLB(machineScope *sco
10671068		return  nil 
10681069	}
10691070
1070- 	if  err  :=  elbsvc .DeregisterInstanceFromAPIServerELB (instance ); err  !=  nil  {
1071+ 	if  err  :=  elbsvc .DeregisterInstanceFromAPIServerELB (ctx ,  instance ); err  !=  nil  {
10711072		r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedDetachControlPlaneELB" ,
10721073			"Failed to deregister control plane instance %q from load balancer: %v" , instance .ID , err )
10731074		conditions .MarkFalse (machineScope .AWSMachine , infrav1 .ELBAttachedCondition , infrav1 .ELBDetachFailedReason , clusterv1 .ConditionSeverityError , "%s" , err .Error ())
@@ -1079,8 +1080,8 @@ func (r *AWSMachineReconciler) deregisterInstanceFromClassicLB(machineScope *sco
10791080	return  nil 
10801081}
10811082
1082- func  (r  * AWSMachineReconciler ) deregisterInstanceFromV2LB (machineScope  * scope.MachineScope , elbsvc  services.ELBInterface , i  * infrav1.Instance , lb  * infrav1.AWSLoadBalancerSpec ) error  {
1083- 	targetGroupARNs , registered , err  :=  elbsvc .IsInstanceRegisteredWithAPIServerLB (i , lb )
1083+ func  (r  * AWSMachineReconciler ) deregisterInstanceFromV2LB (ctx  context. Context ,  machineScope  * scope.MachineScope , elbsvc  services.ELBInterface , i  * infrav1.Instance , lb  * infrav1.AWSLoadBalancerSpec ) error  {
1084+ 	targetGroupARNs , registered , err  :=  elbsvc .IsInstanceRegisteredWithAPIServerLB (ctx ,  i , lb )
10841085	if  err  !=  nil  {
10851086		r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedDetachControlPlaneELB" ,
10861087			"Failed to deregister control plane instance %q from load balancer: failed to determine registration status: %v" , i .ID , err )
@@ -1092,7 +1093,7 @@ func (r *AWSMachineReconciler) deregisterInstanceFromV2LB(machineScope *scope.Ma
10921093	}
10931094
10941095	for  _ , targetGroupArn  :=  range  targetGroupARNs  {
1095- 		if  err  :=  elbsvc .DeregisterInstanceFromAPIServerLB (targetGroupArn , i ); err  !=  nil  {
1096+ 		if  err  :=  elbsvc .DeregisterInstanceFromAPIServerLB (ctx ,  targetGroupArn , i ); err  !=  nil  {
10961097			r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedDetachControlPlaneELB" ,
10971098				"Failed to deregister control plane instance %q from load balancer: %v" , i .ID , err )
10981099			conditions .MarkFalse (machineScope .AWSMachine , infrav1 .ELBAttachedCondition , infrav1 .ELBDetachFailedReason , clusterv1 .ConditionSeverityError , "%s" , err .Error ())
@@ -1234,6 +1235,7 @@ func (r *AWSMachineReconciler) getInfraCluster(ctx context.Context, log *logger.
12341235		AWSCluster :                   awsCluster ,
12351236		ControllerName :               "awsmachine" ,
12361237		TagUnmanagedNetworkResources : r .TagUnmanagedNetworkResources ,
1238+ 		MaxWaitActiveUpdateDelete :    r .MaxWaitActiveUpdateDelete ,
12371239	})
12381240	if  err  !=  nil  {
12391241		return  nil , err 
0 commit comments