gpt4 book ai didi

scala - 保持按住直到创建了pod pod Java客户端Kubernetes

转载 作者:行者123 更新时间:2023-12-02 11:44:03 25 4
gpt4 key购买 nike

我在集成测试的beforeAll方法中使用Java客户端为Kubernetes API创建了一个自定义对象。创建自定义对象后,也会创建 pod 。但是,仅当我将Thread.sleep设置几秒钟时,它才起作用。没有它,将创建对象,然后执行所有测试。我还定义了对自定义对象状态的监视,但它也无济于事。
还有其他方法(Thread.sleep除外)保持几秒钟,直到创建Pod?

我的自定义对象创建代码:

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)
}

最佳答案

您可以在while循环中同步检查是否已创建Pod:

// 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

关于scala - 保持按住直到创建了pod pod Java客户端Kubernetes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53815823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com