@@ -29,6 +29,7 @@ import (
29
29
30
30
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
31
31
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
32
+ "sigs.k8s.io/cluster-api-provider-aws/v2/test/helpers"
32
33
"sigs.k8s.io/cluster-api-provider-aws/v2/test/mocks"
33
34
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
34
35
"sigs.k8s.io/cluster-api/util/conditions"
@@ -39,6 +40,7 @@ const DNSName = "www.google.com"
39
40
var (
40
41
lbName = aws .String ("test-cluster-apiserver" )
41
42
lbArn = aws .String ("loadbalancer::arn" )
43
+ tgArn = aws .String ("arn::target-group" )
42
44
describeLBInput = & elb.DescribeLoadBalancersInput {
43
45
LoadBalancerNames : aws .StringSlice ([]string {"test-cluster-apiserver" }),
44
46
}
@@ -291,6 +293,157 @@ func mockedCreateLBV2Calls(t *testing.T, m *mocks.MockELBV2APIMockRecorder) {
291
293
})).MaxTimes (1 )
292
294
}
293
295
296
+ func mockedDescribeTargetGroupsCall (t * testing.T , m * mocks.MockELBV2APIMockRecorder ) {
297
+ t .Helper ()
298
+ m .DescribeTargetGroups (gomock .Eq (& elbv2.DescribeTargetGroupsInput {
299
+ LoadBalancerArn : lbArn ,
300
+ })).
301
+ Return (& elbv2.DescribeTargetGroupsOutput {
302
+ NextMarker : new (string ),
303
+ TargetGroups : []* elbv2.TargetGroup {
304
+ {
305
+ HealthCheckEnabled : aws .Bool (true ),
306
+ HealthCheckIntervalSeconds : new (int64 ),
307
+ HealthCheckPath : new (string ),
308
+ HealthCheckPort : new (string ),
309
+ HealthCheckProtocol : new (string ),
310
+ HealthCheckTimeoutSeconds : new (int64 ),
311
+ HealthyThresholdCount : new (int64 ),
312
+ IpAddressType : new (string ),
313
+ LoadBalancerArns : []* string {lbArn },
314
+ Matcher : & elbv2.Matcher {},
315
+ Port : new (int64 ),
316
+ Protocol : new (string ),
317
+ ProtocolVersion : new (string ),
318
+ TargetGroupArn : tgArn ,
319
+ TargetGroupName : new (string ),
320
+ TargetType : new (string ),
321
+ UnhealthyThresholdCount : new (int64 ),
322
+ VpcId : new (string ),
323
+ }},
324
+ }, nil )
325
+ }
326
+
327
+ func mockedCreateTargetGroupCall (t * testing.T , m * mocks.MockELBV2APIMockRecorder ) {
328
+ t .Helper ()
329
+ m .CreateTargetGroup (helpers .PartialMatchCreateTargetGroupInput (t , & elbv2.CreateTargetGroupInput {
330
+ HealthCheckEnabled : aws .Bool (true ),
331
+ HealthCheckIntervalSeconds : aws .Int64 (infrav1 .DefaultAPIServerHealthCheckIntervalSec ),
332
+ HealthCheckPort : aws .String (infrav1 .DefaultAPIServerPortString ),
333
+ HealthCheckProtocol : aws .String ("TCP" ),
334
+ HealthCheckTimeoutSeconds : aws .Int64 (infrav1 .DefaultAPIServerHealthCheckTimeoutSec ),
335
+ HealthyThresholdCount : aws .Int64 (infrav1 .DefaultAPIServerHealthThresholdCount ),
336
+ // Note: this is treated as a prefix with the partial matcher.
337
+ Name : aws .String ("apiserver-target" ),
338
+ Port : aws .Int64 (infrav1 .DefaultAPIServerPort ),
339
+ Protocol : aws .String ("TCP" ),
340
+ Tags : []* elbv2.Tag {
341
+ {
342
+ Key : aws .String ("Name" ),
343
+ Value : aws .String ("bar-apiserver" ),
344
+ },
345
+ {
346
+ Key : aws .String ("sigs.k8s.io/cluster-api-provider-aws/cluster/test-cluster" ),
347
+ Value : aws .String ("owned" ),
348
+ },
349
+ {
350
+ Key : aws .String ("sigs.k8s.io/cluster-api-provider-aws/role" ),
351
+ Value : aws .String ("apiserver" ),
352
+ },
353
+ },
354
+ UnhealthyThresholdCount : aws .Int64 (infrav1 .DefaultAPIServerUnhealthThresholdCount ),
355
+ VpcId : aws .String ("vpc-exists" ),
356
+ })).Return (& elbv2.CreateTargetGroupOutput {
357
+ TargetGroups : []* elbv2.TargetGroup {{
358
+ HealthCheckEnabled : aws .Bool (true ),
359
+ HealthCheckIntervalSeconds : aws .Int64 (infrav1 .DefaultAPIServerHealthCheckIntervalSec ),
360
+ HealthCheckPort : aws .String (infrav1 .DefaultAPIServerPortString ),
361
+ HealthCheckProtocol : aws .String ("TCP" ),
362
+ HealthCheckTimeoutSeconds : aws .Int64 (infrav1 .DefaultAPIServerHealthCheckTimeoutSec ),
363
+ HealthyThresholdCount : aws .Int64 (infrav1 .DefaultAPIServerHealthThresholdCount ),
364
+ LoadBalancerArns : []* string {lbArn },
365
+ Matcher : & elbv2.Matcher {},
366
+ Port : aws .Int64 (infrav1 .DefaultAPIServerPort ),
367
+ Protocol : aws .String ("TCP" ),
368
+ TargetGroupArn : tgArn ,
369
+ TargetGroupName : aws .String ("apiserver-target" ),
370
+ UnhealthyThresholdCount : aws .Int64 (infrav1 .DefaultAPIServerUnhealthThresholdCount ),
371
+ VpcId : aws .String ("vpc-exists" ),
372
+ }},
373
+ }, nil )
374
+ }
375
+
376
+ func mockedModifyTargetGroupAttributes (t * testing.T , m * mocks.MockELBV2APIMockRecorder ) {
377
+ t .Helper ()
378
+ m .ModifyTargetGroupAttributes (gomock .Eq (& elbv2.ModifyTargetGroupAttributesInput {
379
+ TargetGroupArn : tgArn ,
380
+ Attributes : []* elbv2.TargetGroupAttribute {
381
+ {
382
+ Key : aws .String (infrav1 .TargetGroupAttributeEnablePreserveClientIP ),
383
+ Value : aws .String ("false" ),
384
+ },
385
+ },
386
+ })).Return (nil , nil )
387
+ }
388
+
389
+ func mockedDescribeListenersCall (t * testing.T , m * mocks.MockELBV2APIMockRecorder ) {
390
+ t .Helper ()
391
+ m .DescribeListeners (gomock .Eq (& elbv2.DescribeListenersInput {
392
+ LoadBalancerArn : lbArn ,
393
+ })).
394
+ Return (& elbv2.DescribeListenersOutput {
395
+ Listeners : []* elbv2.Listener {{
396
+ DefaultActions : []* elbv2.Action {{
397
+ TargetGroupArn : aws .String ("arn::targetgroup-not-found" ),
398
+ }},
399
+ ListenerArn : aws .String ("arn::listener" ),
400
+ LoadBalancerArn : lbArn ,
401
+ }},
402
+ }, nil )
403
+ }
404
+
405
+ func mockedCreateListenerCall (t * testing.T , m * mocks.MockELBV2APIMockRecorder ) {
406
+ t .Helper ()
407
+ m .CreateListener (gomock .Eq (& elbv2.CreateListenerInput {
408
+ DefaultActions : []* elbv2.Action {
409
+ {
410
+ TargetGroupArn : tgArn ,
411
+ Type : aws .String (elbv2 .ActionTypeEnumForward ),
412
+ },
413
+ },
414
+ LoadBalancerArn : lbArn ,
415
+ Port : aws .Int64 (infrav1 .DefaultAPIServerPort ),
416
+ Protocol : aws .String ("TCP" ),
417
+ Tags : []* elbv2.Tag {
418
+ {
419
+ Key : aws .String ("Name" ),
420
+ Value : aws .String ("test-cluster-apiserver" ),
421
+ },
422
+ {
423
+ Key : aws .String ("sigs.k8s.io/cluster-api-provider-aws/cluster/test-cluster" ),
424
+ Value : aws .String ("owned" ),
425
+ },
426
+ {
427
+ Key : aws .String ("sigs.k8s.io/cluster-api-provider-aws/role" ),
428
+ Value : aws .String ("apiserver" ),
429
+ },
430
+ },
431
+ })).Return (& elbv2.CreateListenerOutput {
432
+ Listeners : []* elbv2.Listener {
433
+ {
434
+ DefaultActions : []* elbv2.Action {
435
+ {
436
+ TargetGroupArn : tgArn ,
437
+ Type : aws .String (elbv2 .ActionTypeEnumForward ),
438
+ },
439
+ },
440
+ ListenerArn : aws .String ("listener::arn" ),
441
+ Port : aws .Int64 (infrav1 .DefaultAPIServerPort ),
442
+ Protocol : aws .String ("TCP" ),
443
+ },
444
+ }}, nil )
445
+ }
446
+
294
447
func mockedDeleteLBCalls (expectV2Call bool , mv2 * mocks.MockELBV2APIMockRecorder , m * mocks.MockELBAPIMockRecorder ) {
295
448
if expectV2Call {
296
449
mv2 .DescribeLoadBalancers (gomock .Any ()).Return (describeLBOutputV2 , nil )
0 commit comments