Skip to content

Commit d485719

Browse files
committed
Configure node selection (#76)
Fixes #3
1 parent 0205e60 commit d485719

File tree

18 files changed

+217
-73
lines changed

18 files changed

+217
-73
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ All notable changes to this project will be documented in this file.
77
### Added
88

99
- Added new fields to govern image pull policy ([#75])
10+
- New `nodeSelector` fields for both the driver and the excutors ([#76])
1011

1112
[#75]: https://github.com/stackabletech/spark-k8s-operator/pull/75
13+
[#76]: https://github.com/stackabletech/spark-k8s-operator/pull/76
1214

1315
### Changed
1416

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/crd/sparkapplication.crd.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ spec:
9696
memory:
9797
nullable: true
9898
type: string
99+
nodeSelector:
100+
additionalProperties:
101+
type: string
102+
nullable: true
103+
type: object
99104
volumeMounts:
100105
items:
101106
description: VolumeMount describes a mounting of a Volume within a container.
@@ -222,6 +227,11 @@ spec:
222227
memory:
223228
nullable: true
224229
type: string
230+
nodeSelector:
231+
additionalProperties:
232+
type: string
233+
nullable: true
234+
type: object
225235
volumeMounts:
226236
items:
227237
description: VolumeMount describes a mounting of a Volume within a container.

deploy/helm/spark-k8s-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
apiVersion: v2
33
name: spark-k8s-operator
4-
version: "0.1.0"
5-
appVersion: "0.1.0"
4+
version: "0.2.0-nightly"
5+
appVersion: "0.2.0-nightly"
66
description: The Stackable Operator for Apache Spark-on-Kubernetes
77
home: https://github.com/stackabletech/spark-k8s-operator
88
maintainers:

deploy/helm/spark-k8s-operator/crds/crds.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ spec:
9898
memory:
9999
nullable: true
100100
type: string
101+
nodeSelector:
102+
additionalProperties:
103+
type: string
104+
nullable: true
105+
type: object
101106
volumeMounts:
102107
items:
103108
description: VolumeMount describes a mounting of a Volume within a container.
@@ -224,6 +229,11 @@ spec:
224229
memory:
225230
nullable: true
226231
type: string
232+
nodeSelector:
233+
additionalProperties:
234+
type: string
235+
nullable: true
236+
type: object
227237
volumeMounts:
228238
items:
229239
description: VolumeMount describes a mounting of a Volume within a container.

deploy/manifests/configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,4 @@ metadata:
284284
labels:
285285
app.kubernetes.io/name: spark-k8s-operator
286286
app.kubernetes.io/instance: spark-k8s-operator
287-
app.kubernetes.io/version: "0.1.0"
287+
app.kubernetes.io/version: "0.2.0-nightly"

deploy/manifests/crds.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ spec:
9999
memory:
100100
nullable: true
101101
type: string
102+
nodeSelector:
103+
additionalProperties:
104+
type: string
105+
nullable: true
106+
type: object
102107
volumeMounts:
103108
items:
104109
description: VolumeMount describes a mounting of a Volume within a container.
@@ -225,6 +230,11 @@ spec:
225230
memory:
226231
nullable: true
227232
type: string
233+
nodeSelector:
234+
additionalProperties:
235+
type: string
236+
nullable: true
237+
type: object
228238
volumeMounts:
229239
items:
230240
description: VolumeMount describes a mounting of a Volume within a container.

deploy/manifests/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
labels:
77
app.kubernetes.io/name: spark-k8s-operator
88
app.kubernetes.io/instance: spark-k8s-operator
9-
app.kubernetes.io/version: "0.1.0"
9+
app.kubernetes.io/version: "0.2.0-nightly"
1010
spec:
1111
replicas: 1
1212
strategy:
@@ -26,7 +26,7 @@ spec:
2626
containers:
2727
- name: spark-k8s-operator
2828
securityContext: {}
29-
image: "docker.stackable.tech/stackable/spark-k8s-operator:0.1.0"
29+
image: "docker.stackable.tech/stackable/spark-k8s-operator:0.2.0-nightly"
3030
imagePullPolicy: IfNotPresent
3131
resources: {}
3232
volumeMounts:

deploy/manifests/serviceaccount.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
labels:
77
app.kubernetes.io/name: spark-k8s-operator
88
app.kubernetes.io/instance: spark-k8s-operator
9-
app.kubernetes.io/version: "0.1.0"
9+
app.kubernetes.io/version: "0.2.0-nightly"
1010
---
1111
apiVersion: rbac.authorization.k8s.io/v1
1212
# This cluster role binding allows anyone in the "manager" group to read secrets in any namespace.
@@ -16,7 +16,7 @@ metadata:
1616
labels:
1717
app.kubernetes.io/name: spark-k8s-operator
1818
app.kubernetes.io/instance: spark-k8s-operator
19-
app.kubernetes.io/version: "0.1.0"
19+
app.kubernetes.io/version: "0.2.0-nightly"
2020
subjects:
2121
- kind: ServiceAccount
2222
name: spark-k8s-operator-serviceaccount

docs/antora.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: spark-k8s
3-
version: "0.1"
3+
version: "nightly"
44
title: Stackable Operator for Apache Spark on Kubernetes
55
nav:
66
- modules/ROOT/nav.adoc
7-
prerelease: false
7+
prerelease: true

docs/modules/ROOT/pages/usage.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ Below are listed the CRD fields that can be defined by the user:
259259
|`spec.driver.volumeMounts.mountPath`
260260
|Volume mount path
261261

262+
|`spec.driver.nodeSelector`
263+
|A dictionary of labels to use for node selection when scheduling the driver N.B. this assumes there are no implicit node dependencies (e.g. `PVC`, `VolumeMount`) defined elsewhere.
264+
262265
|`spec.executor.cores`
263266
|Number of cores for each executor
264267

@@ -276,5 +279,8 @@ Below are listed the CRD fields that can be defined by the user:
276279

277280
|`spec.executor.volumeMounts.mountPath`
278281
|Volume mount path
282+
283+
|`spec.executor.nodeSelector`
284+
|A dictionary of labels to use for node selection when scheduling the executors N.B. this assumes there are no implicit node dependencies (e.g. `PVC`, `VolumeMount`) defined elsewhere.
279285
|===
280286

rust/crd/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
license = "OSL-3.0"
66
name = "stackable-spark-k8s-crd"
77
repository = "https://github.com/stackabletech/spark-k8s-operator"
8-
version = "0.1.0"
8+
version = "0.2.0-nightly"
99

1010
[dependencies]
1111
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag="0.19.0" }

rust/crd/src/lib.rs

Lines changed: 99 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
pub mod constants;
44

55
use constants::*;
6+
use stackable_operator::builder::VolumeBuilder;
67
use stackable_operator::commons::s3::{InlinedS3BucketSpec, S3BucketDef};
78
use stackable_operator::k8s_openapi::api::core::v1::{
8-
EnvVar, EnvVarSource, LocalObjectReference, SecretKeySelector, Volume, VolumeMount,
9+
EmptyDirVolumeSource, EnvVar, EnvVarSource, LocalObjectReference, SecretKeySelector, Volume,
10+
VolumeMount,
911
};
1012

1113
use std::collections::{BTreeMap, HashMap};
@@ -160,28 +162,89 @@ impl SparkApplication {
160162
}
161163

162164
pub fn volumes(&self) -> Vec<Volume> {
163-
let tmp = self.spec.volumes.as_ref();
164-
tmp.iter().flat_map(|v| v.iter()).cloned().collect()
165+
let mut result: Vec<Volume> = self
166+
.spec
167+
.volumes
168+
.as_ref()
169+
.iter()
170+
.flat_map(|v| v.iter())
171+
.cloned()
172+
.collect();
173+
174+
if self.spec.image.is_some() {
175+
result.push(
176+
VolumeBuilder::new(VOLUME_MOUNT_NAME_JOB)
177+
.empty_dir(EmptyDirVolumeSource::default())
178+
.build(),
179+
);
180+
}
181+
182+
if self.requirements().is_some() {
183+
result.push(
184+
VolumeBuilder::new(VOLUME_MOUNT_NAME_REQ)
185+
.empty_dir(EmptyDirVolumeSource::default())
186+
.build(),
187+
);
188+
}
189+
result
165190
}
166191

167192
pub fn executor_volume_mounts(&self) -> Vec<VolumeMount> {
168-
let tmp = self
193+
let mut result: Vec<VolumeMount> = self
169194
.spec
170195
.executor
171196
.as_ref()
172-
.and_then(|executor_conf| executor_conf.volume_mounts.clone());
197+
.and_then(|executor_conf| executor_conf.volume_mounts.clone())
198+
.iter()
199+
.flat_map(|v| v.iter())
200+
.cloned()
201+
.collect();
202+
203+
if self.spec.image.is_some() {
204+
result.push(VolumeMount {
205+
name: VOLUME_MOUNT_NAME_JOB.into(),
206+
mount_path: VOLUME_MOUNT_PATH_JOB.into(),
207+
..VolumeMount::default()
208+
});
209+
}
210+
211+
if self.requirements().is_some() {
212+
result.push(VolumeMount {
213+
name: VOLUME_MOUNT_NAME_REQ.into(),
214+
mount_path: VOLUME_MOUNT_PATH_REQ.into(),
215+
..VolumeMount::default()
216+
});
217+
}
173218

174-
tmp.iter().flat_map(|v| v.iter()).cloned().collect()
219+
result
175220
}
176221

177222
pub fn driver_volume_mounts(&self) -> Vec<VolumeMount> {
178-
let tmp = self
223+
let mut result: Vec<VolumeMount> = self
179224
.spec
180225
.driver
181226
.as_ref()
182-
.and_then(|driver_conf| driver_conf.volume_mounts.clone());
227+
.and_then(|driver_conf| driver_conf.volume_mounts.clone())
228+
.iter()
229+
.flat_map(|v| v.iter())
230+
.cloned()
231+
.collect();
232+
if self.spec.image.is_some() {
233+
result.push(VolumeMount {
234+
name: VOLUME_MOUNT_NAME_JOB.into(),
235+
mount_path: VOLUME_MOUNT_PATH_JOB.into(),
236+
..VolumeMount::default()
237+
});
238+
}
183239

184-
tmp.iter().flat_map(|v| v.iter()).cloned().collect()
240+
if self.requirements().is_some() {
241+
result.push(VolumeMount {
242+
name: VOLUME_MOUNT_NAME_REQ.into(),
243+
mount_path: VOLUME_MOUNT_PATH_REQ.into(),
244+
..VolumeMount::default()
245+
});
246+
}
247+
result
185248
}
186249

187250
pub fn recommended_labels(&self) -> BTreeMap<String, String> {
@@ -299,6 +362,15 @@ impl SparkApplication {
299362
));
300363
}
301364
}
365+
if self.requirements().is_some() {
366+
e.push(EnvVar {
367+
name: "PYTHONPATH".to_string(),
368+
value: Some(format!(
369+
"$SPARK_HOME/python:{VOLUME_MOUNT_PATH_REQ}:$PYTHONPATH"
370+
)),
371+
value_from: None,
372+
});
373+
}
302374
e
303375
}
304376

@@ -316,6 +388,20 @@ impl SparkApplication {
316388
..Default::default()
317389
}
318390
}
391+
392+
pub fn driver_node_selector(&self) -> Option<std::collections::BTreeMap<String, String>> {
393+
self.spec
394+
.driver
395+
.as_ref()
396+
.and_then(|driver_config| driver_config.node_selector.clone())
397+
}
398+
399+
pub fn executor_node_selector(&self) -> Option<std::collections::BTreeMap<String, String>> {
400+
self.spec
401+
.executor
402+
.as_ref()
403+
.and_then(|executor_config| executor_config.node_selector.clone())
404+
}
319405
}
320406

321407
#[derive(Clone, Default, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
@@ -343,6 +429,8 @@ pub struct DriverConfig {
343429
pub memory: Option<String>,
344430
#[serde(default, skip_serializing_if = "Option::is_none")]
345431
pub volume_mounts: Option<Vec<VolumeMount>>,
432+
#[serde(default, skip_serializing_if = "Option::is_none")]
433+
pub node_selector: Option<std::collections::BTreeMap<String, String>>,
346434
}
347435

348436
impl DriverConfig {
@@ -371,6 +459,8 @@ pub struct ExecutorConfig {
371459
pub memory: Option<String>,
372460
#[serde(default, skip_serializing_if = "Option::is_none")]
373461
pub volume_mounts: Option<Vec<VolumeMount>>,
462+
#[serde(default, skip_serializing_if = "Option::is_none")]
463+
pub node_selector: Option<std::collections::BTreeMap<String, String>>,
374464
}
375465

376466
impl ExecutorConfig {

rust/operator-binary/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
license = "OSL-3.0"
66
name = "stackable-spark-k8s-operator"
77
repository = "https://github.com/stackabletech/spark-k8s-operator"
8-
version = "0.1.0"
8+
version = "0.2.0-nightly"
99

1010
[dependencies]
1111
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag="0.19.0" }

0 commit comments

Comments
 (0)