@@ -59,9 +59,14 @@ func TestReconcileSubnets(t *testing.T) {
59
59
{ID : "subnet-private-us-east-1-nyc-1a" , AvailabilityZone : "us-east-1-nyc-1a" , CidrBlock : "10.0.5.0/24" , IsPublic : false },
60
60
{ID : "subnet-public-us-east-1-nyc-1a" , AvailabilityZone : "us-east-1-nyc-1a" , CidrBlock : "10.0.6.0/24" , IsPublic : true },
61
61
}
62
+ stubSubnetsWavelengthZone := []infrav1.SubnetSpec {
63
+ {ID : "subnet-private-us-east-1-wl1-nyc-wlz-1" , AvailabilityZone : "us-east-1-wl1-nyc-wlz-1" , CidrBlock : "10.0.7.0/24" , IsPublic : false },
64
+ {ID : "subnet-public-us-east-1-wl1-nyc-wlz-1" , AvailabilityZone : "us-east-1-wl1-nyc-wlz-1" , CidrBlock : "10.0.8.0/24" , IsPublic : true },
65
+ }
62
66
// TODO(mtulio): replace by slices.Concat(...) on go 1.22+
63
67
stubSubnetsAllZones := stubSubnetsAvailabilityZone
64
68
stubSubnetsAllZones = append (stubSubnetsAllZones , stubSubnetsLocalZone ... )
69
+ stubSubnetsAllZones = append (stubSubnetsAllZones , stubSubnetsWavelengthZone ... )
65
70
66
71
// NetworkSpec with subnets in zone type availability-zone
67
72
stubNetworkSpecWithSubnets := & infrav1.NetworkSpec {
@@ -655,7 +660,7 @@ func TestReconcileSubnets(t *testing.T) {
655
660
tagUnmanagedNetworkResources : true ,
656
661
},
657
662
{
658
- name : "Unmanaged VPC, 2 existing matching subnets, subnet tagging fails with subnet update, should succeed" ,
663
+ name : "Unmanaged VPC, one existing matching subnets, subnet tagging fails with subnet update, should succeed" ,
659
664
input : NewClusterScope ().WithNetwork (& infrav1.NetworkSpec {
660
665
VPC : infrav1.VPCSpec {
661
666
ID : subnetsVPCID ,
@@ -767,6 +772,9 @@ func TestReconcileSubnets(t *testing.T) {
767
772
{
768
773
ID : "subnet-1" ,
769
774
},
775
+ {
776
+ ID : "subnet-2" ,
777
+ },
770
778
},
771
779
}).WithTagUnmanagedNetworkResources (true ),
772
780
optionalExpectSubnets : infrav1.Subnets {
@@ -778,6 +786,14 @@ func TestReconcileSubnets(t *testing.T) {
778
786
IsPublic : true ,
779
787
Tags : infrav1.Tags {},
780
788
},
789
+ {
790
+ ID : "subnet-2" ,
791
+ ResourceID : "subnet-2" ,
792
+ AvailabilityZone : "us-east-1b" ,
793
+ CidrBlock : "10.0.11.0/24" ,
794
+ IsPublic : true ,
795
+ Tags : infrav1.Tags {},
796
+ },
781
797
},
782
798
expect : func (m * mocks.MockEC2APIMockRecorder ) {
783
799
m .DescribeSubnetsWithContext (context .TODO (), gomock .Eq (& ec2.DescribeSubnetsInput {
@@ -799,6 +815,13 @@ func TestReconcileSubnets(t *testing.T) {
799
815
SubnetId : aws .String ("subnet-1" ),
800
816
AvailabilityZone : aws .String ("us-east-1a" ),
801
817
CidrBlock : aws .String ("10.0.10.0/24" ),
818
+ MapPublicIpOnLaunch : aws .Bool (true ),
819
+ },
820
+ {
821
+ VpcId : aws .String (subnetsVPCID ),
822
+ SubnetId : aws .String ("subnet-2" ),
823
+ AvailabilityZone : aws .String ("us-east-1b" ),
824
+ CidrBlock : aws .String ("10.0.11.0/24" ),
802
825
MapPublicIpOnLaunch : aws .Bool (false ),
803
826
},
804
827
},
@@ -821,6 +844,20 @@ func TestReconcileSubnets(t *testing.T) {
821
844
},
822
845
},
823
846
},
847
+ {
848
+ VpcId : aws .String (subnetsVPCID ),
849
+ Associations : []* ec2.RouteTableAssociation {
850
+ {
851
+ SubnetId : aws .String ("subnet-2" ),
852
+ RouteTableId : aws .String ("rt-00000" ),
853
+ },
854
+ },
855
+ Routes : []* ec2.Route {
856
+ {
857
+ GatewayId : aws .String ("igw-12345" ),
858
+ },
859
+ },
860
+ },
824
861
},
825
862
}, nil )
826
863
@@ -840,10 +877,10 @@ func TestReconcileSubnets(t *testing.T) {
840
877
gomock .Any ()).Return (nil )
841
878
842
879
stubMockDescribeAvailabilityZonesWithContextCustomZones (m , []* ec2.AvailabilityZone {
843
- {ZoneName : aws .String ("us-east-1a" )},
880
+ {ZoneName : aws .String ("us-east-1a" )}, { ZoneName : aws . String ( "us-east-1b" )},
844
881
}).AnyTimes ()
845
882
846
- m .CreateTagsWithContext (context .TODO (), gomock .Eq (& ec2.CreateTagsInput {
883
+ subnet1tag := m .CreateTagsWithContext (context .TODO (), gomock .Eq (& ec2.CreateTagsInput {
847
884
Resources : aws .StringSlice ([]string {"subnet-1" }),
848
885
Tags : []* ec2.Tag {
849
886
{
@@ -857,6 +894,21 @@ func TestReconcileSubnets(t *testing.T) {
857
894
},
858
895
})).
859
896
Return (& ec2.CreateTagsOutput {}, fmt .Errorf ("tagging failed" ))
897
+
898
+ m .CreateTagsWithContext (context .TODO (), gomock .Eq (& ec2.CreateTagsInput {
899
+ Resources : aws .StringSlice ([]string {"subnet-2" }),
900
+ Tags : []* ec2.Tag {
901
+ {
902
+ Key : aws .String ("kubernetes.io/cluster/test-cluster" ),
903
+ Value : aws .String ("shared" ),
904
+ },
905
+ {
906
+ Key : aws .String ("kubernetes.io/role/elb" ),
907
+ Value : aws .String ("1" ),
908
+ },
909
+ },
910
+ })).
911
+ Return (& ec2.CreateTagsOutput {}, fmt .Errorf ("tagging failed" )).After (subnet1tag )
860
912
},
861
913
tagUnmanagedNetworkResources : true ,
862
914
},
@@ -975,6 +1027,11 @@ func TestReconcileSubnets(t *testing.T) {
975
1027
})).
976
1028
Return (& ec2.CreateTagsOutput {}, nil )
977
1029
1030
+ stubMockDescribeAvailabilityZonesWithContextCustomZones (m , []* ec2.AvailabilityZone {
1031
+ {ZoneName : aws .String ("us-east-1a" ), ZoneType : aws .String ("availability-zone" )},
1032
+ {ZoneName : aws .String ("us-east-1b" ), ZoneType : aws .String ("availability-zone" )},
1033
+ }).AnyTimes ()
1034
+
978
1035
m .CreateTagsWithContext (context .TODO (), gomock .Eq (& ec2.CreateTagsInput {
979
1036
Resources : aws .StringSlice ([]string {"subnet-2" }),
980
1037
Tags : []* ec2.Tag {
@@ -2873,6 +2930,7 @@ func TestReconcileSubnets(t *testing.T) {
2873
2930
{ZoneName : aws .String ("us-east-1a" ), ZoneType : aws .String ("availability-zone" )},
2874
2931
{ZoneName : aws .String ("us-east-1b" ), ZoneType : aws .String ("availability-zone" )},
2875
2932
{ZoneName : aws .String ("us-east-1-nyc-1a" ), ZoneType : aws .String ("local-zone" ), ParentZoneName : aws .String ("us-east-1a" )},
2933
+ {ZoneName : aws .String ("us-east-1-wl1-nyc-wlz-1" ), ZoneType : aws .String ("wavelength-zone" ), ParentZoneName : aws .String ("us-east-1a" )},
2876
2934
}).AnyTimes ()
2877
2935
2878
2936
m .WaitUntilSubnetAvailableWithContext (context .TODO (), gomock .Any ()).AnyTimes ()
@@ -2928,6 +2986,12 @@ func TestReconcileSubnets(t *testing.T) {
2928
2986
2929
2987
lz1Public := stubGenMockCreateSubnetWithContext (m , "test-cluster" , "us-east-1-nyc-1a" , "public" , "10.0.6.0/24" , true ).After (lz1Private )
2930
2988
stubMockModifySubnetAttributeWithContext (m , "subnet-public-us-east-1-nyc-1a" ).After (lz1Public )
2989
+
2990
+ // Wavelength zone nyc-1.
2991
+ wz1Private := stubGenMockCreateSubnetWithContext (m , "test-cluster" , "us-east-1-wl1-nyc-wlz-1" , "private" , "10.0.7.0/24" , true ).
2992
+ After (describeCall )
2993
+
2994
+ stubGenMockCreateSubnetWithContext (m , "test-cluster" , "us-east-1-wl1-nyc-wlz-1" , "public" , "10.0.8.0/24" , true ).After (wz1Private )
2931
2995
},
2932
2996
},
2933
2997
{
@@ -2990,14 +3054,21 @@ func TestReconcileSubnets(t *testing.T) {
2990
3054
{ResourceID : "subnet-az-1a-public" },
2991
3055
{ResourceID : "subnet-lz-1a-private" },
2992
3056
{ResourceID : "subnet-lz-1a-public" },
3057
+ {ResourceID : "subnet-wl-1a-private" },
3058
+ {ResourceID : "subnet-wl-1a-public" },
2993
3059
}
2994
3060
return NewClusterScope ().WithNetwork (net )
2995
3061
}(),
2996
3062
expect : func (m * mocks.MockEC2APIMockRecorder ) {
2997
3063
stubMockDescribeSubnetsWithContextUnmanaged (m )
2998
3064
stubMockDescribeAvailabilityZonesWithContextAllZones (m )
2999
- stubMockDescribeRouteTablesWithContext (m )
3065
+ stubMockDescribeRouteTablesWithContextWithWavelength (m ,
3066
+ []string {"subnet-az-1a-private" , "subnet-lz-1a-private" , "subnet-wl-1a-private" },
3067
+ []string {"subnet-az-1a-public" , "subnet-lz-1a-public" },
3068
+ []string {"subnet-wl-1a-public" })
3069
+
3000
3070
stubMockDescribeNatGatewaysPagesWithContext (m )
3071
+ stubMockCreateTagsWithContext (m , "test-cluster" , "subnet-az-1a-private" , "us-east-1a" , "private" , false ).AnyTimes ()
3001
3072
},
3002
3073
},
3003
3074
}
@@ -3601,6 +3672,41 @@ func TestService_retrieveZoneInfo(t *testing.T) {
3601
3672
},
3602
3673
},
3603
3674
},
3675
+ {
3676
+ name : "get type wavelength zones" ,
3677
+ inputZoneNames : []string {"us-east-1-wl1-nyc-wlz-1" , "us-east-1-wl1-bos-wlz-1" },
3678
+ expect : func (m * mocks.MockEC2APIMockRecorder ) {
3679
+ m .DescribeAvailabilityZonesWithContext (context .TODO (), & ec2.DescribeAvailabilityZonesInput {
3680
+ ZoneNames : aws .StringSlice ([]string {"us-east-1-wl1-nyc-wlz-1" , "us-east-1-wl1-bos-wlz-1" }),
3681
+ }).
3682
+ Return (& ec2.DescribeAvailabilityZonesOutput {
3683
+ AvailabilityZones : []* ec2.AvailabilityZone {
3684
+ {
3685
+ ZoneName : aws .String ("us-east-1-wl1-nyc-wlz-1" ),
3686
+ ZoneType : aws .String ("wavelength-zone" ),
3687
+ ParentZoneName : aws .String ("us-east-1a" ),
3688
+ },
3689
+ {
3690
+ ZoneName : aws .String ("us-east-1-wl1-bos-wlz-1" ),
3691
+ ZoneType : aws .String ("wavelength-zone" ),
3692
+ ParentZoneName : aws .String ("us-east-1b" ),
3693
+ },
3694
+ },
3695
+ }, nil )
3696
+ },
3697
+ want : []* ec2.AvailabilityZone {
3698
+ {
3699
+ ZoneName : aws .String ("us-east-1-wl1-nyc-wlz-1" ),
3700
+ ZoneType : aws .String ("wavelength-zone" ),
3701
+ ParentZoneName : aws .String ("us-east-1a" ),
3702
+ },
3703
+ {
3704
+ ZoneName : aws .String ("us-east-1-wl1-bos-wlz-1" ),
3705
+ ZoneType : aws .String ("wavelength-zone" ),
3706
+ ParentZoneName : aws .String ("us-east-1b" ),
3707
+ },
3708
+ },
3709
+ },
3604
3710
{
3605
3711
name : "get all zone types" ,
3606
3712
inputZoneNames : []string {"us-east-1a" , "us-east-1-nyc-1a" , "us-east-1-wl1-nyc-wlz-1" },
@@ -3620,6 +3726,11 @@ func TestService_retrieveZoneInfo(t *testing.T) {
3620
3726
ZoneType : aws .String ("local-zone" ),
3621
3727
ParentZoneName : aws .String ("us-east-1a" ),
3622
3728
},
3729
+ {
3730
+ ZoneName : aws .String ("us-east-1-wl1-nyc-wlz-1" ),
3731
+ ZoneType : aws .String ("wavelength-zone" ),
3732
+ ParentZoneName : aws .String ("us-east-1a" ),
3733
+ },
3623
3734
},
3624
3735
}, nil )
3625
3736
},
@@ -3634,6 +3745,11 @@ func TestService_retrieveZoneInfo(t *testing.T) {
3634
3745
ZoneType : aws .String ("local-zone" ),
3635
3746
ParentZoneName : aws .String ("us-east-1a" ),
3636
3747
},
3748
+ {
3749
+ ZoneName : aws .String ("us-east-1-wl1-nyc-wlz-1" ),
3750
+ ZoneType : aws .String ("wavelength-zone" ),
3751
+ ParentZoneName : aws .String ("us-east-1a" ),
3752
+ },
3637
3753
},
3638
3754
},
3639
3755
}
@@ -3732,11 +3848,79 @@ func stubGenMockCreateSubnetWithContext(m *mocks.MockEC2APIMockRecorder, prefix,
3732
3848
}, nil )
3733
3849
}
3734
3850
3851
+ func stubMockCreateTagsWithContext (m * mocks.MockEC2APIMockRecorder , prefix , name , zone , role string , isEdge bool ) * gomock.Call {
3852
+ return m .CreateTagsWithContext (context .TODO (), gomock .Eq (& ec2.CreateTagsInput {
3853
+ Resources : aws .StringSlice ([]string {name }),
3854
+ Tags : stubGetTags (prefix , role , zone , isEdge ),
3855
+ })).
3856
+ Return (& ec2.CreateTagsOutput {}, nil )
3857
+ }
3858
+
3735
3859
func stubMockDescribeRouteTablesWithContext (m * mocks.MockEC2APIMockRecorder ) {
3736
3860
m .DescribeRouteTablesWithContext (context .TODO (), gomock .AssignableToTypeOf (& ec2.DescribeRouteTablesInput {})).
3737
3861
Return (& ec2.DescribeRouteTablesOutput {}, nil )
3738
3862
}
3739
3863
3864
+ func stubMockDescribeRouteTablesWithContextWithWavelength (m * mocks.MockEC2APIMockRecorder , privSubnets , pubSubnetsIGW , pubSubnetsCarrier []string ) * gomock.Call {
3865
+ routes := []* ec2.RouteTable {}
3866
+
3867
+ // create public route table
3868
+ pubTable := & ec2.RouteTable {
3869
+ Routes : []* ec2.Route {
3870
+ {
3871
+ DestinationCidrBlock : aws .String ("0.0.0.0/0" ),
3872
+ GatewayId : aws .String ("igw-0" ),
3873
+ },
3874
+ },
3875
+ RouteTableId : aws .String ("rtb-public" ),
3876
+ }
3877
+ for _ , sub := range pubSubnetsIGW {
3878
+ pubTable .Associations = append (pubTable .Associations , & ec2.RouteTableAssociation {
3879
+ SubnetId : aws .String (sub ),
3880
+ })
3881
+ }
3882
+ routes = append (routes , pubTable )
3883
+
3884
+ // create public carrier route table
3885
+ pubCarrierTable := & ec2.RouteTable {
3886
+ Routes : []* ec2.Route {
3887
+ {
3888
+ DestinationCidrBlock : aws .String ("0.0.0.0/0" ),
3889
+ CarrierGatewayId : aws .String ("cagw-0" ),
3890
+ },
3891
+ },
3892
+ RouteTableId : aws .String ("rtb-carrier" ),
3893
+ }
3894
+ for _ , sub := range pubSubnetsCarrier {
3895
+ pubCarrierTable .Associations = append (pubCarrierTable .Associations , & ec2.RouteTableAssociation {
3896
+ SubnetId : aws .String (sub ),
3897
+ })
3898
+ }
3899
+ routes = append (routes , pubCarrierTable )
3900
+
3901
+ // create private route table
3902
+ privTable := & ec2.RouteTable {
3903
+ Routes : []* ec2.Route {
3904
+ {
3905
+ DestinationCidrBlock : aws .String ("10.0.11.0/24" ),
3906
+ GatewayId : aws .String ("vpc-natgw-1a" ),
3907
+ },
3908
+ },
3909
+ RouteTableId : aws .String ("rtb-private" ),
3910
+ }
3911
+ for _ , sub := range privSubnets {
3912
+ privTable .Associations = append (privTable .Associations , & ec2.RouteTableAssociation {
3913
+ SubnetId : aws .String (sub ),
3914
+ })
3915
+ }
3916
+ routes = append (routes , privTable )
3917
+
3918
+ return m .DescribeRouteTablesWithContext (context .TODO (), gomock .AssignableToTypeOf (& ec2.DescribeRouteTablesInput {})).
3919
+ Return (& ec2.DescribeRouteTablesOutput {
3920
+ RouteTables : routes ,
3921
+ }, nil )
3922
+ }
3923
+
3740
3924
func stubMockDescribeSubnetsWithContext (m * mocks.MockEC2APIMockRecorder , out * ec2.DescribeSubnetsOutput , filterKey , filterValue string ) * gomock.Call {
3741
3925
return m .DescribeSubnetsWithContext (context .TODO (), gomock .Eq (& ec2.DescribeSubnetsInput {
3742
3926
Filters : []* ec2.Filter {
@@ -3760,6 +3944,8 @@ func stubMockDescribeSubnetsWithContextUnmanaged(m *mocks.MockEC2APIMockRecorder
3760
3944
{SubnetId : aws .String ("subnet-az-1a-public" ), AvailabilityZone : aws .String ("us-east-1a" )},
3761
3945
{SubnetId : aws .String ("subnet-lz-1a-private" ), AvailabilityZone : aws .String ("us-east-1-nyc-1a" )},
3762
3946
{SubnetId : aws .String ("subnet-lz-1a-public" ), AvailabilityZone : aws .String ("us-east-1-nyc-1a" )},
3947
+ {SubnetId : aws .String ("subnet-wl-1a-private" ), AvailabilityZone : aws .String ("us-east-1-wl1-nyc-wlz-1" )},
3948
+ {SubnetId : aws .String ("subnet-wl-1a-public" ), AvailabilityZone : aws .String ("us-east-1-wl1-nyc-wlz-1" )},
3763
3949
},
3764
3950
}, "vpc-id" , subnetsVPCID )
3765
3951
}
@@ -3801,6 +3987,11 @@ func stubMockDescribeAvailabilityZonesWithContextAllZones(m *mocks.MockEC2APIMoc
3801
3987
ZoneType : aws .String ("local-zone" ),
3802
3988
ParentZoneName : aws .String ("us-east-1a" ),
3803
3989
},
3990
+ {
3991
+ ZoneName : aws .String ("us-east-1-wl1-nyc-wlz-1" ),
3992
+ ZoneType : aws .String ("wavelength-zone" ),
3993
+ ParentZoneName : aws .String ("us-east-1a" ),
3994
+ },
3804
3995
},
3805
3996
}, nil ).AnyTimes ()
3806
3997
}
0 commit comments