Skip to content

Commit b64edec

Browse files
committed
feat: support for custom node selector
we want jobs to be able to select different node types Signed-off-by: vsoch <[email protected]>
1 parent 1255777 commit b64edec

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ For each job script section, the following environment variables are provided fo
9090
- registry: the registry where your artifact will be pushed
9191
- pull_tag: the pull tag to use (if the workflow is pulling)
9292
- push_tag: the push tag to use (if the workflow is pushing)
93+
- properties:
94+
- node-selector: key value pair to be added as node selectors for the job (Kubernetes only). E.g., `node.kubernetes.io/instance-type: c7a.4xlarge`
9395

9496
Take a look at the simple example [examples/state-machine.yaml](examples/state-machine.yaml) to see how push/pull is defined between steps. Given that these are found (with a tag) your artifact will be named `<registry>:<jobid>:<tag>` to be moved between steps.
9597

python/state_machine_operator/schema.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"config": {"$ref": "#/definitions/config"},
8181
"script": {"type": "string"},
8282
"image": {"type": "string"},
83+
"properties": {"$ref": "#/definitions/properties"},
8384
"registry": {"$ref": "#/definitions/registry"},
8485
"workdir": {"type": "string", "default": "/tmp/out"},
8586
"additionalProperties": False,
@@ -96,6 +97,10 @@
9697
},
9798
"additionalProperties": False,
9899
},
100+
"properties": {
101+
"type": "object",
102+
"properties": {"type": "object", "additionalProperties": True},
103+
},
99104
"config": {
100105
"type": "object",
101106
"properties": {

python/state_machine_operator/tracker/kubernetes/tracker.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ def delete_configmap(self, name):
9090
except Exception as e:
9191
LOGGER.warning(f"Issue deleting configmap {name}: {e}")
9292

93+
def get_node_selector(self):
94+
"""
95+
Node selector is in properties -> node-selector
96+
"""
97+
return self.job_desc.get("properties", {}).get("node-selector")
98+
9399
def generate_batch_job(self, step, jobid):
94100
"""
95101
Generate the job CRD assuming the config map entrypoint.
@@ -186,6 +192,12 @@ def generate_batch_job(self, step, jobid):
186192
},
187193
}
188194

195+
# Add node selectors? E.g.,
196+
# node.kubernetes.io/instance-type: c7a.4xlarge
197+
node_selector = self.get_node_selector()
198+
if node_selector is not None:
199+
template["spec"]["nodeSelector"] = node_selector
200+
189201
# Only add walltime if it's > 0 and not None
190202
if walltime:
191203
template["spec"]["activeDeadlineSeconds"] = int(walltime)

0 commit comments

Comments
 (0)