From 4dfef6962f32a50bc313e5c85706e76ab7ef9c76 Mon Sep 17 00:00:00 2001 From: Manuel Sopena Ballesteros Date: Tue, 5 Nov 2024 19:23:48 +0100 Subject: [PATCH] feat: session creation sync can now print CFS session logs --- src/cfs/session.rs | 50 ++++++++++++++++++++++++++++++++-------- src/common/kubernetes.rs | 2 +- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/cfs/session.rs b/src/cfs/session.rs index 87af491..115fbe2 100644 --- a/src/cfs/session.rs +++ b/src/cfs/session.rs @@ -1159,13 +1159,23 @@ pub mod mesa { pub mod http_client { - use crate::{cfs, error::Error}; + use crate::{ + cfs, + common::{ + kubernetes::{self, print_cfs_session_logs}, + vault::http_client::fetch_shasta_k8s_secrets, + }, + error::Error, + }; use super::{ r#struct::v3::{CfsSessionGetResponse, CfsSessionPostRequest}, wait_cfs_session_to_finish, }; + use futures::TryStreamExt; + use tokio_stream::StreamExt; + /// Fetch CFS sessions ref --> https://apidocs.svc.cscs.ch/paas/cfs/operation/get_sessions/ /// Returns list of CFS sessions ordered by start time. /// This methods filter by either HSM group name or HSM group members or both @@ -1244,7 +1254,12 @@ pub mod mesa { shasta_token: &str, shasta_base_url: &str, shasta_root_cert: &[u8], + vault_base_url: &str, + vault_secret_path: &str, + vault_role_id: &str, + k8s_api_url: &str, session: &CfsSessionPostRequest, + watch_logs: bool, ) -> Result { let cfs_session: CfsSessionGetResponse = cfs::session::mesa::http_client::post( shasta_token, @@ -1256,14 +1271,31 @@ pub mod mesa { let cfs_session_name: String = cfs_session.name.unwrap(); - // Wait till the CFS session finishes - wait_cfs_session_to_finish( - shasta_token, - shasta_base_url, - shasta_root_cert, - &cfs_session_name, - ) - .await; + // FIXME: refactor becase this code is duplicated in command `manta apply sat-file` and also in + // `manta logs` + if watch_logs { + log::info!("Fetching logs ..."); + let shasta_k8s_secrets = + fetch_shasta_k8s_secrets(vault_base_url, vault_secret_path, vault_role_id) + .await; + + let client = + kubernetes::get_k8s_client_programmatically(k8s_api_url, shasta_k8s_secrets) + .await + .unwrap(); + + let _ = print_cfs_session_logs(client, &cfs_session_name).await; + } else { + // User does not want the CFS logs but we still need to wayt the CFS session to + // finis. Wait till the CFS session finishes + wait_cfs_session_to_finish( + shasta_token, + shasta_base_url, + shasta_root_cert, + &cfs_session_name, + ) + .await; + } // Get most recent CFS session status let cfs_session: CfsSessionGetResponse = get( diff --git a/src/common/kubernetes.rs b/src/common/kubernetes.rs index 35a1ad5..6740fb5 100644 --- a/src/common/kubernetes.rs +++ b/src/common/kubernetes.rs @@ -486,7 +486,7 @@ pub async fn get_cfs_session_container_git_clone_logs_stream( .is_some()) && i <= max { - log::info!( + log::debug!( "Init container '{}' state:\n{:?}", git_clone_container.name, init_container_status