@@ -9,7 +9,7 @@ use kube::api::{DeleteParams, ListParams, Patch, PatchParams, PostParams, Resour
9
9
use kube:: client:: Client as KubeClient ;
10
10
use kube:: core:: Status ;
11
11
use kube:: runtime:: wait:: delete:: delete_and_finalize;
12
- use kube:: runtime:: WatchStreamExt ;
12
+ use kube:: runtime:: { watcher , WatchStreamExt } ;
13
13
use kube:: { Api , Config } ;
14
14
use serde:: de:: DeserializeOwned ;
15
15
use serde:: Serialize ;
@@ -426,34 +426,35 @@ impl Client {
426
426
/// # Example
427
427
///
428
428
/// ```no_run
429
- /// use kube::api::ListParams;
430
429
/// use std::time::Duration;
431
430
/// use tokio::time::error::Elapsed;
431
+ /// use kube::runtime::watcher;
432
432
/// use k8s_openapi::api::core::v1::Pod;
433
433
/// use stackable_operator::client::{Client, create_client};
434
434
///
435
435
/// #[tokio::main]
436
436
/// async fn main(){
437
+ ///
437
438
/// let client: Client = create_client(None).await.expect("Unable to construct client.");
438
- /// let lp: ListParams =
439
- /// ListParams ::default().fields(&format!("metadata.name=nonexistent-pod"));
439
+ /// let watcher_config: watcher::Config =
440
+ /// watcher::Config ::default().fields(&format!("metadata.name=nonexistent-pod"));
440
441
///
441
442
/// // Will time out in 1 second unless the nonexistent-pod actually exists
442
443
/// let wait_created_result: Result<(), Elapsed> = tokio::time::timeout(
443
444
/// Duration::from_secs(1),
444
- /// client.wait_created::<Pod>(&client.default_namespace, lp.clone() ),
445
+ /// client.wait_created::<Pod>(&client.default_namespace, watcher_config ),
445
446
/// )
446
447
/// .await;
447
448
/// }
448
449
/// ```
449
450
///
450
- pub async fn wait_created < T > ( & self , namespace : & T :: Namespace , lp : ListParams )
451
+ pub async fn wait_created < T > ( & self , namespace : & T :: Namespace , watcher_config : watcher :: Config )
451
452
where
452
453
T : Resource + GetApi + Clone + Debug + DeserializeOwned + Send + ' static ,
453
454
<T as Resource >:: DynamicType : Default ,
454
455
{
455
456
let api: Api < T > = self . get_api ( namespace) ;
456
- let watcher = kube:: runtime:: watcher ( api, lp ) . boxed ( ) ;
457
+ let watcher = kube:: runtime:: watcher ( api, watcher_config ) . boxed ( ) ;
457
458
watcher
458
459
. applied_objects ( )
459
460
. skip_while ( |res| std:: future:: ready ( res. is_err ( ) ) )
@@ -558,7 +559,8 @@ mod tests {
558
559
use futures:: StreamExt ;
559
560
use k8s_openapi:: api:: core:: v1:: { Container , Pod , PodSpec } ;
560
561
use k8s_openapi:: apimachinery:: pkg:: apis:: meta:: v1:: LabelSelector ;
561
- use kube:: api:: { ListParams , ObjectMeta , PostParams , ResourceExt } ;
562
+ use kube:: api:: { ObjectMeta , PostParams , ResourceExt } ;
563
+ use kube:: runtime:: watcher;
562
564
use kube:: runtime:: watcher:: Event ;
563
565
use std:: collections:: BTreeMap ;
564
566
use std:: time:: Duration ;
@@ -595,7 +597,7 @@ mod tests {
595
597
. create ( & PostParams :: default ( ) , & pod_to_wait_for)
596
598
. await
597
599
. expect ( "Test pod not created." ) ;
598
- let lp : ListParams = ListParams :: default ( ) . fields ( & format ! (
600
+ let watcher_config : watcher :: Config = watcher :: Config :: default ( ) . fields ( & format ! (
599
601
"metadata.name={}" ,
600
602
created_pod
601
603
. metadata
@@ -607,14 +609,14 @@ mod tests {
607
609
// Timeout is not acceptable
608
610
tokio:: time:: timeout (
609
611
Duration :: from_secs ( 30 ) , // Busybox is ~5MB and sub 1 sec to start.
610
- client. wait_created :: < Pod > ( & client. default_namespace , lp . clone ( ) ) ,
612
+ client. wait_created :: < Pod > ( & client. default_namespace , watcher_config . clone ( ) ) ,
611
613
)
612
614
. await
613
615
. expect ( "The tested wait_created function timed out." ) ;
614
616
615
617
// A second, manually constructed watcher is used to verify the ListParams filter out the correct resource
616
618
// and the `wait_created` function returned when the correct resources had been detected.
617
- let mut ready_watcher = kube:: runtime:: watcher :: < Pod > ( api, lp ) . boxed ( ) ;
619
+ let mut ready_watcher = kube:: runtime:: watcher :: < Pod > ( api, watcher_config ) . boxed ( ) ;
618
620
while let Some ( result) = ready_watcher. next ( ) . await {
619
621
match result {
620
622
Ok ( event) => match event {
@@ -649,12 +651,13 @@ mod tests {
649
651
. await
650
652
. expect ( "KUBECONFIG variable must be configured." ) ;
651
653
652
- let lp: ListParams = ListParams :: default ( ) . fields ( "metadata.name=nonexistent-pod" ) ;
654
+ let watcher_config: watcher:: Config =
655
+ watcher:: Config :: default ( ) . fields ( "metadata.name=nonexistent-pod" ) ;
653
656
654
657
// There is no such pod, therefore the `wait_created` function call times out.
655
658
let wait_created_result: Result < ( ) , Elapsed > = tokio:: time:: timeout (
656
659
Duration :: from_secs ( 1 ) ,
657
- client. wait_created :: < Pod > ( & client. default_namespace , lp . clone ( ) ) ,
660
+ client. wait_created :: < Pod > ( & client. default_namespace , watcher_config ) ,
658
661
)
659
662
. await ;
660
663
0 commit comments