diff --git a/assets/kino_terminal/main.ts b/assets/kino_terminal/main.ts index cce059d..beba381 100644 --- a/assets/kino_terminal/main.ts +++ b/assets/kino_terminal/main.ts @@ -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 = ` diff --git a/dev.livemd b/dev.livemd index e6146b3..6136045 100644 --- a/dev.livemd +++ b/dev.livemd @@ -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 @@ -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 diff --git a/lib/assets/kino_terminal/main.js b/lib/assets/kino_terminal/main.js index a2d3a89..915ae5a 100644 --- a/lib/assets/kino_terminal/main.js +++ b/lib/assets/kino_terminal/main.js @@ -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>