Title: Hold until pods are created java-client Kubernetes
Tags: scala;kubernetes
Question: I create a custom object using java-client for Kubernetes API in the beforeAll method of the integration tests. After the custom object is created the pods get created too. However, it only works when I set Thread.sleep for a few seconds. Without it, the object is created and then all the tests executed. I also defined watch on custom object statuses, but it does not help either.
Is there any other way (except for Thread.sleep) to hold for a few seconds until the pods get created?

My code for the custom object creation:

```def createWatchCustomObjectsCalls() = {
    client.getHttpClient.setReadTimeout(0, TimeUnit.SECONDS)
    val watchCalls: Watch[V1Namespace]  = Watch.createWatch(client,
      apiInstance.listNamespacedCustomObjectCall(crdGroup, crdVersion,  crdNamespace, crdPlural, "true",  null, null, true,null,  null),
      new TypeToken[Watch.Response[V1Namespace]]{}.getType)
    watchCalls
  }

 override def beforeAll(): Unit = {
    val creationResourcePath = Source.getClass.getResource("/" + httpServerScriptName).getPath
    val serverStartupProcessBuilder = Seq("sh", creationResourcePath, "&amp;") #&gt; Console.out
    serverStartupProcessBuilder.run()

    val body = convertYamlToJson()
    val sparkAppCreation = apiInstance.createNamespacedCustomObject(crdGroup, crdVersion, crdNamespace, crdPlural, body,"true")
    println(sparkAppCreation)
}
```



Here is another answer: You can synchronously check in a while loop if pods had been created:

```// while
val currentPodList = getCoreV1Api()
                    .listPodForAllNamespaces(null /* _continue */,
                                            null /* fieldSelector */,
                                            null /* includeUninitialized */,
                                            null /* labelSelector */,
                                            null /* limit */,
                                            "false" /* pretty */,
                                            null /* resourceVersion */,
                                            null /* timeoutSeconds */,
                                            false /* watch */)
                    .getItems();
// check items from currentPodList
// end while
```


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:12/17/18', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<scala><kubernetes>', 'Title': 'Hold until pods are created java-client Kubernetes', 'ViewCount': 211, 'id': 53815823, 'user_AboutMe': '<p>Data Engineer</p>\n', 'user_AccountId': 7099483.0, 'user_DisplayName': 'Cassie', 'user_Reputation': 2701.0, 'user_Views': 1239.0, 'user_id': 5431681.0}}