kuberneteswebsocket

WebSocket Connection to KubeVirt Console Established, but No TTY Output


I'm currently facing an issue when trying to connect to the KubeVirt VirtualMachineInstance (VMI) console serial using a WebSocket client.

Implementation:

The WebSocket is initialized as follows:

const targetUrl = `${apiServer}/apis/subresources.kubevirt.io/v1alpha3/namespaces/${namespace}/virtualmachineinstances/${vmi}/console`;

const ws = new WebSocket(targetUrl, {
  headers: {
    Authorization: `Bearer ${token}`,
    "Sec-WebSocket-Protocol": "base64.channel.kubevirt.io",
  },
  rejectUnauthorized: false,
});
proxySocket.on("open", () => {
  socket.emit("data", "Connected To VM WS");
  console.log("KubeVirt WS connected");
});

proxySocket.on("message", (data) => {
  console.log("Received data:", data);
});

WebSocket Behavior:

If anyone's run into this before or has any idea what I might be missing, I'd really appreciate the help. Thanks a bunch!


Solution

  • After conducting further research, I was able to resolve the issue independently. The solution involved converting the string into an ASCII array before sending it through the WebSocket.

            const enc = new TextEncoder().encode(data);
            proxySocket.send(enc);