private void waitUntilPodsAreReady ( final T obj , final String namespace , final int requiredPodCount ) { final CountDownLatch countDownLatch = new CountDownLatch ( 1 ) ; final AtomicInteger podCount = new AtomicInteger ( 0 ) ; final Runnable readyPodsPoller = ( ) -> { PodList podList = listSelectedPods ( obj ) ; int count = 0 ; List < Pod > items = podList . getItems ( ) ; for ( Pod item : items ) { for ( PodCondition c : item . getStatus ( ) . getConditions ( ) ) { if ( c . getType ( ) . equals ( "Ready" ) && c . getStatus ( ) . equals ( "True" ) ) { count ++ ; } } } podCount . set ( count ) ; if ( count == requiredPodCount ) { countDownLatch . countDown ( ) ; } } ; ScheduledExecutorService executor = Executors . newSingleThreadScheduledExecutor ( ) ; ScheduledFuture poller = executor . scheduleWithFixedDelay ( readyPodsPoller , 0 , 1 , TimeUnit . SECONDS ) ; ScheduledFuture logger = executor . scheduleWithFixedDelay ( ( ) -> LOG . debug ( "Only {}/{} pod(s) ready for {}: {} in namespace: {} seconds so waiting..." , podCount . get ( ) , requiredPodCount , obj . getKind ( ) , obj . getMetadata ( ) . getName ( ) , namespace ) , 0 , loggingIntervalMillis , TimeUnit . MILLISECONDS ) ; try { countDownLatch . await ( rollingTimeoutMillis , TimeUnit . MILLISECONDS ) ; executor . shutdown ( ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; poller . cancel ( true ) ; logger . cancel ( true ) ; executor . shutdown ( ) ; LOG . warn ( "Only {}/{} pod(s) ready for {}: {} in namespace: {} after waiting for {} seconds so giving up" , podCount . get ( ) , requiredPodCount , obj . getKind ( ) , obj . getMetadata ( ) . getName ( ) , namespace , TimeUnit . MILLISECONDS . toSeconds ( rollingTimeoutMillis ) ) ; } }
Lets wait until there are enough Ready pods of the given RC