@@ -28,7 +28,6 @@ import (
2828 "k8s.io/utils/ptr"
2929
3030 infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
31- utildefaulting "sigs.k8s.io/cluster-api/util/defaulting"
3231)
3332
3433var (
@@ -37,134 +36,6 @@ var (
3736 vV1_16 = "v1.16"
3837)
3938
40- func TestDefaultingWebhook (t * testing.T ) {
41- defaultTestBastion := infrav1.Bastion {
42- AllowedCIDRBlocks : []string {"0.0.0.0/0" },
43- }
44- AZUsageLimit := 3
45- defaultVPCSpec := infrav1.VPCSpec {
46- AvailabilityZoneUsageLimit : & AZUsageLimit ,
47- AvailabilityZoneSelection : & infrav1 .AZSelectionSchemeOrdered ,
48- SubnetSchema : & infrav1 .SubnetSchemaPreferPrivate ,
49- }
50- defaultIdentityRef := & infrav1.AWSIdentityReference {
51- Kind : infrav1 .ControllerIdentityKind ,
52- Name : infrav1 .AWSClusterControllerIdentityName ,
53- }
54- defaultNetworkSpec := infrav1.NetworkSpec {
55- VPC : defaultVPCSpec ,
56- CNI : & infrav1.CNISpec {
57- CNIIngressRules : []infrav1.CNIIngressRule {
58- {
59- Description : "bgp (calico)" ,
60- Protocol : "tcp" ,
61- FromPort : 179 ,
62- ToPort : 179 ,
63- },
64- {
65- Description : "IP-in-IP (calico)" ,
66- Protocol : "4" ,
67- FromPort : - 1 ,
68- ToPort : 65535 ,
69- },
70- },
71- },
72- }
73-
74- tests := []struct {
75- name string
76- resourceName string
77- resourceNS string
78- expectHash bool
79- expect string
80- spec AWSManagedControlPlaneSpec
81- expectSpec AWSManagedControlPlaneSpec
82- }{
83- {
84- name : "less than 100 chars" ,
85- resourceName : "cluster1" ,
86- resourceNS : "default" ,
87- expectHash : false ,
88- expectSpec : AWSManagedControlPlaneSpec {EKSClusterName : "default_cluster1" , IdentityRef : defaultIdentityRef , Bastion : defaultTestBastion , NetworkSpec : defaultNetworkSpec , TokenMethod : & EKSTokenMethodIAMAuthenticator },
89- },
90- {
91- name : "less than 100 chars, dot in name" ,
92- resourceName : "team1.cluster1" ,
93- resourceNS : "default" ,
94- expectHash : false ,
95- expectSpec : AWSManagedControlPlaneSpec {EKSClusterName : "default_team1_cluster1" , IdentityRef : defaultIdentityRef , Bastion : defaultTestBastion , NetworkSpec : defaultNetworkSpec , TokenMethod : & EKSTokenMethodIAMAuthenticator },
96- },
97- {
98- name : "more than 100 chars" ,
99- resourceName : "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde" ,
100- resourceNS : "default" ,
101- expectHash : true ,
102- expectSpec : AWSManagedControlPlaneSpec {EKSClusterName : "capi_" , IdentityRef : defaultIdentityRef , Bastion : defaultTestBastion , NetworkSpec : defaultNetworkSpec , TokenMethod : & EKSTokenMethodIAMAuthenticator },
103- },
104- {
105- name : "with patch" ,
106- resourceName : "cluster1" ,
107- resourceNS : "default" ,
108- expectHash : false ,
109- spec : AWSManagedControlPlaneSpec {Version : & vV1_17_1 },
110- expectSpec : AWSManagedControlPlaneSpec {EKSClusterName : "default_cluster1" , Version : & vV1_17_1 , IdentityRef : defaultIdentityRef , Bastion : defaultTestBastion , NetworkSpec : defaultNetworkSpec , TokenMethod : & EKSTokenMethodIAMAuthenticator },
111- },
112- {
113- name : "with allowed ip on bastion" ,
114- resourceName : "cluster1" ,
115- resourceNS : "default" ,
116- expectHash : false ,
117- spec : AWSManagedControlPlaneSpec {Bastion : infrav1.Bastion {AllowedCIDRBlocks : []string {"100.100.100.100/0" }}},
118- expectSpec : AWSManagedControlPlaneSpec {EKSClusterName : "default_cluster1" , IdentityRef : defaultIdentityRef , Bastion : infrav1.Bastion {AllowedCIDRBlocks : []string {"100.100.100.100/0" }}, NetworkSpec : defaultNetworkSpec , TokenMethod : & EKSTokenMethodIAMAuthenticator },
119- },
120- {
121- name : "with CNI on network" ,
122- resourceName : "cluster1" ,
123- resourceNS : "default" ,
124- expectHash : false ,
125- spec : AWSManagedControlPlaneSpec {NetworkSpec : infrav1.NetworkSpec {CNI : & infrav1.CNISpec {}}},
126- expectSpec : AWSManagedControlPlaneSpec {EKSClusterName : "default_cluster1" , IdentityRef : defaultIdentityRef , Bastion : defaultTestBastion , NetworkSpec : infrav1.NetworkSpec {CNI : & infrav1.CNISpec {}, VPC : defaultVPCSpec }, TokenMethod : & EKSTokenMethodIAMAuthenticator },
127- },
128- {
129- name : "secondary CIDR" ,
130- resourceName : "cluster1" ,
131- resourceNS : "default" ,
132- expectHash : false ,
133- expectSpec : AWSManagedControlPlaneSpec {EKSClusterName : "default_cluster1" , IdentityRef : defaultIdentityRef , Bastion : defaultTestBastion , NetworkSpec : defaultNetworkSpec , SecondaryCidrBlock : nil , TokenMethod : & EKSTokenMethodIAMAuthenticator },
134- },
135- }
136-
137- for _ , tc := range tests {
138- t .Run (tc .name , func (t * testing.T ) {
139- ctx := context .TODO ()
140- g := NewWithT (t )
141-
142- mcp := & AWSManagedControlPlane {
143- ObjectMeta : metav1.ObjectMeta {
144- Name : tc .resourceName ,
145- Namespace : tc .resourceNS ,
146- },
147- }
148- t .Run ("for AWSManagedMachinePool" , utildefaulting .DefaultValidateTest (mcp ))
149- mcp .Spec = tc .spec
150-
151- g .Expect (testEnv .Create (ctx , mcp )).To (Succeed ())
152-
153- defer func () {
154- testEnv .Delete (ctx , mcp )
155- }()
156-
157- g .Expect (mcp .Spec .EKSClusterName ).ToNot (BeEmpty ())
158-
159- if tc .expectHash {
160- g .Expect (strings .HasPrefix (mcp .Spec .EKSClusterName , "capa_" )).To (BeTrue ())
161- // We don't care about the exact name
162- tc .expectSpec .EKSClusterName = mcp .Spec .EKSClusterName
163- }
164- g .Expect (mcp .Spec ).To (Equal (tc .expectSpec ))
165- })
166- }
167- }
16839
16940func TestWebhookCreate (t * testing.T ) {
17041 tests := []struct { //nolint:maligned
0 commit comments