@@ -243,6 +243,7 @@ func TestServiceDiassociateSecondaryCidr(t *testing.T) {
243
243
tests := []struct {
244
244
name string
245
245
fillAWSManagedControlPlaneSecondaryCIDR bool
246
+ unmanagedVPC bool
246
247
networkSecondaryCIDRBlocks []infrav1.VpcCidrBlock
247
248
expect func (m * mocks.MockEC2APIMockRecorder )
248
249
wantErr bool
@@ -289,7 +290,7 @@ func TestServiceDiassociateSecondaryCidr(t *testing.T) {
289
290
},
290
291
},
291
292
{
292
- name : "Should return error if failed to diassociate secondary cidr block" ,
293
+ name : "Should return error if failed to disassociate secondary cidr block" ,
293
294
fillAWSManagedControlPlaneSecondaryCIDR : true ,
294
295
expect : func (m * mocks.MockEC2APIMockRecorder ) {
295
296
m .DescribeVpcsWithContext (context .TODO (), gomock .AssignableToTypeOf (& ec2.DescribeVpcsInput {})).Return (& ec2.DescribeVpcsOutput {
@@ -320,6 +321,17 @@ func TestServiceDiassociateSecondaryCidr(t *testing.T) {
320
321
},
321
322
wantErr : false ,
322
323
},
324
+ {
325
+ name : "Should successfully return from disassociating secondary CIDR blocks if VPC is in unmanaged mode" ,
326
+ fillAWSManagedControlPlaneSecondaryCIDR : true ,
327
+ unmanagedVPC : true ,
328
+ expect : func (m * mocks.MockEC2APIMockRecorder ) {
329
+ // No calls expected
330
+ m .DescribeVpcsWithContext (context .TODO (), gomock .Any ()).Times (0 )
331
+ m .DisassociateVpcCidrBlockWithContext (context .TODO (), gomock .Any ()).Times (0 )
332
+ },
333
+ wantErr : false ,
334
+ },
323
335
{
324
336
name : "Should successfully disassociate existing secondary CIDR blocks" ,
325
337
fillAWSManagedControlPlaneSecondaryCIDR : false ,
@@ -381,6 +393,18 @@ func TestServiceDiassociateSecondaryCidr(t *testing.T) {
381
393
if ! tt .fillAWSManagedControlPlaneSecondaryCIDR {
382
394
mcpScope .ControlPlane .Spec .SecondaryCidrBlock = nil
383
395
}
396
+
397
+ if ! tt .unmanagedVPC {
398
+ mcpScope .ControlPlane .Spec .NetworkSpec .VPC = infrav1.VPCSpec {
399
+ ID : subnetsVPCID ,
400
+ Tags : infrav1.Tags {
401
+ infrav1 .ClusterTagKey ("test-cluster" ): "owned" ,
402
+ },
403
+ }
404
+
405
+ mcpScope .Cluster .Name = "test-cluster"
406
+ }
407
+
384
408
mcpScope .ControlPlane .Spec .NetworkSpec .VPC .SecondaryCidrBlocks = tt .networkSecondaryCIDRBlocks
385
409
386
410
s := NewService (mcpScope )
0 commit comments