Skip to content

Commit

Permalink
Ability to specify service account to run VMs in GCP. (#413)
Browse files Browse the repository at this point in the history
* Ability to specify service account to run VMs in GCP.

* fixed long line
  • Loading branch information
jmhatze authored Aug 21, 2023
1 parent 7b214ad commit ef21317
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions dask_cloudprovider/cloudprovider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ cloudprovider:
public_ingress: true # configure the scheduler to be externally accessible. This assumes firefwall rules for 8787 and 8786
instance_labels:
container_vm: "dask-cloudprovider"
service_account: "default"

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 @@ -67,6 +67,7 @@ def __init__(
auto_shutdown=None,
preemptible=False,
instance_labels=None,
service_account=None,
**kwargs,
):
super().__init__(**kwargs)
Expand Down Expand Up @@ -106,7 +107,10 @@ def __init__(

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

self.service_account = service_account or self.config.get("service_account")

def create_gcp_config(self):

subnetwork = f"projects/{self.network_projectid}/regions/{self.general_zone}/subnetworks/{self.network}"
config = {
"name": self.name,
Expand Down Expand Up @@ -143,7 +147,7 @@ def create_gcp_config(self):
# Allow the instance to access cloud storage and logging.
"serviceAccounts": [
{
"email": "default",
"email": self.service_account,
"scopes": [
"https://www.googleapis.com/auth/devstorage.read_write",
"https://www.googleapis.com/auth/logging.write",
Expand Down Expand Up @@ -489,6 +493,9 @@ class GCPCluster(VMCluster):
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.
service_account: str
Service account that all VMs will run under.
Defaults to the default Compute Engine service account for your GCP project.
Examples
--------
Expand Down Expand Up @@ -581,6 +588,7 @@ def __init__(
preemptible=None,
debug=False,
instance_labels=None,
service_account=None,
**kwargs,
):

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

0 comments on commit ef21317

Please sign in to comment.