Skip to content

Commit

Permalink
PTFE-1402 use subnetwork only for gcp runners (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet authored Jan 30, 2024
1 parent 3429616 commit 5f68631
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion runner_manager/backend/gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def disks(self) -> List[AttachedDisk]:
@property
def network_interfaces(self) -> List[NetworkInterface]:
network_interface: NetworkInterface = NetworkInterface(
network=self.instance_config.network,
subnetwork=f"projects/{self.config.project_id}/regions/{self.config.region}/subnetworks/{self.instance_config.subnetwork}",
)
if self.instance_config.enable_external_ip:
network_interface.access_configs = [
Expand Down
3 changes: 2 additions & 1 deletion runner_manager/models/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class GCPConfig(BackendConfig):

project_id: str
zone: str
region: str = "europe-west1"
service_account_email: str = "default"
google_application_credentials: Optional[str] = None

Expand All @@ -102,7 +103,7 @@ class GCPInstanceConfig(InstanceConfig):
image_family: str = "ubuntu-2004-lts"
image_project: str = "ubuntu-os-cloud"
machine_type: str = "e2-small"
network: str = "global/networks/default"
subnetwork: str = "default"
enable_nested_virtualization: bool = True
enable_external_ip: bool = True
spot: bool = False
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/backend/test_gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
def gcp_group(settings, monkeypatch) -> RunnerGroup:
config = GCPConfig(
project_id=os.environ.get("CLOUDSDK_CORE_PROJECT", ""),
region=os.environ.get("CLOUDSDK_COMPUTE_REGION", ""),
zone=os.environ.get("CLOUDSDK_COMPUTE_ZONE", ""),
google_application_credentials=os.environ.get(
"GOOGLE_APPLICATION_CREDENTIALS", ""
Expand Down Expand Up @@ -55,8 +56,9 @@ def gcp_runner(runner: Runner, gcp_group: RunnerGroup) -> Runner:


def test_gcp_network_interfaces(gcp_group: RunnerGroup):
interfaces = gcp_group.backend.network_interfaces
interfaces: List[NetworkInterface] = gcp_group.backend.network_interfaces
assert len(interfaces) == 1
assert "default" in gcp_group.backend.network_interfaces[0].subnetwork
assert interfaces[0].access_configs[0].name == "External NAT"
# Test disabling external IP
gcp_group.backend.instance_config.enable_external_ip = False
Expand Down

0 comments on commit 5f68631

Please sign in to comment.