@@ -48,6 +48,90 @@ func TestReconcileSubnets(t *testing.T) {
48
48
errorExpected bool
49
49
tagUnmanagedNetworkResources bool
50
50
}{
51
+ {
52
+ name : "Unmanaged VPC, disable TagUnmanagedNetworkResources, 2 existing subnets in vpc, 2 subnet in spec, subnets match, with routes, should succeed" ,
53
+ input : NewClusterScope ().WithNetwork (& infrav1.NetworkSpec {
54
+ VPC : infrav1.VPCSpec {
55
+ ID : subnetsVPCID ,
56
+ },
57
+ Subnets : []infrav1.SubnetSpec {
58
+ {
59
+ ID : "subnet-1" ,
60
+ },
61
+ {
62
+ ID : "subnet-2" ,
63
+ },
64
+ },
65
+ }).WithTagUnmanagedNetworkResources (false ),
66
+ expect : func (m * mocks.MockEC2APIMockRecorder ) {
67
+ m .DescribeSubnets (gomock .Eq (& ec2.DescribeSubnetsInput {
68
+ Filters : []* ec2.Filter {
69
+ {
70
+ Name : aws .String ("state" ),
71
+ Values : []* string {aws .String ("pending" ), aws .String ("available" )},
72
+ },
73
+ {
74
+ Name : aws .String ("vpc-id" ),
75
+ Values : []* string {aws .String (subnetsVPCID )},
76
+ },
77
+ },
78
+ })).
79
+ Return (& ec2.DescribeSubnetsOutput {
80
+ Subnets : []* ec2.Subnet {
81
+ {
82
+ VpcId : aws .String (subnetsVPCID ),
83
+ SubnetId : aws .String ("subnet-1" ),
84
+ AvailabilityZone : aws .String ("us-east-1a" ),
85
+ CidrBlock : aws .String ("10.0.10.0/24" ),
86
+ MapPublicIpOnLaunch : aws .Bool (false ),
87
+ },
88
+ {
89
+ VpcId : aws .String (subnetsVPCID ),
90
+ SubnetId : aws .String ("subnet-2" ),
91
+ AvailabilityZone : aws .String ("us-east-1a" ),
92
+ CidrBlock : aws .String ("10.0.20.0/24" ),
93
+ MapPublicIpOnLaunch : aws .Bool (false ),
94
+ },
95
+ },
96
+ }, nil )
97
+
98
+ m .DescribeRouteTables (gomock .AssignableToTypeOf (& ec2.DescribeRouteTablesInput {})).
99
+ Return (& ec2.DescribeRouteTablesOutput {
100
+ RouteTables : []* ec2.RouteTable {
101
+ {
102
+ VpcId : aws .String (subnetsVPCID ),
103
+ Associations : []* ec2.RouteTableAssociation {
104
+ {
105
+ SubnetId : aws .String ("subnet-1" ),
106
+ RouteTableId : aws .String ("rt-12345" ),
107
+ },
108
+ },
109
+ Routes : []* ec2.Route {
110
+ {
111
+ GatewayId : aws .String ("igw-12345" ),
112
+ },
113
+ },
114
+ },
115
+ },
116
+ }, nil )
117
+
118
+ m .DescribeNatGatewaysPages (
119
+ gomock .Eq (& ec2.DescribeNatGatewaysInput {
120
+ Filter : []* ec2.Filter {
121
+ {
122
+ Name : aws .String ("vpc-id" ),
123
+ Values : []* string {aws .String (subnetsVPCID )},
124
+ },
125
+ {
126
+ Name : aws .String ("state" ),
127
+ Values : []* string {aws .String ("pending" ), aws .String ("available" )},
128
+ },
129
+ },
130
+ }),
131
+ gomock .Any ()).Return (nil )
132
+ },
133
+ tagUnmanagedNetworkResources : false ,
134
+ },
51
135
{
52
136
name : "Unmanaged VPC, 2 existing subnets in vpc, 2 subnet in spec, subnets match, with routes, should succeed" ,
53
137
input : NewClusterScope ().WithNetwork (& infrav1.NetworkSpec {
@@ -62,7 +146,7 @@ func TestReconcileSubnets(t *testing.T) {
62
146
ID : "subnet-2" ,
63
147
},
64
148
},
65
- }),
149
+ }). WithTagUnmanagedNetworkResources ( true ) ,
66
150
expect : func (m * mocks.MockEC2APIMockRecorder ) {
67
151
m .DescribeSubnets (gomock .Eq (& ec2.DescribeSubnetsInput {
68
152
Filters : []* ec2.Filter {
@@ -160,6 +244,7 @@ func TestReconcileSubnets(t *testing.T) {
160
244
})).
161
245
Return (& ec2.CreateTagsOutput {}, nil )
162
246
},
247
+ tagUnmanagedNetworkResources : true ,
163
248
},
164
249
{
165
250
name : "IPv6 enabled vpc with default subnets should succeed" ,
@@ -179,7 +264,7 @@ func TestReconcileSubnets(t *testing.T) {
179
264
IPv6CidrBlock : "2001:db8:1234:1a02::/64" ,
180
265
},
181
266
},
182
- }),
267
+ }). WithTagUnmanagedNetworkResources ( true ) ,
183
268
expect : func (m * mocks.MockEC2APIMockRecorder ) {
184
269
m .DescribeSubnets (gomock .Eq (& ec2.DescribeSubnetsInput {
185
270
Filters : []* ec2.Filter {
@@ -297,6 +382,7 @@ func TestReconcileSubnets(t *testing.T) {
297
382
})).
298
383
Return (& ec2.CreateTagsOutput {}, nil )
299
384
},
385
+ tagUnmanagedNetworkResources : true ,
300
386
},
301
387
{
302
388
name : "Unmanaged VPC, 2 existing subnets in vpc, 2 subnet in spec, subnets match, no routes, should succeed" ,
@@ -313,7 +399,7 @@ func TestReconcileSubnets(t *testing.T) {
313
399
ID : "subnet-2" ,
314
400
},
315
401
},
316
- }),
402
+ }). WithTagUnmanagedNetworkResources ( true ) ,
317
403
expect : func (m * mocks.MockEC2APIMockRecorder ) {
318
404
m .DescribeSubnets (gomock .Eq (& ec2.DescribeSubnetsInput {
319
405
Filters : []* ec2.Filter {
@@ -394,7 +480,8 @@ func TestReconcileSubnets(t *testing.T) {
394
480
})).
395
481
Return (& ec2.CreateTagsOutput {}, nil )
396
482
},
397
- errorExpected : false ,
483
+ errorExpected : false ,
484
+ tagUnmanagedNetworkResources : true ,
398
485
},
399
486
{
400
487
name : "Unmanaged VPC, 2 existing matching subnets, subnet tagging fails, should succeed" ,
@@ -410,7 +497,7 @@ func TestReconcileSubnets(t *testing.T) {
410
497
ID : "subnet-2" ,
411
498
},
412
499
},
413
- }),
500
+ }). WithTagUnmanagedNetworkResources ( true ) ,
414
501
expect : func (m * mocks.MockEC2APIMockRecorder ) {
415
502
m .DescribeSubnets (gomock .Eq (& ec2.DescribeSubnetsInput {
416
503
Filters : []* ec2.Filter {
@@ -493,6 +580,7 @@ func TestReconcileSubnets(t *testing.T) {
493
580
})).
494
581
Return (& ec2.CreateTagsOutput {}, fmt .Errorf ("tagging failed" ))
495
582
},
583
+ tagUnmanagedNetworkResources : true ,
496
584
},
497
585
{
498
586
name : "Unmanaged VPC, 2 existing subnets in vpc, 0 subnet in spec, should fail" ,
@@ -573,7 +661,7 @@ func TestReconcileSubnets(t *testing.T) {
573
661
IsPublic : true ,
574
662
},
575
663
},
576
- }),
664
+ }). WithTagUnmanagedNetworkResources ( true ) ,
577
665
expect : func (m * mocks.MockEC2APIMockRecorder ) {
578
666
m .DescribeSubnets (gomock .Eq (& ec2.DescribeSubnetsInput {
579
667
Filters : []* ec2.Filter {
@@ -607,7 +695,8 @@ func TestReconcileSubnets(t *testing.T) {
607
695
}),
608
696
gomock .Any ()).Return (nil )
609
697
},
610
- errorExpected : true ,
698
+ errorExpected : true ,
699
+ tagUnmanagedNetworkResources : true ,
611
700
},
612
701
{
613
702
name : "Unmanaged VPC, 2 subnets exist, 2 private subnet in spec, should succeed" ,
@@ -627,7 +716,7 @@ func TestReconcileSubnets(t *testing.T) {
627
716
IsPublic : false ,
628
717
},
629
718
},
630
- }),
719
+ }). WithTagUnmanagedNetworkResources ( true ) ,
631
720
expect : func (m * mocks.MockEC2APIMockRecorder ) {
632
721
m .DescribeSubnets (gomock .Eq (& ec2.DescribeSubnetsInput {
633
722
Filters : []* ec2.Filter {
@@ -708,7 +797,8 @@ func TestReconcileSubnets(t *testing.T) {
708
797
})).
709
798
Return (& ec2.CreateTagsOutput {}, nil )
710
799
},
711
- errorExpected : false ,
800
+ errorExpected : false ,
801
+ tagUnmanagedNetworkResources : true ,
712
802
},
713
803
{
714
804
name : "Managed VPC, no subnets exist, 1 private and 1 public subnet in spec, create both" ,
0 commit comments