From fcf9e6f7ce500c4155f91c33e70aeea9b73c60e8 Mon Sep 17 00:00:00 2001 From: Nick Jiang Date: Mon, 2 Sep 2024 10:31:18 -0700 Subject: [PATCH] feat(hydro_deploy): add more error handling --- .../core/src/hydroflow_crate/service.rs | 2 ++ hydro_deploy/core/src/kubernetes/mod.rs | 33 ++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/hydro_deploy/core/src/hydroflow_crate/service.rs b/hydro_deploy/core/src/hydroflow_crate/service.rs index b101d4385046..c8b2f5be6af3 100644 --- a/hydro_deploy/core/src/hydroflow_crate/service.rs +++ b/hydro_deploy/core/src/hydroflow_crate/service.rs @@ -244,7 +244,9 @@ impl Service for HydroflowCrateService { let mut host_write = self.on.write().await; let launched = host_write.provision(resource_result).await; + ProgressTracker::println("About to copy binary!"); launched.copy_binary(built.clone()).await?; + ProgressTracker::println("Done copying binary"); self.launched_host = Some(launched); Ok(()) diff --git a/hydro_deploy/core/src/kubernetes/mod.rs b/hydro_deploy/core/src/kubernetes/mod.rs index 79babdf23740..8f4b62396789 100644 --- a/hydro_deploy/core/src/kubernetes/mod.rs +++ b/hydro_deploy/core/src/kubernetes/mod.rs @@ -153,6 +153,8 @@ impl Host for PodHost { } + ProgressTracker::println("finished provisioning"); + self.launched.as_ref().unwrap().clone() } @@ -241,18 +243,19 @@ impl LaunchedHost for LaunchedPod { async fn copy_binary(&self, binary: Arc<(String, Vec, PathBuf)>) -> Result<()> { // Create a new pod in the running kubernetes cluster (we assume the user already has one up) + ProgressTracker::println("Copying binary to pod"); let client = Client::try_default().await?; let pods: Api = Api::default_namespaced(client); let file_name = format!("hydro-{}-binary", binary.0); - let metadata = std::fs::metadata("/Users/nickjiang/Nick/Hydro/hydroflow/hydro_deploy/core/src/kubernetes/hello_world_aarch64_musl")?; // importantly, this file has executable permissions - + // let metadata = std::fs::metadata("/Users/nickjiang/Nick/Hydro/hydroflow/hydro_deploy/core/src/kubernetes/hello_world_aarch64_musl")?; // importantly, this file has executable permissions { let binary_data = binary.1.clone(); let mut header = tar::Header::new_gnu(); header.set_path(file_name).unwrap(); header.set_size(binary_data.len() as u64); - header.set_metadata(&metadata); + // header.set_metadata(&metadata); + header.set_mode(0o755); // give the binary executable permissions header.set_cksum(); let mut ar = tar::Builder::new(Vec::new()); @@ -265,12 +268,20 @@ impl LaunchedHost for LaunchedPod { .await?; let mut tar_stdin = tar.stdin().unwrap(); tar_stdin.write_all(&data).await?; + ProgressTracker::println("Wrote all the stdin"); // Flush the stdin to finish sending the file through tar_stdin.flush().await?; - tar.join().await?; // TODO: Do something with the result of this + ProgressTracker::println("Flushed!"); + drop(tar_stdin); // Ensure stdin is closed before joining + let result = tar.join().await; + match result { + Ok(_) => ProgressTracker::println("Successfully copied binary to pod"), + Err(e) => ProgressTracker::println(&format!("Failed to copy binary to pod: {:?}", e)), + } } + ProgressTracker::println("Finishd copying binary to pod"); Ok(()) } @@ -281,7 +292,7 @@ impl LaunchedHost for LaunchedPod { binary: Arc<(String, Vec, PathBuf)>, args: &[String], ) -> Result>> { - // ProgressTracker::println("Launching binary in Pod"); + ProgressTracker::println("Launching binary in Pod"); let client = Client::try_default().await?; let pods: Api = Api::default_namespaced(client); @@ -294,9 +305,15 @@ impl LaunchedHost for LaunchedPod { // Execute binary inside the new pod let ap = AttachParams::default().stdin(true).stdout(true).stderr(true); - let mut launch_binary = pods - .exec(pod_name, args_list, &ap) - .await?; + let mut launch_binary = match pods.exec(pod_name, args_list, &ap).await { + Ok(exec) => exec, + Err(e) => { + ProgressTracker::println(&format!("Failed to launch binary in Pod: {:?}", e)); + return Err(e.into()); + } + }; + + // ProgressTracker::println(&format!("Launched binary in pod {:?}", pod_name)); Ok(Arc::new(RwLock::new(LaunchedPodBinary::new( &mut launch_binary, id,