Skip to content

Commit 99e14b5

Browse files
committed
Migrate elb to AWS SDK v2
1 parent ffa284d commit 99e14b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2131
-5750
lines changed

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ LDFLAGS := $(shell source ./hack/version.sh; version::ldflags)
143143
# Set USE_EXISTING_CLUSTER to use an existing kubernetes context
144144
USE_EXISTING_CLUSTER ?= "false"
145145

146+
# GORELEASER_PARALLELISM restricts the number of tasks goreleaser will run
147+
# concurrently. The primary reason to do this is to ensure its memory usage
148+
# remains within the resource limits of the
149+
# cluster-api-provider-aws-build-docker job
150+
GORELEASER_PARALLELISM ?= 2
151+
146152
# Set E2E_SKIP_EKS_UPGRADE to false to test EKS upgrades.
147153
# Warning, this takes a long time
148154
E2E_SKIP_EKS_UPGRADE ?= "false"
@@ -571,7 +577,7 @@ release: clean-release check-release-tag check-release-branch $(RELEASE_DIR) $(G
571577
$(MAKE) release-changelog
572578
CORE_CONTROLLER_IMG=$(PROD_REGISTRY)/$(CORE_IMAGE_NAME) $(MAKE) release-manifests
573579
$(MAKE) release-policies
574-
$(GORELEASER) release --config $(GORELEASER_CONFIG) --release-notes $(RELEASE_DIR)/CHANGELOG.md --clean
580+
$(GORELEASER) release --config $(GORELEASER_CONFIG) --release-notes $(RELEASE_DIR)/CHANGELOG.md --clean --parallelism $(GORELEASER_PARALLELISM)
575581

576582
release-policies: $(RELEASE_POLICIES) ## Release policies
577583

@@ -606,7 +612,7 @@ promote-images: $(KPROMO) $(YQ)
606612

607613
.PHONY: release-binaries
608614
release-binaries: $(GORELEASER) ## Builds only the binaries, not a release.
609-
GOMAXPROCS=2 $(GORELEASER) build --config $(GORELEASER_CONFIG) --snapshot --clean
615+
$(GORELEASER) build --config $(GORELEASER_CONFIG) --snapshot --clean --parallelism $(GORELEASER_PARALLELISM)
610616

611617
.PHONY: release-staging
612618
release-staging: ## Builds and push container images and manifests to the staging bucket.

controllers/awscluster_controller.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type AWSClusterReconciler struct {
8080
ExternalResourceGC bool
8181
AlternativeGCStrategy bool
8282
TagUnmanagedNetworkResources bool
83+
MaxWaitActiveUpdateDelete time.Duration
8384
}
8485

8586
// getEC2Service factory func is added for testing purpose so that we can inject mocked EC2Service to the AWSClusterReconciler.
@@ -178,6 +179,7 @@ func (r *AWSClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
178179
ControllerName: "awscluster",
179180
Endpoints: r.Endpoints,
180181
TagUnmanagedNetworkResources: r.TagUnmanagedNetworkResources,
182+
MaxWaitActiveUpdateDelete: r.MaxWaitActiveUpdateDelete,
181183
})
182184
if err != nil {
183185
return reconcile.Result{}, errors.Errorf("failed to create scope: %+v", err)
@@ -247,7 +249,7 @@ func (r *AWSClusterReconciler) reconcileDelete(ctx context.Context, clusterScope
247249
allErrs = append(allErrs, errors.Wrapf(err, "error deleting S3 Bucket"))
248250
}
249251

250-
if err := elbsvc.DeleteLoadbalancers(); err != nil {
252+
if err := elbsvc.DeleteLoadbalancers(ctx); err != nil {
251253
allErrs = append(allErrs, errors.Wrapf(err, "error deleting load balancers"))
252254
}
253255

@@ -279,7 +281,7 @@ func (r *AWSClusterReconciler) reconcileDelete(ctx context.Context, clusterScope
279281
return reconcile.Result{}, nil
280282
}
281283

282-
func (r *AWSClusterReconciler) reconcileLoadBalancer(clusterScope *scope.ClusterScope, awsCluster *infrav1.AWSCluster) (*time.Duration, error) {
284+
func (r *AWSClusterReconciler) reconcileLoadBalancer(ctx context.Context, clusterScope *scope.ClusterScope, awsCluster *infrav1.AWSCluster) (*time.Duration, error) {
283285
retryAfterDuration := 15 * time.Second
284286
if clusterScope.AWSCluster.Spec.ControlPlaneLoadBalancer.LoadBalancerType == infrav1.LoadBalancerTypeDisabled {
285287
clusterScope.Debug("load balancer reconciliation shifted to external provider, checking external endpoint")
@@ -289,7 +291,7 @@ func (r *AWSClusterReconciler) reconcileLoadBalancer(clusterScope *scope.Cluster
289291

290292
elbService := r.getELBService(clusterScope)
291293

292-
if err := elbService.ReconcileLoadbalancers(); err != nil {
294+
if err := elbService.ReconcileLoadbalancers(ctx); err != nil {
293295
clusterScope.Error(err, "failed to reconcile load balancer")
294296
conditions.MarkFalse(awsCluster, infrav1.LoadBalancerReadyCondition, infrav1.LoadBalancerFailedReason, infrautilconditions.ErrorConditionAfterInit(clusterScope.ClusterObj()), "%s", err.Error())
295297
return nil, err
@@ -354,7 +356,7 @@ func (r *AWSClusterReconciler) reconcileNormal(ctx context.Context, clusterScope
354356
}
355357
}
356358

357-
if requeueAfter, err := r.reconcileLoadBalancer(clusterScope, awsCluster); err != nil {
359+
if requeueAfter, err := r.reconcileLoadBalancer(ctx, clusterScope, awsCluster); err != nil {
358360
return reconcile.Result{}, err
359361
} else if requeueAfter != nil {
360362
return reconcile.Result{RequeueAfter: *requeueAfter}, err

controllers/awscluster_controller_test.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import (
2121
"testing"
2222
"time"
2323

24-
"github.com/aws/aws-sdk-go/aws"
24+
"github.com/aws/aws-sdk-go-v2/aws"
25+
elb "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing"
26+
elbtypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types"
2527
"github.com/aws/aws-sdk-go/service/ec2"
26-
"github.com/aws/aws-sdk-go/service/elb"
2728
"github.com/golang/mock/gomock"
2829
. "github.com/onsi/gomega"
2930
"github.com/pkg/errors"
@@ -1379,26 +1380,26 @@ func mockedCallsForMissingEverything(m *mocks.MockEC2APIMockRecorder, e *mocks.M
13791380
SubnetId: aws.String("subnet-2"),
13801381
})).Return(&ec2.AssociateRouteTableOutput{}, nil)
13811382

1382-
e.DescribeLoadBalancers(gomock.Eq(&elb.DescribeLoadBalancersInput{
1383-
LoadBalancerNames: aws.StringSlice([]string{"test-cluster-apiserver"}),
1383+
e.DescribeLoadBalancers(gomock.Any(), gomock.Eq(&elb.DescribeLoadBalancersInput{
1384+
LoadBalancerNames: []string{"test-cluster-apiserver"},
13841385
})).Return(&elb.DescribeLoadBalancersOutput{
1385-
LoadBalancerDescriptions: []*elb.LoadBalancerDescription{},
1386+
LoadBalancerDescriptions: []elbtypes.LoadBalancerDescription{},
13861387
}, nil)
13871388

1388-
e.CreateLoadBalancer(gomock.Eq(&elb.CreateLoadBalancerInput{
1389-
Listeners: []*elb.Listener{
1389+
e.CreateLoadBalancer(gomock.Any(), gomock.Eq(&elb.CreateLoadBalancerInput{
1390+
Listeners: []elbtypes.Listener{
13901391
{
1391-
InstancePort: aws.Int64(6443),
1392+
InstancePort: aws.Int32(6443),
13921393
InstanceProtocol: aws.String("TCP"),
1393-
LoadBalancerPort: aws.Int64(6443),
1394+
LoadBalancerPort: 6443,
13941395
Protocol: aws.String("TCP"),
13951396
},
13961397
},
13971398
LoadBalancerName: aws.String("test-cluster-apiserver"),
13981399
Scheme: aws.String("internet-facing"),
1399-
SecurityGroups: aws.StringSlice([]string{"sg-apiserver-lb"}),
1400-
Subnets: aws.StringSlice([]string{"subnet-2"}),
1401-
Tags: []*elb.Tag{
1400+
SecurityGroups: []string{"sg-apiserver-lb"},
1401+
Subnets: []string{"subnet-2"},
1402+
Tags: []elbtypes.Tag{
14021403
{
14031404
Key: aws.String("Name"),
14041405
Value: aws.String("test-cluster-apiserver"),
@@ -1416,14 +1417,14 @@ func mockedCallsForMissingEverything(m *mocks.MockEC2APIMockRecorder, e *mocks.M
14161417
DNSName: aws.String("unittest24.de"),
14171418
}, nil)
14181419

1419-
e.ConfigureHealthCheck(gomock.Eq(&elb.ConfigureHealthCheckInput{
1420+
e.ConfigureHealthCheck(gomock.Any(), gomock.Eq(&elb.ConfigureHealthCheckInput{
14201421
LoadBalancerName: aws.String("test-cluster-apiserver"),
1421-
HealthCheck: &elb.HealthCheck{
1422+
HealthCheck: &elbtypes.HealthCheck{
14221423
Target: aws.String("TCP:6443"),
1423-
Interval: aws.Int64(10),
1424-
Timeout: aws.Int64(5),
1425-
HealthyThreshold: aws.Int64(5),
1426-
UnhealthyThreshold: aws.Int64(3),
1424+
Interval: aws.Int32(10),
1425+
Timeout: aws.Int32(5),
1426+
HealthyThreshold: aws.Int32(5),
1427+
UnhealthyThreshold: aws.Int32(3),
14271428
},
14281429
})).Return(&elb.ConfigureHealthCheckOutput{}, nil)
14291430
}

controllers/awscluster_controller_unit_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
196196
g := NewWithT(t)
197197
runningCluster := func() {
198198
ec2Svc.EXPECT().ReconcileBastion().Return(nil)
199-
elbSvc.EXPECT().ReconcileLoadbalancers().Return(nil)
199+
elbSvc.EXPECT().ReconcileLoadbalancers(gomock.Any()).Return(nil)
200200
networkSvc.EXPECT().ReconcileNetwork().Return(nil)
201201
sgSvc.EXPECT().ReconcileSecurityGroups().Return(nil)
202202
}
@@ -252,7 +252,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
252252
g := NewWithT(t)
253253
runningCluster := func() {
254254
ec2Svc.EXPECT().ReconcileBastion().Return(nil)
255-
elbSvc.EXPECT().ReconcileLoadbalancers().Return(nil)
255+
elbSvc.EXPECT().ReconcileLoadbalancers(gomock.Any()).Return(nil)
256256
networkSvc.EXPECT().ReconcileNetwork().Return(nil)
257257
sgSvc.EXPECT().ReconcileSecurityGroups().Return(nil)
258258
}
@@ -352,7 +352,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
352352
networkSvc.EXPECT().ReconcileNetwork().Return(nil)
353353
sgSvc.EXPECT().ReconcileSecurityGroups().Return(nil)
354354
ec2Svc.EXPECT().ReconcileBastion().Return(nil)
355-
elbSvc.EXPECT().ReconcileLoadbalancers().Return(expectedErr)
355+
elbSvc.EXPECT().ReconcileLoadbalancers(gomock.Any()).Return(expectedErr)
356356
}
357357
csClient := setup(t, &awsCluster)
358358
defer teardown()
@@ -376,7 +376,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
376376
networkSvc.EXPECT().ReconcileNetwork().Return(nil)
377377
sgSvc.EXPECT().ReconcileSecurityGroups().Return(nil)
378378
ec2Svc.EXPECT().ReconcileBastion().Return(nil)
379-
elbSvc.EXPECT().ReconcileLoadbalancers().Return(nil)
379+
elbSvc.EXPECT().ReconcileLoadbalancers(gomock.Any()).Return(nil)
380380
}
381381
csClient := setup(t, &awsCluster)
382382
defer teardown()
@@ -399,7 +399,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
399399
t.Run("Reconcile success", func(t *testing.T) {
400400
deleteCluster := func() {
401401
ec2Svc.EXPECT().DeleteBastion().Return(nil)
402-
elbSvc.EXPECT().DeleteLoadbalancers().Return(nil)
402+
elbSvc.EXPECT().DeleteLoadbalancers(gomock.Any()).Return(nil)
403403
networkSvc.EXPECT().DeleteNetwork().Return(nil)
404404
sgSvc.EXPECT().DeleteSecurityGroups().Return(nil)
405405
}
@@ -429,7 +429,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
429429
g := NewWithT(t)
430430
deleteCluster := func() {
431431
t.Helper()
432-
elbSvc.EXPECT().DeleteLoadbalancers().Return(expectedErr)
432+
elbSvc.EXPECT().DeleteLoadbalancers(gomock.Any()).Return(expectedErr)
433433
ec2Svc.EXPECT().DeleteBastion().Return(nil)
434434
networkSvc.EXPECT().DeleteNetwork().Return(nil)
435435
sgSvc.EXPECT().DeleteSecurityGroups().Return(nil)
@@ -455,7 +455,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
455455
g := NewWithT(t)
456456
deleteCluster := func() {
457457
ec2Svc.EXPECT().DeleteBastion().Return(expectedErr)
458-
elbSvc.EXPECT().DeleteLoadbalancers().Return(nil)
458+
elbSvc.EXPECT().DeleteLoadbalancers(gomock.Any()).Return(nil)
459459
networkSvc.EXPECT().DeleteNetwork().Return(nil)
460460
sgSvc.EXPECT().DeleteSecurityGroups().Return(nil)
461461
}
@@ -480,7 +480,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
480480
g := NewWithT(t)
481481
deleteCluster := func() {
482482
ec2Svc.EXPECT().DeleteBastion().Return(nil)
483-
elbSvc.EXPECT().DeleteLoadbalancers().Return(nil)
483+
elbSvc.EXPECT().DeleteLoadbalancers(gomock.Any()).Return(nil)
484484
sgSvc.EXPECT().DeleteSecurityGroups().Return(expectedErr)
485485
networkSvc.EXPECT().DeleteNetwork().Return(nil)
486486
}
@@ -505,7 +505,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
505505
g := NewWithT(t)
506506
deleteCluster := func() {
507507
ec2Svc.EXPECT().DeleteBastion().Return(nil)
508-
elbSvc.EXPECT().DeleteLoadbalancers().Return(nil)
508+
elbSvc.EXPECT().DeleteLoadbalancers(gomock.Any()).Return(nil)
509509
sgSvc.EXPECT().DeleteSecurityGroups().Return(nil)
510510
networkSvc.EXPECT().DeleteNetwork().Return(expectedErr)
511511
}

0 commit comments

Comments
 (0)