From f0ea4062c5185954b9514fa1171118f00ab28724 Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:47:31 +0100 Subject: [PATCH] feat: run containerdebug in the background --- .../src/history/history_controller.rs | 12 +++++++++--- rust/operator-binary/src/spark_k8s_controller.rs | 5 +++++ tests/templates/kuttl/smoke/06-assert.yaml | 7 +++++++ tests/templates/kuttl/smoke/10-assert.yaml | 7 +++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/rust/operator-binary/src/history/history_controller.rs b/rust/operator-binary/src/history/history_controller.rs index 5149bf4d..9637658b 100644 --- a/rust/operator-binary/src/history/history_controller.rs +++ b/rust/operator-binary/src/history/history_controller.rs @@ -527,7 +527,13 @@ fn build_stateful_set( .context(InvalidContainerNameSnafu)? .image_from_product_image(resolved_product_image) .resources(merged_config.resources.clone().into()) - .command(vec!["/bin/bash".to_string()]) + .command(vec![ + "/bin/bash".to_string(), + "-x".to_string(), + "-euo".to_string(), + "pipefail".to_string(), + "-c".to_string(), + ]) .args(command_args(log_dir)) .add_container_port("http", 18080) .add_container_port("metrics", METRICS_PORT.into()) @@ -751,10 +757,10 @@ fn command_args(logdir: &ResolvedLogDir) -> Vec { } command.extend(vec![ + format!("CONTAINERDEBUG_LOG_DIRECTORY={VOLUME_MOUNT_PATH_LOG}/containerdebug containerdebug --output={VOLUME_MOUNT_PATH_LOG}/containerdebug-state.json --loop &"), format!("/stackable/spark/sbin/start-history-server.sh --properties-file {VOLUME_MOUNT_PATH_CONFIG}/{SPARK_DEFAULTS_FILE_NAME}"), ]); - - vec![String::from("-c"), command.join(" && ")] + vec![command.join("\n")] } fn labels<'a, T>( diff --git a/rust/operator-binary/src/spark_k8s_controller.rs b/rust/operator-binary/src/spark_k8s_controller.rs index ccb9eb84..40020f51 100644 --- a/rust/operator-binary/src/spark_k8s_controller.rs +++ b/rust/operator-binary/src/spark_k8s_controller.rs @@ -594,6 +594,11 @@ fn pod_template( .resources(config.resources.clone().into()) .image_from_product_image(spark_image); + cb.add_env_var( + "_STACKABLE_PRE_HOOK", + format!("CONTAINERDEBUG_LOG_DIRECTORY={VOLUME_MOUNT_PATH_LOG}/containerdebug containerdebug --output={VOLUME_MOUNT_PATH_LOG}/containerdebug-state.json --loop &"), + ); + if config.logging.enable_vector_agent { cb.add_env_var( "_STACKABLE_POST_HOOK", diff --git a/tests/templates/kuttl/smoke/06-assert.yaml b/tests/templates/kuttl/smoke/06-assert.yaml index 68c0e487..386ee1fb 100644 --- a/tests/templates/kuttl/smoke/06-assert.yaml +++ b/tests/templates/kuttl/smoke/06-assert.yaml @@ -9,3 +9,10 @@ metadata: name: spark-history-node-default status: readyReplicas: 1 +--- +# This test checks if the containerdebug-state.json file is present and valid +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 600 +commands: + - script: kubectl exec -n $NAMESPACE --container airflow spark-history-node-default-0 -- cat /stackable/log/containerdebug-state.json | jq --exit-status diff --git a/tests/templates/kuttl/smoke/10-assert.yaml b/tests/templates/kuttl/smoke/10-assert.yaml index 38367193..9ac8d04e 100644 --- a/tests/templates/kuttl/smoke/10-assert.yaml +++ b/tests/templates/kuttl/smoke/10-assert.yaml @@ -9,3 +9,10 @@ metadata: name: spark-pi-s3-1 status: phase: Succeeded +--- +# This test checks if the containerdebug-state.json file is present and valid +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 600 +commands: + - script: kubectl exec -n $NAMESPACE --container airflow spark-history-node-default-0 -- cat /stackable/log/containerdebug-state.json | jq --exit-status