Skip to content

Commit 4264995

Browse files
committed
implement review feedback
1 parent b5676f8 commit 4264995

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

rust/crd/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,21 @@ pub struct JobDependencies {
230230
}
231231

232232
impl SparkApplication {
233+
/// Returns if this [`SparkApplication`] has already created a Kubernetes Job doing the actual `spark-submit`.
234+
///
235+
/// This is needed because Kubernetes will remove the succeeded Job after some time. When the spark-k8s-operator is
236+
/// restarted it would re-create the Job, resulting in the Spark job running multiple times. This function assumes
237+
/// that the [`SparkApplication`]'s status will always be set when the Kubernetes Job is created. It therefore
238+
/// checks if the status is set to determine if the Job was already created in the past.
239+
///
240+
/// See the bug report [#457](https://github.com/stackabletech/spark-k8s-operator/issues/457) for details.
241+
pub fn k8s_job_has_been_created(&self) -> bool {
242+
self.status
243+
.as_ref()
244+
.map(|s| !s.phase.is_empty())
245+
.unwrap_or_default()
246+
}
247+
233248
pub fn submit_job_config_map_name(&self) -> String {
234249
format!("{app_name}-submit-job", app_name = self.name_any())
235250
}

rust/operator-binary/src/spark_k8s_controller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub async fn reconcile(spark_application: Arc<SparkApplication>, ctx: Arc<Ctx>)
175175

176176
let client = &ctx.client;
177177

178-
if spark_application.status.is_some() {
178+
if spark_application.k8s_job_has_been_created() {
179179
tracing::info!(
180180
spark_application = spark_application.name_any(),
181181
"Skipped reconciling SparkApplication with non empty status"

0 commit comments

Comments
 (0)