Skip to content

Commit 4f8682b

Browse files
authored
Allow for the ability to enable/disable public ingress for the compute instances via class instantiation rather than via the config (#477)
1 parent ca25d15 commit 4f8682b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

dask_cloudprovider/gcp/instances.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(
6767
instance_labels=None,
6868
service_account=None,
6969
instance_scopes=None,
70+
public_ingress=None,
7071
**kwargs,
7172
):
7273
super().__init__(**kwargs)
@@ -107,6 +108,7 @@ def __init__(
107108
self.general_zone = "-".join(self.zone.split("-")[:2]) # us-east1-c -> us-east1
108109
self.service_account = service_account or self.config.get("service_account")
109110
self.instance_scopes = instance_scopes or self.config.get("instance_scopes")
111+
self.public_ingress = public_ingress or self.config.get("public_ingress", True)
110112

111113
def create_gcp_config(self):
112114
subnetwork = f"projects/{self.network_projectid}/regions/{self.general_zone}/subnetworks/{self.network}"
@@ -178,7 +180,7 @@ def create_gcp_config(self):
178180
"reservationAffinity": {"consumeReservationType": "ANY_RESERVATION"},
179181
}
180182

181-
if self.config.get("public_ingress", True):
183+
if self.public_ingress:
182184
config["networkInterfaces"][0]["accessConfigs"] = [
183185
{
184186
"kind": "compute#accessConfig",
@@ -219,7 +221,7 @@ async def create_vm(self):
219221
await asyncio.sleep(0.5)
220222

221223
self.internal_ip = await self.get_internal_ip()
222-
if self.config.get("public_ingress", True):
224+
if self.public_ingress:
223225
self.external_ip = await self.get_external_ip()
224226
else:
225227
self.external_ip = None
@@ -307,7 +309,7 @@ async def start_scheduler(self):
307309
self.cluster._log("Creating scheduler instance")
308310
self.internal_ip, self.external_ip = await self.create_vm()
309311

310-
if self.config.get("public_ingress", True) and not is_inside_gce():
312+
if self.public_ingress and not is_inside_gce():
311313
# scheduler must be publicly available, and firewall
312314
# needs to be in place to allow access to 8786 on
313315
# the external IP
@@ -377,7 +379,7 @@ async def start_worker(self):
377379
self.cluster._log(f"Worker GPU Count: {self.ngpus}")
378380
self.cluster._log(f"Worker GPU Type: {self.gpu_type}")
379381
self.internal_ip, self.external_ip = await self.create_vm()
380-
if self.config.get("public_ingress", True):
382+
if self.public_ingress:
381383
# scheduler is publicly available
382384
self.address = self.external_ip
383385
else:
@@ -519,6 +521,10 @@ class GCPCluster(VMCluster):
519521
Defaults to ``["https://www.googleapis.com/auth/devstorage.read_write",
520522
"https://www.googleapis.com/auth/logging.write",
521523
"https://www.googleapis.com/auth/monitoring.write"]``.
524+
public_ingress: bool (optional)
525+
Whether to assign a public IP address to both the scheduler and worker instances,
526+
allowing them to be externally accessible, assumes firewall rules for 8786 and 8787 are in place.
527+
Defaults to ``True``.
522528
service_account_credentials: Optional[Dict[str, Any]]
523529
Service account credentials to create the compute engine Vms
524530
@@ -621,6 +627,7 @@ def __init__(
621627
instance_labels=None,
622628
service_account=None,
623629
instance_scopes=None,
630+
public_ingress=None,
624631
service_account_credentials: Optional[Dict[str, Any]] = None,
625632
**kwargs,
626633
):
@@ -722,6 +729,7 @@ def __init__(
722729
"instance_labels": instance_labels or self.config.get("instance_labels"),
723730
"service_account": service_account or self.config.get("service_account"),
724731
"instance_scopes": instance_scopes or self.config.get("instance_scopes"),
732+
"public_ingress": public_ingress or self.config.get("public_ingress", True),
725733
}
726734
self.scheduler_options = {**self.options}
727735
self.scheduler_options["machine_type"] = self.scheduler_machine_type

0 commit comments

Comments
 (0)