Skip to content

Commit

Permalink
Add support for GCP labels on instance creation (#355)
Browse files Browse the repository at this point in the history
* allow user define GCP labels

* formatting
  • Loading branch information
kapadia committed Jun 6, 2022
1 parent 93c62e6 commit 41e6624
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dask_cloudprovider/cloudprovider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ cloudprovider:
docker_image: "daskdev/dask:latest" # docker image to use
auto_shutdown: true # Shutdown instances automatically if the scheduler or worker services time out.
public_ingress: true # configure the scheduler to be externally accessible. This assumes firefwall rules for 8787 and 8786
instance_labels:
container_vm: "dask-cloudprovider"

hetzner:
token: null # API token for interacting with the Hetzner cloud API
Expand Down
11 changes: 10 additions & 1 deletion dask_cloudprovider/gcp/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(
gpu_instance=None,
auto_shutdown=None,
preemptible=False,
instance_labels=None,
**kwargs,
):
super().__init__(**kwargs)
Expand Down Expand Up @@ -99,6 +100,10 @@ def __init__(
self.auto_shutdown = auto_shutdown
self.preemptible = preemptible

_instance_labels = self.config.get("instance_labels")
_instance_labels.update(instance_labels)
self.instance_labels = _instance_labels

self.general_zone = "-".join(self.zone.split("-")[:2]) # us-east1-c -> us-east1

def create_gcp_config(self):
Expand Down Expand Up @@ -159,7 +164,7 @@ def create_gcp_config(self):
{"key": "user-data", "value": self.cloud_init},
]
},
"labels": {"container-vm": "dask-cloudprovider"},
"labels": self.instance_labels,
"scheduling": {
"preemptible": ("true" if self.preemptible else "false"),
"onHostMaintenance": self.on_host_maintenance.upper(),
Expand Down Expand Up @@ -482,6 +487,8 @@ class GCPCluster(VMCluster):
Whether to use preemptible instances for workers in this cluster. Defaults to ``False``.
debug: bool, optional
More information will be printed when constructing clusters to enable debugging.
instance_labels: dict (optional)
Labels to be applied to all GCP instances upon creation.
Examples
--------
Expand Down Expand Up @@ -573,6 +580,7 @@ def __init__(
bootstrap=True,
preemptible=None,
debug=False,
instance_labels=None,
**kwargs,
):

Expand Down Expand Up @@ -615,6 +623,7 @@ def __init__(
"preemptible": preemptible
if preemptible is not None
else self.config.get("preemptible"),
"instance_labels": instance_labels or self.config.get("instance_labels"),
}
self.scheduler_options = {**self.options}
self.worker_options = {**self.options}
Expand Down

0 comments on commit 41e6624

Please sign in to comment.