Skip to content

Commit 31f099a

Browse files
committed
Added owner-ref to pod templates (#104)
# Description - added an owner-reference to the pod templates for driver and executor(s) so that their pods are cleaned up along with the SparkApplication - also fixed broken file name in one of the examples
1 parent d8b1757 commit 31f099a

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ All notable changes to this project will be documented in this file.
99
- Include chart name when installing with a custom release name ([#97])
1010
- Pinned MinIO version for tests ([#100])
1111
- `operator-rs` `0.21.0``0.22.0` ([#102]).
12+
- Added owner-reference to pod templates ([#104])
1213

1314
[#97]: https://github.com/stackabletech/spark-k8s-operator/pull/92
1415
[#100]: https://github.com/stackabletech/spark-k8s-operator/pull/100
1516
[#102]: https://github.com/stackabletech/spark-k8s-operator/pull/102
17+
[#104]: https://github.com/stackabletech/spark-k8s-operator/pull/104
1618

1719
## [0.3.0] - 2022-06-30
1820

examples/ny-tlc-report-external-dependencies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spec:
1010
# Always | IfNotPresent | Never
1111
sparkImagePullPolicy: IfNotPresent
1212
mode: cluster
13-
mainApplicationFile: s3a://my-bucket/ny-tlc-report.py
13+
mainApplicationFile: s3a://my-bucket/ny_tlc_report.py
1414
args:
1515
- "--input 's3a://my-bucket/yellow_tripdata_2021-07.csv'"
1616
deps:

rust/crd/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ mod tests {
485485
use crate::ImagePullPolicy;
486486
use crate::LocalObjectReference;
487487
use crate::SparkApplication;
488+
use stackable_operator::builder::ObjectMetaBuilder;
488489
use stackable_operator::commons::s3::{
489490
S3AccessStyle, S3BucketSpec, S3ConnectionDef, S3ConnectionSpec,
490491
};
@@ -609,6 +610,7 @@ kind: SparkApplication
609610
metadata:
610611
name: ny-tlc-report-external-dependencies
611612
namespace: default
613+
uid: 12345678asdfghj
612614
spec:
613615
version: "1.0"
614616
sparkImage: docker.stackable.tech/stackable/spark-k8s:3.2.1-hadoop3.2-python39-aws1.11.375-stackable0.3.0
@@ -631,6 +633,14 @@ spec:
631633
memory: "512m"
632634
"#).unwrap();
633635

636+
let meta = ObjectMetaBuilder::new()
637+
.name_and_namespace(&spark_application)
638+
.ownerreference_from_resource(&spark_application, None, Some(true))
639+
.unwrap()
640+
.build();
641+
642+
assert_eq!("12345678asdfghj", meta.owner_references.unwrap()[0].uid);
643+
634644
assert_eq!("1.0", spark_application.spec.version.unwrap_or_default());
635645
assert_eq!(
636646
Some("s3a://stackable-spark-k8s-jars/jobs/ny_tlc_report.py".to_string()),

rust/operator-binary/src/spark_k8s_controller.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ fn pod_template(
253253
Ok(Pod {
254254
metadata: ObjectMetaBuilder::new()
255255
.name(container_name)
256+
// this reference is not pointing to a controller but only provides a UID that can used to clean up resources
257+
// cleanly (specifically driver pods and related config maps) when the spark application is deleted.
258+
.ownerreference_from_resource(spark_application, None, None)
259+
.context(ObjectMissingMetadataForOwnerRefSnafu)?
256260
.with_labels(spark_application.recommended_labels())
257261
.build(),
258262
spec: Some(pod_spec),

0 commit comments

Comments
 (0)