diff --git a/CHANGELOG.md b/CHANGELOG.md index 4972f892757..d559a9b62b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,7 @@ Use Kubernetes beta feature `Ephemeral Containers` to mirror traffic with the `- - E2E: Collect minikube logs and fix collecting container logs - E2E: macOS use colima instead of minikube. - Refactored `mirrord-layer/lib.rs` - no more passing many arguments! :) +- Refactored `mirrord-layer/lib.rs` - remove `unwrap()` and propagate error using `Result` ### Fixed - Handle unwraps in fileops to gracefully exit and enable python fileops tests. diff --git a/mirrord-layer/src/pod_api.rs b/mirrord-layer/src/pod_api.rs index 5f52034d77d..1ad460aa493 100644 --- a/mirrord-layer/src/pod_api.rs +++ b/mirrord-layer/src/pod_api.rs @@ -29,9 +29,9 @@ impl RuntimeData { pod_name: &str, pod_namespace: &str, container_name: &Option, - ) -> Self { + ) -> Result { let pods_api: Api = Api::namespaced(client, pod_namespace); - let pod = pods_api.get(pod_name).await.unwrap(); + let pod = pods_api.get(pod_name).await?; let node_name = &pod.spec.unwrap().node_name; let container_statuses = &pod.status.unwrap().container_statuses.unwrap(); let container_info = if let Some(container_name) = container_name { @@ -43,8 +43,7 @@ impl RuntimeData { "no container named {} found in namespace={}, pod={}", &container_name, &pod_namespace, &pod_name ) - }) - .unwrap() + })? .container_id } else { info!("No container name specified, defaulting to first container found"); @@ -65,12 +64,12 @@ impl RuntimeData { let container_id = container_info.last().unwrap(); - RuntimeData { + Ok(RuntimeData { container_id: container_id.to_string(), container_runtime: container_runtime.to_string(), node_name: node_name.as_ref().unwrap().to_string(), socket_path: socket_path.to_string(), - } + }) } } @@ -120,7 +119,7 @@ pub(crate) async fn create_agent( &config, agent_image, &pods_api, - runtime_data, + runtime_data.unwrap(), &jobs_api, connection_port, )