Skip to content

Commit f21bfca

Browse files
authored
Merge pull request #3207 from pydctw/revert-3073-awscluster-controller-coverage
Revert "Increase unit test coverage for AWSCluster controller"
2 parents 023a977 + bc71efc commit f21bfca

10 files changed

+12
-1012
lines changed

controllers/awscluster_controller.go

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
4242
"sigs.k8s.io/cluster-api-provider-aws/feature"
4343
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/scope"
44-
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services"
4544
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services/ec2"
4645
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services/elb"
4746
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services/instancestate"
@@ -69,45 +68,9 @@ var (
6968
// AWSClusterReconciler reconciles a AwsCluster object.
7069
type AWSClusterReconciler struct {
7170
client.Client
72-
Recorder record.EventRecorder
73-
ec2ServiceFactory func(scope.EC2Scope) services.EC2MachineInterface
74-
networkServiceFactory func(scope.ClusterScope) services.NetworkInterface
75-
elbServiceFactory func(scope.ELBScope) services.ELBInterface
76-
securityGroupFactory func(scope.ClusterScope) services.SecurityGroupInterface
77-
Endpoints []scope.ServiceEndpoint
78-
WatchFilterValue string
79-
}
80-
81-
// getEC2Service factory func is added for testing purpose so that we can inject mocked EC2Service to the AWSClusterReconciler.
82-
func (r *AWSClusterReconciler) getEC2Service(scope scope.EC2Scope) services.EC2MachineInterface {
83-
if r.ec2ServiceFactory != nil {
84-
return r.ec2ServiceFactory(scope)
85-
}
86-
return ec2.NewService(scope)
87-
}
88-
89-
// getELBService factory func is added for testing purpose so that we can inject mocked ELBService to the AWSClusterReconciler.
90-
func (r *AWSClusterReconciler) getELBService(scope scope.ELBScope) services.ELBInterface {
91-
if r.elbServiceFactory != nil {
92-
return r.elbServiceFactory(scope)
93-
}
94-
return elb.NewService(scope)
95-
}
96-
97-
// getNetworkService factory func is added for testing purpose so that we can inject mocked NetworkService to the AWSClusterReconciler.
98-
func (r *AWSClusterReconciler) getNetworkService(scope scope.ClusterScope) services.NetworkInterface {
99-
if r.networkServiceFactory != nil {
100-
return r.networkServiceFactory(scope)
101-
}
102-
return network.NewService(&scope)
103-
}
104-
105-
// getSecurityGroupService factory func is added for testing purpose so that we can inject mocked SecurityGroupService to the AWSClusterReconciler.
106-
func (r *AWSClusterReconciler) getSecurityGroupService(scope scope.ClusterScope) services.SecurityGroupInterface {
107-
if r.securityGroupFactory != nil {
108-
return r.securityGroupFactory(scope)
109-
}
110-
return securitygroup.NewService(&scope, awsSecurityGroupRoles)
71+
Recorder record.EventRecorder
72+
Endpoints []scope.ServiceEndpoint
73+
WatchFilterValue string
11174
}
11275

11376
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=awsclusters,verbs=get;list;watch;create;update;patch;delete
@@ -196,10 +159,10 @@ func (r *AWSClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
196159
func (r *AWSClusterReconciler) reconcileDelete(clusterScope *scope.ClusterScope) (reconcile.Result, error) {
197160
clusterScope.Info("Reconciling AWSCluster delete")
198161

199-
ec2svc := r.getEC2Service(clusterScope)
200-
elbsvc := r.getELBService(clusterScope)
201-
networkSvc := r.getNetworkService(*clusterScope)
202-
sgService := r.getSecurityGroupService(*clusterScope)
162+
ec2svc := ec2.NewService(clusterScope)
163+
elbsvc := elb.NewService(clusterScope)
164+
networkSvc := network.NewService(clusterScope)
165+
sgService := securitygroup.NewService(clusterScope, awsSecurityGroupRoles)
203166

204167
if feature.Gates.Enabled(feature.EventBridgeInstanceState) {
205168
instancestateSvc := instancestate.NewService(clusterScope)
@@ -247,10 +210,10 @@ func (r *AWSClusterReconciler) reconcileNormal(clusterScope *scope.ClusterScope)
247210
return reconcile.Result{}, err
248211
}
249212

250-
ec2Service := r.getEC2Service(clusterScope)
251-
elbService := r.getELBService(clusterScope)
252-
networkSvc := r.getNetworkService(*clusterScope)
253-
sgService := r.getSecurityGroupService(*clusterScope)
213+
ec2Service := ec2.NewService(clusterScope)
214+
elbService := elb.NewService(clusterScope)
215+
networkSvc := network.NewService(clusterScope)
216+
sgService := securitygroup.NewService(clusterScope, awsSecurityGroupRoles)
254217

255218
if err := networkSvc.ReconcileNetwork(); err != nil {
256219
clusterScope.Error(err, "failed to reconcile network")

controllers/awscluster_controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
1617
package controllers
1718

1819
import (

0 commit comments

Comments
 (0)