@@ -243,6 +243,7 @@ func TestServiceDiassociateSecondaryCidr(t *testing.T) {
243243 tests := []struct {
244244 name string
245245 fillAWSManagedControlPlaneSecondaryCIDR bool
246+ unmanagedVPC bool
246247 networkSecondaryCIDRBlocks []infrav1.VpcCidrBlock
247248 expect func (m * mocks.MockEC2APIMockRecorder )
248249 wantErr bool
@@ -289,7 +290,7 @@ func TestServiceDiassociateSecondaryCidr(t *testing.T) {
289290 },
290291 },
291292 {
292- name : "Should return error if failed to diassociate secondary cidr block" ,
293+ name : "Should return error if failed to disassociate secondary cidr block" ,
293294 fillAWSManagedControlPlaneSecondaryCIDR : true ,
294295 expect : func (m * mocks.MockEC2APIMockRecorder ) {
295296 m .DescribeVpcsWithContext (context .TODO (), gomock .AssignableToTypeOf (& ec2.DescribeVpcsInput {})).Return (& ec2.DescribeVpcsOutput {
@@ -320,6 +321,17 @@ func TestServiceDiassociateSecondaryCidr(t *testing.T) {
320321 },
321322 wantErr : false ,
322323 },
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+ },
323335 {
324336 name : "Should successfully disassociate existing secondary CIDR blocks" ,
325337 fillAWSManagedControlPlaneSecondaryCIDR : false ,
@@ -381,6 +393,18 @@ func TestServiceDiassociateSecondaryCidr(t *testing.T) {
381393 if ! tt .fillAWSManagedControlPlaneSecondaryCIDR {
382394 mcpScope .ControlPlane .Spec .SecondaryCidrBlock = nil
383395 }
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+
384408 mcpScope .ControlPlane .Spec .NetworkSpec .VPC .SecondaryCidrBlocks = tt .networkSecondaryCIDRBlocks
385409
386410 s := NewService (mcpScope )
0 commit comments