Skip to content

Commit

Permalink
chores: Upgrade xterm.js to 5.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mruoss committed Nov 29, 2023
1 parent 2cb4bd4 commit 1d3ebac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 66 deletions.
4 changes: 2 additions & 2 deletions assets/kino_terminal/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { KinoTerminalAttrs } from './types'

export async function init(ctx: KinoContext, attrs: KinoTerminalAttrs) {
await ctx.importCSS(
'https://cdn.jsdelivr.net/npm/xterm@5.0.0/css/xterm.min.css',
'https://cdn.jsdelivr.net/npm/xterm@5.3.0/css/xterm.min.css',
)
await ctx.importJS(
'https://cdn.jsdelivr.net/npm/xterm@5.0.0/lib/xterm.min.js',
'https://cdn.jsdelivr.net/npm/xterm@5.3.0/lib/xterm.min.js',
)

ctx.root.innerHTML = `
Expand Down
80 changes: 17 additions & 63 deletions dev.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -19,71 +19,38 @@ Mix.install([{:kino_k8s, path: "~/src/community/kino_k8s"}])
conn
```

<!-- livebook:{"attrs":{"connection":{"conn_hash":100330371,"variable":"conn"},"connections":[{"conn_hash":100330371,"variable":"conn"}],"gvk":null,"namespace":null,"namespaces":null,"request_type":"get","request_types":["get","list","watch"],"resource":null,"resources":null,"result_type":null,"result_types":{"get":null,"list":["list","stream"],"watch":["stream"]},"result_variable":"result"},"chunks":null,"kind":"Elixir.KinoK8s.GetCell","livebook_object":"smart_cell"} -->

```elixir

```
<!-- livebook:{"attrs":{"connect_to":"exec","connect_tos":["exec","logs"],"connection":{"conn_hash":100330371,"variable":"conn"},"connections":[{"conn_hash":100330371,"variable":"conn"}],"container":"busybox","containers":["busybox"],"namespace":"kino-k8s","namespaces":["default","kino-k8s","kube-node-lease","kube-public","kube-system","local-path-storage"],"pod":"busybox","pods":["busybox"]},"chunks":null,"kind":"Elixir.KinoK8s.TerminalCell","livebook_object":"smart_cell"} -->

```elixir
connect_to_pod = fn terminal_kino_pid ->
{:ok, send_to_websocket} =
K8s.Client.connect("v1", "pods/exec", [namespace: "kino-k8s", name: "busybox"],
container: "busybox",
command: "/bin/sh",
tty: true
)
|> K8s.Client.put_conn(conn)
|> K8s.Client.stream_to(terminal_kino_pid)

```

```elixir
{:ok, admin_token} =
K8s.Client.get("v1", "secrets", name: "ns-admin-token", namespace: "kino-k8s")
|> K8s.Client.put_conn(conn)
|> K8s.Client.run()

{:ok, ca_cert} = K8s.Conn.PKI.cert_from_base64(admin_token["data"]["ca.crt"])
send_to_websocket
end

admin_conn =
struct!(conn,
ca_cert: ca_cert,
auth: %K8s.Conn.Auth.Token{token: Base.decode64!(admin_token["data"]["token"])},
namespace: Base.decode64!(admin_token["data"]["namespace"])
)
KinoK8s.KinoTerminal.open(connect_to_pod)
```

```elixir
{:ok, cluster_admin_token} =
K8s.Client.get("v1", "secrets", name: "cluster-admin-token", namespace: "kino-k8s")
|> K8s.Client.put_conn(conn)
|> K8s.Client.run()

{:ok, ca_cert} = K8s.Conn.PKI.cert_from_base64(cluster_admin_token["data"]["ca.crt"])

cluster_admin_conn =
struct!(conn,
ca_cert: ca_cert,
auth: %K8s.Conn.Auth.Token{token: Base.decode64!(cluster_admin_token["data"]["token"])},
namespace: Base.decode64!(cluster_admin_token["data"]["namespace"])
)
```
<!-- livebook:{"attrs":{"connection":{"conn_hash":100330371,"variable":"conn"},"connections":[{"conn_hash":100330371,"variable":"conn"}],"gvk":null,"namespace":null,"namespaces":null,"request_type":"get","request_types":["get","list","watch"],"resource":null,"resources":null,"result_type":null,"result_types":{"get":null,"list":["list","stream"],"watch":["stream"]},"result_variable":"result"},"chunks":null,"kind":"Elixir.KinoK8s.GetCell","livebook_object":"smart_cell"} -->

```elixir
{:ok, cm_pod_reader_token} =
K8s.Client.get("v1", "secrets", name: "cm-pod-reader-token", namespace: "kino-k8s")
|> K8s.Client.put_conn(conn)
|> K8s.Client.run()

{:ok, ca_cert} = K8s.Conn.PKI.cert_from_base64(cm_pod_reader_token["data"]["ca.crt"])

cm_pod_reader_conn =
struct!(conn,
ca_cert: ca_cert,
auth: %K8s.Conn.Auth.Token{token: Base.decode64!(cm_pod_reader_token["data"]["token"])},
namespace: Base.decode64!(cm_pod_reader_token["data"]["namespace"])
)
```

<!-- livebook:{"attrs":{"connection":{"conn_hash":100330371,"variable":"conn"},"connections":[{"conn_hash":100330371,"variable":"conn"},{"conn_hash":105793204,"variable":"cm_pod_reader_conn"},{"conn_hash":97020151,"variable":"cluster_admin_conn"},{"conn_hash":21208925,"variable":"admin_conn"}],"gvk":null,"namespace":null,"namespaces":null,"request_type":"get","request_types":["get","list","watch"],"resource":null,"resources":null,"result_type":null,"result_types":{"get":null,"list":["list","stream"],"watch":["stream"]},"result_variable":"result2"},"chunks":null,"kind":"Elixir.KinoK8s.GetCell","livebook_object":"smart_cell"} -->
<!-- livebook:{"attrs":{"connection":{"conn_hash":100330371,"variable":"conn"},"connections":[{"conn_hash":100330371,"variable":"conn"}],"gvk":null,"namespace":null,"namespaces":null,"request_type":"get","request_types":["get","list","watch"],"resource":null,"resources":null,"result_type":null,"result_types":{"get":null,"list":["list","stream"],"watch":["stream"]},"result_variable":"result2"},"chunks":null,"kind":"Elixir.KinoK8s.GetCell","livebook_object":"smart_cell"} -->

```elixir

```

<!-- livebook:{"attrs":{"body":"apiVersion: v1\nkind: Pod\nmetadata:\n name: busybox\n namespace: kino-k8s\nspec:\n containers:\n - image: busybox\n command:\n - sleep\n - \"3600\"\n imagePullPolicy: IfNotPresent\n name: busybox\n restartPolicy: Always","connection":{"conn_hash":100330371,"variable":"conn"},"connections":[{"conn_hash":100330371,"variable":"conn"},{"conn_hash":105793204,"variable":"cm_pod_reader_conn"},{"conn_hash":97020151,"variable":"cluster_admin_conn"},{"conn_hash":21208925,"variable":"admin_conn"}],"method":"apply","methods":["apply","create","update"],"result_variable":"applied_resource"},"chunks":null,"kind":"Elixir.KinoK8s.ApplyCell","livebook_object":"smart_cell"} -->
<!-- livebook:{"attrs":{"body":"apiVersion: v1\nkind: Pod\nmetadata:\n name: busybox\n namespace: kino-k8s\nspec:\n containers:\n - image: busybox\n command:\n - sleep\n - \"3600\"\n imagePullPolicy: IfNotPresent\n name: busybox\n restartPolicy: Always","connection":{"conn_hash":100330371,"variable":"conn"},"connections":[{"conn_hash":100330371,"variable":"conn"}],"method":"apply","methods":["apply","create","update"],"result_variable":"applied_resource"},"chunks":null,"kind":"Elixir.KinoK8s.ApplyCell","livebook_object":"smart_cell"} -->

````elixir
import YamlElixir.Sigil
Expand Down Expand Up @@ -117,23 +84,10 @@ Kino.Markdown.new("#### Applied Resource:
")
````

<!-- livebook:{"attrs":{"connect_to":"logs","connect_tos":["exec","logs"],"connection":{"conn_hash":105793204,"variable":"cm_pod_reader_conn"},"connections":[{"conn_hash":100330371,"variable":"conn"},{"conn_hash":105793204,"variable":"cm_pod_reader_conn"},{"conn_hash":97020151,"variable":"cluster_admin_conn"},{"conn_hash":21208925,"variable":"admin_conn"}],"container":"busybox","containers":["busybox"],"namespace":"kino-k8s","namespaces":[],"pod":"busybox","pods":[]},"chunks":null,"kind":"Elixir.KinoK8s.TerminalCell","livebook_object":"smart_cell"} -->
<!-- livebook:{"attrs":{"connect_to":"logs","connect_tos":["exec","logs"],"connection":{"conn_hash":100330371,"variable":"conn"},"connections":[{"conn_hash":100330371,"variable":"conn"}],"container":null,"containers":null,"namespace":"default","namespaces":["default","kino-k8s","kube-node-lease","kube-public","kube-system","local-path-storage"],"pod":null,"pods":[]},"chunks":null,"kind":"Elixir.KinoK8s.TerminalCell","livebook_object":"smart_cell"} -->

```elixir
connect_to_pod = fn terminal_kino_pid ->
{:ok, send_to_websocket} =
K8s.Client.connect("v1", "pods/log", [namespace: "kino-k8s", name: "busybox"],
container: "busybox",
tailLines: 100,
follow: true
)
|> K8s.Client.put_conn(cm_pod_reader_conn)
|> K8s.Client.stream_to(terminal_kino_pid)

send_to_websocket
end

KinoK8s.KinoTerminal.open(connect_to_pod)
```

```elixir
Expand Down
2 changes: 1 addition & 1 deletion lib/assets/kino_terminal/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
async function o(n,r){await n.importCSS("https://cdn.jsdelivr.net/npm/xterm@5.0.0/css/xterm.min.css"),await n.importJS("https://cdn.jsdelivr.net/npm/xterm@5.0.0/lib/xterm.min.js"),n.root.innerHTML=`
async function o(n,r){await n.importCSS("https://cdn.jsdelivr.net/npm/xterm@5.3.0/css/xterm.min.css"),await n.importJS("https://cdn.jsdelivr.net/npm/xterm@5.3.0/lib/xterm.min.js"),n.root.innerHTML=`
<div id="k8s-terminal">
<div class="k8s-xtermjs-container"></div>
</div>
Expand Down

0 comments on commit 1d3ebac

Please sign in to comment.