1
- use std:: time:: Duration ;
2
-
3
1
use futures:: prelude:: * ;
4
- use k8s_openapi:: chrono;
5
2
use kube:: ResourceExt ;
6
3
use linkerd_policy_controller_core:: { Ipv4Net , Ipv6Net } ;
7
4
use linkerd_policy_controller_k8s_api as k8s;
8
5
use linkerd_policy_test:: {
9
6
assert_default_all_unauthenticated_labels, assert_is_default_all_unauthenticated,
10
- assert_protocol_detect, create, create_ready_pod, grpc, with_temp_ns,
7
+ assert_protocol_detect, await_condition , create, create_ready_pod, grpc, with_temp_ns,
11
8
} ;
12
9
use maplit:: { btreemap, convert_args, hashmap} ;
13
10
use tokio:: time;
@@ -332,7 +329,7 @@ async fn http_local_rate_limit_policy() {
332
329
. await ;
333
330
334
331
// Create a rate-limit policy associated to the server
335
- create (
332
+ let rate_limit = create (
336
333
& client,
337
334
k8s:: policy:: ratelimit_policy:: HttpLocalRateLimitPolicy {
338
335
metadata : k8s:: ObjectMeta {
@@ -356,25 +353,29 @@ async fn http_local_rate_limit_policy() {
356
353
} ] ,
357
354
} ] ) ,
358
355
} ,
359
- status : Some ( k8s:: policy:: HttpLocalRateLimitPolicyStatus {
360
- conditions : vec ! [ k8s:: Condition {
361
- last_transition_time: k8s:: Time ( chrono:: DateTime :: <chrono:: Utc >:: MIN_UTC ) ,
362
- message: "" . to_string( ) ,
363
- observed_generation: None ,
364
- reason: "" . to_string( ) ,
365
- status: "True" . to_string( ) ,
366
- type_: "Accepted" . to_string( ) ,
367
- } ] ,
368
- target_ref : k8s:: policy:: LocalTargetRef {
369
- group : Some ( "policy.linkerd.io" . to_string ( ) ) ,
370
- kind : "Server" . to_string ( ) ,
371
- name : "linkerd-admin" . to_string ( ) ,
372
- } ,
373
- } ) ,
356
+ status : None ,
374
357
} ,
375
358
)
376
359
. await ;
377
360
361
+ await_condition (
362
+ & client,
363
+ & ns,
364
+ & rate_limit. name_unchecked ( ) ,
365
+ |obj : Option < & k8s:: policy:: ratelimit_policy:: HttpLocalRateLimitPolicy > | {
366
+ obj. as_ref ( ) . map_or ( false , |obj| {
367
+ obj. status . as_ref ( ) . map_or ( false , |status| {
368
+ status
369
+ . conditions
370
+ . iter ( )
371
+ . any ( |c| c. type_ == "Accepted" && c. status == "True" )
372
+ } )
373
+ } )
374
+ } ,
375
+ )
376
+ . await
377
+ . expect ( "rate limit must get a status" ) ;
378
+
378
379
let client_id = format ! ( "sa-0.{}.serviceaccount.identity.linkerd.cluster.local" , ns) ;
379
380
let ratelimit_overrides = vec ! [ ( 200 , vec![ client_id] ) ] ;
380
381
let ratelimit =
@@ -609,23 +610,23 @@ async fn http_routes_ordered_by_creation() {
609
610
// Creation timestamps in Kubernetes only have second precision, so we
610
611
// must wait a whole second between creating each of these routes in
611
612
// order for them to have different creation timestamps.
612
- tokio :: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
613
+ time:: sleep ( time :: Duration :: from_secs ( 1 ) ) . await ;
613
614
create (
614
615
& client,
615
616
mk_admin_route_with_path ( ns. as_ref ( ) , "a" , "/ready" ) ,
616
617
)
617
618
. await ;
618
619
next_config ( & mut rx) . await ;
619
620
620
- tokio :: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
621
+ time:: sleep ( time :: Duration :: from_secs ( 1 ) ) . await ;
621
622
create (
622
623
& client,
623
624
mk_admin_route_with_path ( ns. as_ref ( ) , "c" , "/shutdown" ) ,
624
625
)
625
626
. await ;
626
627
next_config ( & mut rx) . await ;
627
628
628
- tokio :: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
629
+ time:: sleep ( time :: Duration :: from_secs ( 1 ) ) . await ;
629
630
create (
630
631
& client,
631
632
mk_admin_route_with_path ( ns. as_ref ( ) , "b" , "/proxy-log-level" ) ,
@@ -815,7 +816,7 @@ async fn retry_watch_server(
815
816
Ok ( rx) => return rx,
816
817
Err ( error) => {
817
818
tracing:: error!( ?error, ns, pod_name, "failed to watch policy for port 4191" ) ;
818
- time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
819
+ time:: sleep ( time :: Duration :: from_secs ( 1 ) ) . await ;
819
820
}
820
821
}
821
822
}
0 commit comments