@@ -9,7 +9,7 @@ use kube::api::{DeleteParams, ListParams, Patch, PatchParams, PostParams, Resour
99use kube:: client:: Client as KubeClient ;
1010use kube:: core:: Status ;
1111use kube:: runtime:: wait:: delete:: delete_and_finalize;
12- use kube:: runtime:: WatchStreamExt ;
12+ use kube:: runtime:: { watcher , WatchStreamExt } ;
1313use kube:: { Api , Config } ;
1414use serde:: de:: DeserializeOwned ;
1515use serde:: Serialize ;
@@ -426,34 +426,35 @@ impl Client {
426426 /// # Example
427427 ///
428428 /// ```no_run
429- /// use kube::api::ListParams;
430429 /// use std::time::Duration;
431430 /// use tokio::time::error::Elapsed;
431+ /// use kube::runtime::watcher;
432432 /// use k8s_openapi::api::core::v1::Pod;
433433 /// use stackable_operator::client::{Client, create_client};
434434 ///
435435 /// #[tokio::main]
436436 /// async fn main(){
437+ ///
437438 /// 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"));
440441 ///
441442 /// // Will time out in 1 second unless the nonexistent-pod actually exists
442443 /// let wait_created_result: Result<(), Elapsed> = tokio::time::timeout(
443444 /// Duration::from_secs(1),
444- /// client.wait_created::<Pod>(&client.default_namespace, lp.clone() ),
445+ /// client.wait_created::<Pod>(&client.default_namespace, watcher_config ),
445446 /// )
446447 /// .await;
447448 /// }
448449 /// ```
449450 ///
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 )
451452 where
452453 T : Resource + GetApi + Clone + Debug + DeserializeOwned + Send + ' static ,
453454 <T as Resource >:: DynamicType : Default ,
454455 {
455456 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 ( ) ;
457458 watcher
458459 . applied_objects ( )
459460 . skip_while ( |res| std:: future:: ready ( res. is_err ( ) ) )
@@ -558,7 +559,8 @@ mod tests {
558559 use futures:: StreamExt ;
559560 use k8s_openapi:: api:: core:: v1:: { Container , Pod , PodSpec } ;
560561 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;
562564 use kube:: runtime:: watcher:: Event ;
563565 use std:: collections:: BTreeMap ;
564566 use std:: time:: Duration ;
@@ -595,7 +597,7 @@ mod tests {
595597 . create ( & PostParams :: default ( ) , & pod_to_wait_for)
596598 . await
597599 . expect ( "Test pod not created." ) ;
598- let lp : ListParams = ListParams :: default ( ) . fields ( & format ! (
600+ let watcher_config : watcher :: Config = watcher :: Config :: default ( ) . fields ( & format ! (
599601 "metadata.name={}" ,
600602 created_pod
601603 . metadata
@@ -607,14 +609,14 @@ mod tests {
607609 // Timeout is not acceptable
608610 tokio:: time:: timeout (
609611 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 ( ) ) ,
611613 )
612614 . await
613615 . expect ( "The tested wait_created function timed out." ) ;
614616
615617 // A second, manually constructed watcher is used to verify the ListParams filter out the correct resource
616618 // 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 ( ) ;
618620 while let Some ( result) = ready_watcher. next ( ) . await {
619621 match result {
620622 Ok ( event) => match event {
@@ -649,12 +651,13 @@ mod tests {
649651 . await
650652 . expect ( "KUBECONFIG variable must be configured." ) ;
651653
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" ) ;
653656
654657 // There is no such pod, therefore the `wait_created` function call times out.
655658 let wait_created_result: Result < ( ) , Elapsed > = tokio:: time:: timeout (
656659 Duration :: from_secs ( 1 ) ,
657- client. wait_created :: < Pod > ( & client. default_namespace , lp . clone ( ) ) ,
660+ client. wait_created :: < Pod > ( & client. default_namespace , watcher_config ) ,
658661 )
659662 . await ;
660663
0 commit comments