WebSocketClientHandshakeException when trying to reproduce PodExecTest #5364
-
Hi, while trying to fix some failing tests in my project, I tried to use the I'm using Quarkus 3.2.2 and, thus, the kubernetes-client 6.7.2 with Kotlin. Copying and converting the package rocks.theodolite.kubernetes
import io.fabric8.kubernetes.api.model.*
import io.fabric8.kubernetes.client.dsl.ExecWatch
import io.fabric8.kubernetes.client.server.mock.KubernetesServer
import io.fabric8.kubernetes.client.utils.Serialization
import io.fabric8.mockwebserver.internal.WebSocketMessage
import io.quarkus.test.junit.QuarkusTest
import io.quarkus.test.kubernetes.client.KubernetesTestServer
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer
import org.junit.jupiter.api.*
import java.util.concurrent.TimeUnit
@QuarkusTest
@WithKubernetesTestServer
class PodExecTest {
@KubernetesTestServer
private lateinit var server: KubernetesServer
private val READY = PodStatusBuilder().addNewCondition().withType("Ready").withStatus("True").endCondition().build()
@BeforeEach
fun setUp() {
server.client.pods().inAnyNamespace().delete()
}
@Test
@DisplayName("With single container, should exec in the single container")
fun withSingleContainer() {
server.client.pods().resource(PodBuilder().withNewMetadata().withName("single-container").endMetadata()
.withNewSpec()
.addNewContainer()
.withName("the-single-container")
.endContainer()
.endSpec().withStatus(READY)
.build())
.createOrReplace()
server.expect()
.get()
.withPath(
"/api/v1/namespaces/test/pods/single-container/exec?command=sleep%201&container=the-single-container&stderr=true")
.andUpgradeToWebSocket()
.open()
.immediately().andEmit(exitZeroEvent())
.done()
.always()
val result: ExecWatch = server.client.pods().withName("single-container").redirectingError().exec("sleep 1")
result.exitCode().get(1, TimeUnit.SECONDS)
}
private fun exitZeroEvent(): WebSocketMessage {
val success = StatusBuilder().withStatus("Success").build()
return WebSocketMessage(0L, "\u0003" + Serialization.asJson<Any>(success), false, true)
}
}
When running this test, I get the following exception:
Searching for this error resulted only in #5033, which seems to be not really related. I would be very grateful for any advice how to further debug this and how to find out whether this is somehow related to by project setup or anything else. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
From what I recall the kubernetes mock server is not yet compatible with vertx for exec testing. The underlying ok http server / mock server project does not have support for responding with the appropriate subprotocols. The other client types aren't as strict as vertx. |
Beta Was this translation helpful? Give feedback.
No, this can't be done with the Kubernetes Mock Server.
There's an item in my TODO list to explore replacing the Mock Server backend with something that's not based on OkHttp, but so far I haven't found the time to do so.
Although we don't support it (yet?) you can look into our internal TestStandardHttpClientFactory which you can leverage by adding a
test-jar
dependency.You can then use it to set up and test this scenario using similar expectations to those you provide when using the Mock Server. Check the UploadTest which you may be able to use as reference (it's actually testing a more complex scenario -2 execs-).