@@ -123,6 +123,10 @@ impl Admission {
123
123
return self . admit_spec :: < HttpRouteSpec > ( req) . await ;
124
124
}
125
125
126
+ if is_kind :: < k8s_gateway_api:: HttpRoute > ( & req) {
127
+ return self . admit_spec :: < k8s_gateway_api:: HttpRouteSpec > ( req) . await ;
128
+ }
129
+
126
130
AdmissionResponse :: invalid ( format_args ! (
127
131
"unsupported resource type: {}.{}.{}" ,
128
132
req. kind. group, req. kind. version, req. kind. kind
@@ -422,36 +426,35 @@ impl Validate<ServerAuthorizationSpec> for Admission {
422
426
}
423
427
}
424
428
425
- #[ async_trait:: async_trait]
426
- impl Validate < HttpRouteSpec > for Admission {
427
- async fn validate ( self , _ns : & str , _name : & str , spec : HttpRouteSpec ) -> Result < ( ) > {
428
- use index:: http_route;
429
-
430
- fn validate_match (
431
- httproute:: HttpRouteMatch {
432
- path,
433
- headers,
434
- query_params,
435
- method,
436
- } : httproute:: HttpRouteMatch ,
437
- ) -> Result < ( ) > {
438
- let _ = path. map ( http_route:: path_match) . transpose ( ) ?;
439
- let _ = method
440
- . as_deref ( )
441
- . map ( core:: http_route:: Method :: try_from)
442
- . transpose ( ) ?;
443
-
444
- for q in query_params. into_iter ( ) . flatten ( ) {
445
- http_route:: query_param_match ( q) ?;
446
- }
429
+ use index:: http_route;
430
+ fn validate_match (
431
+ httproute:: HttpRouteMatch {
432
+ path,
433
+ headers,
434
+ query_params,
435
+ method,
436
+ } : httproute:: HttpRouteMatch ,
437
+ ) -> Result < ( ) > {
438
+ let _ = path. map ( http_route:: path_match) . transpose ( ) ?;
439
+ let _ = method
440
+ . as_deref ( )
441
+ . map ( core:: http_route:: Method :: try_from)
442
+ . transpose ( ) ?;
443
+
444
+ for q in query_params. into_iter ( ) . flatten ( ) {
445
+ http_route:: query_param_match ( q) ?;
446
+ }
447
447
448
- for h in headers. into_iter ( ) . flatten ( ) {
449
- http_route:: header_match ( h) ?;
450
- }
448
+ for h in headers. into_iter ( ) . flatten ( ) {
449
+ http_route:: header_match ( h) ?;
450
+ }
451
451
452
- Ok ( ( ) )
453
- }
452
+ Ok ( ( ) )
453
+ }
454
454
455
+ #[ async_trait:: async_trait]
456
+ impl Validate < HttpRouteSpec > for Admission {
457
+ async fn validate ( self , _ns : & str , _name : & str , spec : HttpRouteSpec ) -> Result < ( ) > {
455
458
fn validate_filter ( filter : httproute:: HttpRouteFilter ) -> Result < ( ) > {
456
459
match filter {
457
460
httproute:: HttpRouteFilter :: RequestHeaderModifier {
@@ -516,3 +519,49 @@ impl Validate<HttpRouteSpec> for Admission {
516
519
Ok ( ( ) )
517
520
}
518
521
}
522
+
523
+ #[ async_trait:: async_trait]
524
+ impl Validate < k8s_gateway_api:: HttpRouteSpec > for Admission {
525
+ async fn validate (
526
+ self ,
527
+ _ns : & str ,
528
+ _name : & str ,
529
+ spec : k8s_gateway_api:: HttpRouteSpec ,
530
+ ) -> Result < ( ) > {
531
+ fn validate_filter ( filter : k8s_gateway_api:: HttpRouteFilter ) -> Result < ( ) > {
532
+ match filter {
533
+ k8s_gateway_api:: HttpRouteFilter :: RequestHeaderModifier {
534
+ request_header_modifier,
535
+ } => http_route:: header_modifier ( request_header_modifier) . map ( |_| ( ) ) ,
536
+ k8s_gateway_api:: HttpRouteFilter :: ResponseHeaderModifier {
537
+ response_header_modifier,
538
+ } => http_route:: header_modifier ( response_header_modifier) . map ( |_| ( ) ) ,
539
+ k8s_gateway_api:: HttpRouteFilter :: RequestRedirect { request_redirect } => {
540
+ http_route:: req_redirect ( request_redirect) . map ( |_| ( ) )
541
+ }
542
+ k8s_gateway_api:: HttpRouteFilter :: RequestMirror { .. } => Ok ( ( ) ) ,
543
+ k8s_gateway_api:: HttpRouteFilter :: URLRewrite { .. } => Ok ( ( ) ) ,
544
+ k8s_gateway_api:: HttpRouteFilter :: ExtensionRef { .. } => Ok ( ( ) ) ,
545
+ }
546
+ }
547
+
548
+ // Validate the rules in this spec.
549
+ // This is essentially equivalent to the indexer's conversion function
550
+ // from `HttpRouteSpec` to `InboundRouteBinding`, except that we don't
551
+ // actually allocate stuff in order to return an `InboundRouteBinding`.
552
+ for k8s_gateway_api:: HttpRouteRule {
553
+ filters, matches, ..
554
+ } in spec. rules . into_iter ( ) . flatten ( )
555
+ {
556
+ for m in matches. into_iter ( ) . flatten ( ) {
557
+ validate_match ( m) ?;
558
+ }
559
+
560
+ for f in filters. into_iter ( ) . flatten ( ) {
561
+ validate_filter ( f) ?;
562
+ }
563
+ }
564
+
565
+ Ok ( ( ) )
566
+ }
567
+ }
0 commit comments