首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按住直到创建了pod java-client Kubernetes

按住直到创建了pod java-client Kubernetes
EN

Stack Overflow用户
提问于 2018-12-17 21:02:41
回答 1查看 187关注 0票数 2

我在集成测试的beforeAll方法中使用java-client for Kubernetes API创建了一个自定义对象。在创建自定义对象之后,还会创建pod。但是,只有当我将Thread.sleep设置为几秒钟时,它才会起作用。如果没有它,就会创建对象,然后执行所有测试。我还定义了对自定义对象状态的监视,但它也没有帮助。有没有其他方法(除了Thread.sleep)可以在创建pods之前保持几秒钟?

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

代码语言:javascript
复制
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)
}
EN

回答 1

Stack Overflow用户

发布于 2019-05-23 17:02:02

如果已经创建了pod,您可以在while循环中同步检查:

代码语言:javascript
复制
// 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53815823

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档