@@ -66,7 +66,8 @@ type AWSMachineReconciler struct {
66
66
client.Client
67
67
Log logr.Logger
68
68
Recorder record.EventRecorder
69
- ec2ServiceFactory func (scope.EC2Scope ) services.EC2MachineInterface
69
+ ec2ServiceFactory func (scope.EC2Scope ) services.EC2Interface
70
+ elbServiceFactory func (scope.ELBScope ) services.ELBInterface
70
71
secretsManagerServiceFactory func (cloud.ClusterScoper ) services.SecretInterface
71
72
SSMServiceFactory func (cloud.ClusterScoper ) services.SecretInterface
72
73
Endpoints []scope.ServiceEndpoint
@@ -78,7 +79,7 @@ const (
78
79
AWSManagedControlPlaneRefKind = "AWSManagedControlPlane"
79
80
)
80
81
81
- func (r * AWSMachineReconciler ) getEC2Service (scope scope.EC2Scope ) services.EC2MachineInterface {
82
+ func (r * AWSMachineReconciler ) getEC2Service (scope scope.EC2Scope ) services.EC2Interface {
82
83
if r .ec2ServiceFactory != nil {
83
84
return r .ec2ServiceFactory (scope )
84
85
}
@@ -111,6 +112,14 @@ func (r *AWSMachineReconciler) getSecretService(machineScope *scope.MachineScope
111
112
return nil , errors .New ("invalid secret backend" )
112
113
}
113
114
115
+ func (r * AWSMachineReconciler ) getELBService (scope scope.ELBScope ) services.ELBInterface {
116
+ if r .elbServiceFactory != nil {
117
+ return r .elbServiceFactory (scope )
118
+ }
119
+
120
+ return elb .NewService (scope )
121
+ }
122
+
114
123
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsmachines,verbs=get;list;watch;create;update;patch;delete
115
124
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsmachines/status,verbs=get;update;patch
116
125
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=machines;machines/status,verbs=get;list;watch
@@ -382,7 +391,7 @@ func (r *AWSMachineReconciler) reconcileDelete(machineScope *scope.MachineScope,
382
391
// findInstance queries the EC2 apis and retrieves the instance if it exists.
383
392
// If providerID is empty, finds instance by tags and if it cannot be found, returns empty instance with nil error.
384
393
// If providerID is set, either finds the instance by ID or returns error.
385
- func (r * AWSMachineReconciler ) findInstance (scope * scope.MachineScope , ec2svc services.EC2MachineInterface ) (* infrav1.Instance , error ) {
394
+ func (r * AWSMachineReconciler ) findInstance (scope * scope.MachineScope , ec2svc services.EC2Interface ) (* infrav1.Instance , error ) {
386
395
var instance * infrav1.Instance
387
396
388
397
// Parse the ProviderID.
@@ -525,7 +534,7 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
525
534
}
526
535
527
536
// reconcile the deletion of the bootstrap data secret now that we have updated instance state
528
- if deleteSecretErr := r .deleteEncryptedBootstrapDataSecret (machineScope , clusterScope ); err != nil {
537
+ if deleteSecretErr := r .deleteEncryptedBootstrapDataSecret (machineScope , clusterScope ); deleteSecretErr != nil {
529
538
r .Log .Error (deleteSecretErr , "unable to delete secrets" )
530
539
return ctrl.Result {}, deleteSecretErr
531
540
}
@@ -613,7 +622,7 @@ func (r *AWSMachineReconciler) deleteEncryptedBootstrapDataSecret(machineScope *
613
622
return nil
614
623
}
615
624
616
- func (r * AWSMachineReconciler ) createInstance (ec2svc services.EC2MachineInterface , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper ) (* infrav1.Instance , error ) {
625
+ func (r * AWSMachineReconciler ) createInstance (ec2svc services.EC2Interface , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper ) (* infrav1.Instance , error ) {
617
626
machineScope .Info ("Creating EC2 instance" )
618
627
619
628
userData , userDataErr := r .resolveUserData (machineScope , clusterScope )
@@ -678,7 +687,7 @@ func (r *AWSMachineReconciler) reconcileLBAttachment(machineScope *scope.Machine
678
687
return nil
679
688
}
680
689
681
- elbsvc := elb . NewService (clusterScope )
690
+ elbsvc := r . getELBService (clusterScope )
682
691
683
692
// In order to prevent sending request to a "not-ready" control plane machines, it is required to remove the machine
684
693
// from the ELB as soon as the machine gets deleted or when the machine is in a not running state.
@@ -877,7 +886,7 @@ func (r *AWSMachineReconciler) indexAWSMachineByInstanceID(o client.Object) []st
877
886
return nil
878
887
}
879
888
880
- func (r * AWSMachineReconciler ) ensureStorageTags (ec2svc services.EC2MachineInterface , instance * infrav1.Instance , machine * infrav1.AWSMachine ) {
889
+ func (r * AWSMachineReconciler ) ensureStorageTags (ec2svc services.EC2Interface , instance * infrav1.Instance , machine * infrav1.AWSMachine ) {
881
890
annotations , err := r .machineAnnotationJSON (machine , VolumeTagsLastAppliedAnnotation )
882
891
if err != nil {
883
892
r .Log .Error (err , "Failed to fetch the annotations for volume tags" )
0 commit comments