From 6008a8f94150c30a7029f4eb86ef17bf6e256a9f Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Sat, 14 Dec 2024 14:46:20 +0100 Subject: [PATCH] reintroduce the CONTAINERDEBUG_LOG_DIRECTORY env var --- rust/crd/src/history.rs | 10 +++++++ rust/crd/src/lib.rs | 9 +++++++ .../src/spark_k8s_controller.rs | 26 ++++++++++++++++--- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/rust/crd/src/history.rs b/rust/crd/src/history.rs index 1ca93081..55b9f4be 100644 --- a/rust/crd/src/history.rs +++ b/rust/crd/src/history.rs @@ -242,6 +242,16 @@ impl SparkHistoryServer { let mut vars: BTreeMap = BTreeMap::new(); let role_env_overrides = &self.role().config.env_overrides; + // Needed by the `containerdebug` running in the background of the history container + // to log it's tracing information to. + vars.insert( + "CONTAINERDEBUG_LOG_DIRECTORY".to_string(), + EnvVar { + name: "CONTAINERDEBUG_LOG_DIRECTORY".to_string(), + value: Some(format!("{VOLUME_MOUNT_PATH_LOG}/containerdebug")), + value_from: None, + }, + ); // This env var prevents the history server from detaching itself from the // start script because this leads to the Pod terminating immediately. vars.insert( diff --git a/rust/crd/src/lib.rs b/rust/crd/src/lib.rs index 3f85f2d8..9a8bb704 100644 --- a/rust/crd/src/lib.rs +++ b/rust/crd/src/lib.rs @@ -692,6 +692,15 @@ impl SparkApplication { logdir: &Option, ) -> Vec { let mut e: Vec = self.spec.env.clone(); + + // Needed by the `containerdebug` process running in the background of the `spark-submit` + // container to log it's tracing information to. + e.push(EnvVar { + name: "CONTAINERDEBUG_LOG_DIRECTORY".to_string(), + value: Some(format!("{VOLUME_MOUNT_PATH_LOG}/containerdebug")), + value_from: None, + }); + if self.requirements().is_some() { e.push(EnvVar { name: "PYTHONPATH".to_string(), diff --git a/rust/operator-binary/src/spark_k8s_controller.rs b/rust/operator-binary/src/spark_k8s_controller.rs index d08f0142..7bcef777 100644 --- a/rust/operator-binary/src/spark_k8s_controller.rs +++ b/rust/operator-binary/src/spark_k8s_controller.rs @@ -612,11 +612,29 @@ fn pod_template( .resources(config.resources.clone().into()) .image_from_product_image(spark_image); - cb.add_env_var( - "_STACKABLE_PRE_HOOK", - format!( + // These env variables enable the `containerdebug` process in driver and executor pods. + // More precisely, this process runs in the background of every `spark` container. + // - `CONTAINERDEBUG_LOG_DIRECTORY` - is the location where tracing information from the process + // is written. This directory is created by the process it's self. + // - `_STACKABLE_PRE_HOOK` - is evaluated by the entrypoint script (run-spark.sh) in the Spark images + // before the actual JVM process is started. The result of this evaluation is that the + // `containerdebug` process is executed in the background. + cb.add_env_vars( + [ + EnvVar { + name: "CONTAINERDEBUG_LOG_DIRECTORY".into(), + value: Some(format!("{VOLUME_MOUNT_PATH_LOG}/containerdebug")), + value_from: None, + }, + EnvVar { + name: "_STACKABLE_PRE_HOOK".into(), + value: Some(format!( "containerdebug --output={VOLUME_MOUNT_PATH_LOG}/containerdebug-state.json --loop &" - ), + )), + value_from: None, + }, + ] + .into(), ); if config.logging.enable_vector_agent {