我在集成测试的beforeAll方法中使用java-client for Kubernetes API创建了一个自定义对象。在创建自定义对象之后,还会创建pod。但是,只有当我将Thread.sleep设置为几秒钟时,它才会起作用。如果没有它,就会创建对象,然后执行所有测试。我还定义了对自定义对象状态的监视,但它也没有帮助。有没有其他方法(除了Thread.sleep)可以在创建pods之前保持几秒钟?
我创建自定义对象的代码如下:
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, "&") #> Console.out
serverStartupProcessBuilder.run()
val body = convertYamlToJson()
val sparkAppCreation = apiInstance.createNamespacedCustomObject(crdGroup, crdVersion, crdNamespace, crdPlural, body,"true")
println(sparkAppCreation)
}
发布于 2019-05-23 09:02:02
如果已经创建了pod,您可以在while循环中同步检查:
// 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
https://stackoverflow.com/questions/53815823
复制相似问题