Skip to content


Browse files Browse the repository at this point in the history
feat: Support for machine_type for kubernetes executor (#1291)
  • Loading branch information
cademirch committed Mar 20, 2022
1 parent 8f5d116 commit 12d6f67
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
29 changes: 29 additions & 0 deletions docs/executing/cloud.rst
Expand Up @@ -108,6 +108,35 @@ defined as ``mem_mb`` to kubernetes. Further, it will propagate the number of th
a job intends to use, such that kubernetes can allocate it to the correct cloud
computing node.

Machine Types

To specify an exact `machine type <>`_
or a prefix to filter down to and then select based on other resource needs,
you can set a default resource on the command line, either for a prefix or
a full machine type:

.. code-block:: console
--default-resources "machine_type=n1-standard"
For individual jobs, the default machine type can also be overwritten via

.. code-block:: console
--set-resources "somerule:machine_type=n1-standard"
If you want to specify the machine type as a resource in the workflow definition, you can do that too (although it is not recommended in general because it ties your workflow to the used platform):

.. code-block:: python
rule somerule:
"somecommand ..."
Executing a Snakemake workflow via Google Cloud Life Sciences
Expand Down
11 changes: 10 additions & 1 deletion snakemake/executors/
Expand Up @@ -1844,7 +1844,16 @@ def run(self, job, callback=None, submit_callback=None, error_callback=None):
kubernetes.client.V1VolumeMount(name="source", mount_path="/source")

body.spec = kubernetes.client.V1PodSpec(containers=[container])
node_selector = {}
if "machine_type" in job.resources.keys():
# Kubernetes labels a node by its instance type using this node_label.
node_selector[""] = job.resources[

body.spec = kubernetes.client.V1PodSpec(
containers=[container], node_selector=node_selector
# fail on first error
body.spec.restart_policy = "Never"

Expand Down

0 comments on commit 12d6f67

Please sign in to comment.