@@ -28,14 +28,20 @@ mod tests {
2828 use uuid:: Uuid ;
2929
3030 use crate :: {
31+ apis:: standard:: common:: { ParentReference , ParentRouteStatus , RouteStatus } ,
3132 apis:: standard:: constants:: {
3233 GatewayConditionReason , GatewayConditionType , ListenerConditionReason ,
33- ListenerConditionType ,
34+ ListenerConditionType , RouteConditionReason , RouteConditionType ,
3435 } ,
3536 apis:: standard:: gatewayclasses:: { GatewayClass , GatewayClassSpec } ,
3637 apis:: standard:: gateways:: {
3738 Gateway , GatewaySpec , GatewayStatus , GatewayStatusAddresses , GatewayStatusListeners ,
3839 } ,
40+ apis:: standard:: grpcroutes:: GrpcRouteSpec ,
41+ apis:: standard:: httproutes:: HttpRouteSpec ,
42+ apis:: standard:: referencegrants:: {
43+ ReferenceGrantFrom , ReferenceGrantSpec , ReferenceGrantTo ,
44+ } ,
3945 } ;
4046
4147 // -------------------------------------------------------------------------
@@ -44,7 +50,7 @@ mod tests {
4450
4551 #[ ignore]
4652 #[ tokio:: test]
47- async fn deploy_gateway ( ) -> Result < ( ) , Error > {
53+ async fn deploy_resources ( ) -> Result < ( ) , Error > {
4854 let ( client, cluster) = get_client ( ) . await ?;
4955 let info = client. apiserver_version ( ) . await ?;
5056
@@ -114,7 +120,7 @@ mod tests {
114120 } ] ) ,
115121 } ;
116122
117- gw = Api :: default_namespaced ( client)
123+ gw = Api :: default_namespaced ( client. clone ( ) )
118124 . patch_status (
119125 gw. metadata . name . clone ( ) . unwrap ( ) . as_str ( ) ,
120126 & PatchParams :: default ( ) ,
@@ -129,6 +135,162 @@ mod tests {
129135 assert ! ( gw. status. clone( ) . unwrap( ) . listeners. is_some( ) ) ;
130136 assert ! ( gw. status. clone( ) . unwrap( ) . conditions. is_some( ) ) ;
131137
138+ let mut http_route = crate :: apis:: standard:: httproutes:: HTTPRoute {
139+ metadata : ObjectMeta :: default ( ) ,
140+ spec : HttpRouteSpec {
141+ hostnames : Some ( vec ! [ "example.com" . to_string( ) ] ) ,
142+ parent_refs : Some ( vec ! [ ParentReference {
143+ group: Some ( "gateway.networking.k8s.io" . to_string( ) ) ,
144+ kind: Some ( "Gateway" . to_string( ) ) ,
145+ namespace: Some ( "default" . to_string( ) ) ,
146+ name: gw. metadata. name. clone( ) . unwrap( ) ,
147+ section_name: None ,
148+ port: None ,
149+ } ] ) ,
150+ rules : Some ( vec ! [ ] ) ,
151+ } ,
152+ status : None ,
153+ } ;
154+ http_route. metadata . name = Some ( "test-http-route" . to_string ( ) ) ;
155+ http_route = Api :: default_namespaced ( client. clone ( ) )
156+ . create ( & PostParams :: default ( ) , & http_route)
157+ . await ?;
158+
159+ assert ! ( http_route. metadata. name. is_some( ) ) ;
160+ assert ! ( http_route. metadata. uid. is_some( ) ) ;
161+ assert ! ( http_route. spec. hostnames. is_some( ) ) ;
162+ assert ! ( http_route. spec. parent_refs. is_some( ) ) ;
163+
164+ let http_route_status = RouteStatus {
165+ parents : vec ! [ ParentRouteStatus {
166+ parent_ref: ParentReference {
167+ group: Some ( "gateway.networking.k8s.io" . to_string( ) ) ,
168+ kind: Some ( "Gateway" . to_string( ) ) ,
169+ namespace: Some ( "default" . to_string( ) ) ,
170+ name: gw. metadata. name. clone( ) . unwrap( ) ,
171+ section_name: None ,
172+ port: None ,
173+ } ,
174+ controller_name: "test-controller" . to_string( ) ,
175+ conditions: vec![ Condition {
176+ last_transition_time: Time ( Utc :: now( ) ) ,
177+ message: "testing http route" . to_string( ) ,
178+ observed_generation: Some ( 1 ) ,
179+ reason: RouteConditionReason :: Accepted . to_string( ) ,
180+ status: "True" . to_string( ) ,
181+ type_: RouteConditionType :: Accepted . to_string( ) ,
182+ } ] ,
183+ } ] ,
184+ } ;
185+
186+ http_route = Api :: default_namespaced ( client. clone ( ) )
187+ . patch_status (
188+ http_route. metadata . name . clone ( ) . unwrap ( ) . as_str ( ) ,
189+ & PatchParams :: default ( ) ,
190+ & Patch :: Merge ( json ! ( {
191+ "status" : Some ( http_route_status)
192+ } ) ) ,
193+ )
194+ . await ?;
195+
196+ assert ! ( http_route. status. is_some( ) ) ;
197+ assert ! ( !http_route. status. clone( ) . unwrap( ) . parents. is_empty( ) ) ;
198+
199+ let mut grpc_route = crate :: apis:: standard:: grpcroutes:: GRPCRoute {
200+ metadata : ObjectMeta :: default ( ) ,
201+ spec : GrpcRouteSpec {
202+ hostnames : Some ( vec ! [ "grpc.example.com" . to_string( ) ] ) ,
203+ parent_refs : Some ( vec ! [ ParentReference {
204+ group: Some ( "gateway.networking.k8s.io" . to_string( ) ) ,
205+ kind: Some ( "Gateway" . to_string( ) ) ,
206+ namespace: Some ( "default" . to_string( ) ) ,
207+ name: gw. metadata. name. clone( ) . unwrap( ) ,
208+ section_name: None ,
209+ port: None ,
210+ } ] ) ,
211+ rules : Some ( vec ! [ ] ) ,
212+ } ,
213+ status : None ,
214+ } ;
215+ grpc_route. metadata . name = Some ( "test-grpc-route" . to_string ( ) ) ;
216+ grpc_route = Api :: default_namespaced ( client. clone ( ) )
217+ . create ( & PostParams :: default ( ) , & grpc_route)
218+ . await ?;
219+
220+ assert ! ( grpc_route. metadata. name. is_some( ) ) ;
221+ assert ! ( grpc_route. metadata. uid. is_some( ) ) ;
222+ assert ! ( grpc_route. spec. hostnames. is_some( ) ) ;
223+ assert ! ( grpc_route. spec. parent_refs. is_some( ) ) ;
224+
225+ let grpc_route_status = RouteStatus {
226+ parents : vec ! [ ParentRouteStatus {
227+ parent_ref: ParentReference {
228+ group: Some ( "gateway.networking.k8s.io" . to_string( ) ) ,
229+ kind: Some ( "Gateway" . to_string( ) ) ,
230+ namespace: Some ( "default" . to_string( ) ) ,
231+ name: gw. metadata. name. clone( ) . unwrap( ) ,
232+ section_name: None ,
233+ port: None ,
234+ } ,
235+ controller_name: "test-controller" . to_string( ) ,
236+ conditions: vec![ Condition {
237+ last_transition_time: Time ( Utc :: now( ) ) ,
238+ message: "testing grpc route" . to_string( ) ,
239+ observed_generation: Some ( 1 ) ,
240+ reason: RouteConditionReason :: Accepted . to_string( ) ,
241+ status: "True" . to_string( ) ,
242+ type_: RouteConditionType :: Accepted . to_string( ) ,
243+ } ] ,
244+ } ] ,
245+ } ;
246+
247+ grpc_route = Api :: default_namespaced ( client. clone ( ) )
248+ . patch_status (
249+ grpc_route. metadata . name . clone ( ) . unwrap ( ) . as_str ( ) ,
250+ & PatchParams :: default ( ) ,
251+ & Patch :: Merge ( json ! ( {
252+ "status" : Some ( grpc_route_status)
253+ } ) ) ,
254+ )
255+ . await ?;
256+
257+ assert ! ( grpc_route. status. is_some( ) ) ;
258+ assert ! ( !grpc_route. status. clone( ) . unwrap( ) . parents. is_empty( ) ) ;
259+
260+ let mut ref_grant = crate :: apis:: standard:: referencegrants:: ReferenceGrant {
261+ metadata : ObjectMeta :: default ( ) ,
262+ spec : ReferenceGrantSpec {
263+ from : vec ! [ ReferenceGrantFrom {
264+ group: "gateway.networking.k8s.io" . to_string( ) ,
265+ kind: "HTTPRoute" . to_string( ) ,
266+ namespace: "default" . to_string( ) ,
267+ } ] ,
268+ to : vec ! [ ReferenceGrantTo {
269+ group: "" . to_string( ) ,
270+ kind: "Service" . to_string( ) ,
271+ name: Some ( "backend-service" . to_string( ) ) ,
272+ } ] ,
273+ } ,
274+ } ;
275+ ref_grant. metadata . name = Some ( "test-reference-grant" . to_string ( ) ) ;
276+ ref_grant = Api :: default_namespaced ( client. clone ( ) )
277+ . create ( & PostParams :: default ( ) , & ref_grant)
278+ . await ?;
279+
280+ assert ! ( ref_grant. metadata. name. is_some( ) ) ;
281+ assert ! ( ref_grant. metadata. uid. is_some( ) ) ;
282+ assert ! ( !ref_grant. spec. from. is_empty( ) ) ;
283+ assert_eq ! ( ref_grant. spec. from[ 0 ] . group, "gateway.networking.k8s.io" ) ;
284+ assert_eq ! ( ref_grant. spec. from[ 0 ] . kind, "HTTPRoute" ) ;
285+ assert_eq ! ( ref_grant. spec. from[ 0 ] . namespace, "default" ) ;
286+ assert ! ( !ref_grant. spec. to. is_empty( ) ) ;
287+ assert_eq ! ( ref_grant. spec. to[ 0 ] . group, "" ) ;
288+ assert_eq ! ( ref_grant. spec. to[ 0 ] . kind, "Service" ) ;
289+ assert_eq ! (
290+ ref_grant. spec. to[ 0 ] . name,
291+ Some ( "backend-service" . to_string( ) )
292+ ) ;
293+
132294 Ok ( ( ) )
133295 }
134296
@@ -191,6 +353,36 @@ mod tests {
191353 . create ( & PostParams :: default ( ) , & gw_crd)
192354 . await ?;
193355
356+ let mut http_route_crd = crate :: apis:: standard:: httproutes:: HTTPRoute :: crd ( ) ;
357+ http_route_crd. metadata . annotations = Some ( std:: collections:: BTreeMap :: from ( [ (
358+ "api-approved.kubernetes.io" . to_string ( ) ,
359+ "https://github.com/kubernetes/enhancements/pull/1111" . to_string ( ) ,
360+ ) ] ) ) ;
361+
362+ Api :: all ( client. clone ( ) )
363+ . create ( & PostParams :: default ( ) , & http_route_crd)
364+ . await ?;
365+
366+ let mut grpc_route_crd = crate :: apis:: standard:: grpcroutes:: GRPCRoute :: crd ( ) ;
367+ grpc_route_crd. metadata . annotations = Some ( std:: collections:: BTreeMap :: from ( [ (
368+ "api-approved.kubernetes.io" . to_string ( ) ,
369+ "https://github.com/kubernetes/enhancements/pull/1111" . to_string ( ) ,
370+ ) ] ) ) ;
371+
372+ Api :: all ( client. clone ( ) )
373+ . create ( & PostParams :: default ( ) , & grpc_route_crd)
374+ . await ?;
375+
376+ let mut ref_grant_crd = crate :: apis:: standard:: referencegrants:: ReferenceGrant :: crd ( ) ;
377+ ref_grant_crd. metadata . annotations = Some ( std:: collections:: BTreeMap :: from ( [ (
378+ "api-approved.kubernetes.io" . to_string ( ) ,
379+ "https://github.com/kubernetes/enhancements/pull/1111" . to_string ( ) ,
380+ ) ] ) ) ;
381+
382+ Api :: all ( client. clone ( ) )
383+ . create ( & PostParams :: default ( ) , & ref_grant_crd)
384+ . await ?;
385+
194386 Ok ( ( ) )
195387 }
196388
0 commit comments