Skip to content

Commit

Permalink
PTFE-1144 gcloud instances support of fixed labels (#496)
Browse files Browse the repository at this point in the history
This pull request includes changes related to the configuration and
testing of custom labels for GCP instances in the runner manager
backend. The most important changes include adding a new attribute to
the `GCPInstanceConfig` class to configure custom labels, and modifying
the GCP backend test to verify the correct setting of custom labels.
  • Loading branch information
tcarmet authored Dec 7, 2023
1 parent 195e920 commit 6c1196a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion runner_manager/backend/gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _sanitize_label_value(self, value: str) -> str:
return value

def setup_labels(self, runner: Runner) -> MutableMapping[str, str]:
labels: MutableMapping[str, str] = dict()
labels: MutableMapping[str, str] = self.instance_config.labels.copy()
if self.manager:
labels["runner-manager"] = self.manager
labels["status"] = self._sanitize_label_value(runner.status)
Expand Down
1 change: 1 addition & 0 deletions runner_manager/models/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class GCPInstanceConfig(InstanceConfig):
spot: bool = False
disk_size_gb: int = 20
disk_type: Literal["pd-ssd", "pd-standard"] = "pd-ssd"
labels: Dict[str, str] = {}

class Config:
arbitrary_types_allowed = True
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/backend/test_gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def gcp_group(settings, monkeypatch) -> RunnerGroup:
backend=GCPBackend(
name=Backends.gcloud,
config=config,
instance_config=GCPInstanceConfig(),
instance_config=GCPInstanceConfig(
labels={
"key": "value",
}
),
),
labels=[
"label",
Expand Down Expand Up @@ -80,6 +84,7 @@ def test_gcp_setup_labels(runner: Runner, gcp_group: RunnerGroup):
labels = gcp_group.backend.setup_labels(runner)
assert labels["status"] == runner.status
assert labels["busy"] == str(runner.busy).lower()
assert labels["key"] == "value"


def test_gcp_spot_config(runner: Runner, gcp_group: RunnerGroup):
Expand Down

0 comments on commit 6c1196a

Please sign in to comment.