Skip to content

Commit 5f68631

Browse files
authored
PTFE-1402 use subnetwork only for gcp runners (#524)
1 parent 3429616 commit 5f68631

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

runner_manager/backend/gcloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def disks(self) -> List[AttachedDisk]:
9292
@property
9393
def network_interfaces(self) -> List[NetworkInterface]:
9494
network_interface: NetworkInterface = NetworkInterface(
95-
network=self.instance_config.network,
95+
subnetwork=f"projects/{self.config.project_id}/regions/{self.config.region}/subnetworks/{self.instance_config.subnetwork}",
9696
)
9797
if self.instance_config.enable_external_ip:
9898
network_interface.access_configs = [

runner_manager/models/backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class GCPConfig(BackendConfig):
9494

9595
project_id: str
9696
zone: str
97+
region: str = "europe-west1"
9798
service_account_email: str = "default"
9899
google_application_credentials: Optional[str] = None
99100

@@ -102,7 +103,7 @@ class GCPInstanceConfig(InstanceConfig):
102103
image_family: str = "ubuntu-2004-lts"
103104
image_project: str = "ubuntu-os-cloud"
104105
machine_type: str = "e2-small"
105-
network: str = "global/networks/default"
106+
subnetwork: str = "default"
106107
enable_nested_virtualization: bool = True
107108
enable_external_ip: bool = True
108109
spot: bool = False

tests/unit/backend/test_gcp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
def gcp_group(settings, monkeypatch) -> RunnerGroup:
1616
config = GCPConfig(
1717
project_id=os.environ.get("CLOUDSDK_CORE_PROJECT", ""),
18+
region=os.environ.get("CLOUDSDK_COMPUTE_REGION", ""),
1819
zone=os.environ.get("CLOUDSDK_COMPUTE_ZONE", ""),
1920
google_application_credentials=os.environ.get(
2021
"GOOGLE_APPLICATION_CREDENTIALS", ""
@@ -55,8 +56,9 @@ def gcp_runner(runner: Runner, gcp_group: RunnerGroup) -> Runner:
5556

5657

5758
def test_gcp_network_interfaces(gcp_group: RunnerGroup):
58-
interfaces = gcp_group.backend.network_interfaces
59+
interfaces: List[NetworkInterface] = gcp_group.backend.network_interfaces
5960
assert len(interfaces) == 1
61+
assert "default" in gcp_group.backend.network_interfaces[0].subnetwork
6062
assert interfaces[0].access_configs[0].name == "External NAT"
6163
# Test disabling external IP
6264
gcp_group.backend.instance_config.enable_external_ip = False

0 commit comments

Comments
 (0)