Skip to content

Commit

Permalink
get and show pod connection details for livebook smart cell
Browse files Browse the repository at this point in the history
  • Loading branch information
Fadhil committed Sep 30, 2024
1 parent 747cef0 commit 3cbb0dd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cli/src/commands/application/instances/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ struct Status {
struct KubernetesPod {
name: String,
ready: bool,
pod_ip: Option<String>,
node_name: Option<String>,
cookie: Option<String>,
is_livebook: Option<bool>,
}

Expand Down Expand Up @@ -142,6 +145,7 @@ pub async fn handle_connect(
.interact()?;

let instance_name = k8s_pods[instance_name_idx].name.clone();
let instance_object = &k8s_pods[instance_name_idx];

let preparing_loader = new_spinner();
preparing_loader.set_style(spinner_style.clone());
Expand Down Expand Up @@ -271,6 +275,33 @@ pub async fn handle_connect(
);
eprintln!();

match (
&instance_object.node_name,
&instance_object.pod_ip,
&instance_object.cookie,
) {
(Some(node_name), Some(pod_ip), Some(cookie)) => {
eprintln!(
"To connect to mv-wukong-api-proxy, start a new Notebook and click on `+Smart`\nand select `Remote Execution`. Follow the instructions that pop up to restart the Notebook.\nEnter these values into the `NODE` and `COOKIE` input boxes:"
);
eprintln!();
eprintln!("NODE: 🖥️: {}@{}", node_name.cyan(), pod_ip.cyan());
eprintln!("COOKIE: 🍪: {}", cookie.yellow());
}
(None, ..) => {
eprintln!("We were unable to determine the node name for the app node you wish to connect to. Please contact your administrator for assistance.")
}
(_, None, _) => {
eprintln!("We were unable to determine the ip for the app node you wish to connect to. Please contact your administrator for assistance.")
}
(.., None) => {
eprintln!("We were unable to determine the cookie for the app node you wish to connect to. Please contact your administrator for assistance.")
}
}

eprintln!();
eprintln!();

let running_loader = new_spinner();
running_loader
.set_message("Your livebook instance is running. Press Ctrl-C to terminate...");
Expand Down Expand Up @@ -369,6 +400,9 @@ async fn get_ready_k8s_pods(
.map(|pod| KubernetesPod {
name: pod.name,
ready: pod.ready,
pod_ip: pod.pod_ip,
node_name: pod.node_name,
cookie: pod.cookie,
is_livebook: Some(pod.labels.contains(&"livebook".to_string())),
})
.filter(|pod| pod.ready && !pod.is_livebook.unwrap_or_default())
Expand Down
3 changes: 3 additions & 0 deletions sdk/src/graphql/query/kubernetes_pods.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ query KubernetesPodsQuery(
) {
name
podIp
nodeName
cookie
ready
labels

}
}
24 changes: 24 additions & 0 deletions sdk/src/graphql/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3397,6 +3397,30 @@
"ofType": null
}
},
{
"args": [],
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "nodeName",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
{
"args": [],
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "cookie",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
{
"args": [],
"deprecationReason": null,
Expand Down

0 comments on commit 3cbb0dd

Please sign in to comment.