Skip to content

Commit 283dda8

Browse files
committed
fix: regression
* ensure pre and post hooks run in the driver pod by calling run-spark.sh from the image. * give driver pods a stable hostname '<app>-driver' which now differs from the pod name but it keeps backward compatibility relevant for logging.
1 parent fdc2c5c commit 283dda8

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

rust/operator-binary/src/crd/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,8 @@ impl v1alpha2::SparkApplication {
642642
};
643643

644644
let mut submit_cmd = vec![
645-
format!(
646-
"containerdebug --output={VOLUME_MOUNT_PATH_LOG}/containerdebug-state.json --loop &"
647-
),
645+
// containerdebug is started in the background by the image entrypoint (run-spark.sh) via
646+
// the `_STACKABLE_PRE_HOOK` env var, so it must not be repeated here.
648647
build_truststore_commands,
649648
"/stackable/spark/bin/spark-submit".to_string(),
650649
"--verbose".to_string(),

rust/operator-binary/src/spark_k8s_controller.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,11 @@ fn pod_template(
503503
logdir: &Option<ResolvedLogDir>,
504504
spark_image: &ResolvedProductImage,
505505
service_account: &ServiceAccount,
506-
// When set, the spark container runs this command (the spark-submit client invocation). This is
507-
// used for the driver pod, which the operator now launches directly as a Kubernetes Job. When
508-
// `None` (executor pod template), the container relies on the image entrypoint, since Spark sets
509-
// the command on the executor pods it creates.
506+
// When set, the spark container runs this command (the spark-submit client invocation) as the
507+
// container `args`, leaving `command` unset so the image entrypoint (run-spark.sh) is used. This
508+
// is the driver pod, which the operator launches directly as a Kubernetes Job. When `None`
509+
// (executor pod template), the container also relies on the image entrypoint, since Spark sets
510+
// the args on the executor pods it creates.
510511
command: Option<&[String]>,
511512
) -> Result<PodTemplateSpec> {
512513
let container_name = SparkContainer::Spark.to_string();
@@ -543,14 +544,20 @@ fn pod_template(
543544
));
544545
}
545546

546-
cb.command(vec![
547+
// We pass the spark-submit invocation as container `args` and leave `command` unset so the
548+
// image entrypoint (run-spark.sh) runs it. The entrypoint evaluates `_STACKABLE_PRE_HOOK`
549+
// (which starts containerdebug) before, and `_STACKABLE_POST_HOOK` (which writes the Vector
550+
// shutdown file) after the spark-submit process exits. The latter is what lets the Vector
551+
// agent terminate so the driver Job pod can complete. run-spark.sh delegates to Spark's
552+
// entrypoint.sh, which runs our `/bin/bash -c ...` in pass-through mode.
553+
cb.args(vec![
547554
"/bin/bash".to_string(),
548555
"-x".to_string(),
549556
"-euo".to_string(),
550557
"pipefail".to_string(),
551558
"-c".to_string(),
559+
command.join("\n"),
552560
])
553-
.args(vec![command.join("\n")])
554561
.add_env_var("SPARK_SUBMIT_OPTS", spark_submit_opts.join(" "))
555562
// TODO: move this to the image
556563
.add_env_var("SPARK_CONF_DIR", "/stackable/spark/conf");
@@ -909,6 +916,12 @@ fn driver_job(
909916
// A Job's pod must declare a restart policy.
910917
if let Some(spec) = template.spec.as_mut() {
911918
spec.restart_policy = Some("Never".to_string());
919+
// Give the driver pod a stable hostname ending in `-driver`. The Vector agent reports this
920+
// hostname as the `pod` field of every log event (see `log_schema.host_key: pod`), and log
921+
// aggregation/monitoring identifies driver logs by that `-driver` suffix. Without this the
922+
// Job controller's generated pod name (`<app>-<hash>`) would be used, which Spark previously
923+
// avoided by naming the cluster-mode driver pod `<app>-...-driver`.
924+
spec.hostname = Some(spark_application.driver_service_name());
912925
}
913926

914927
let job = Job {

0 commit comments

Comments
 (0)