Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for customer compute service account #51

Merged
merged 6 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__
env
.snakemake
poetry.lock
14 changes: 14 additions & 0 deletions docs/further.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,20 @@ rule hello_world:
"..."
```

#### googlebatch_service_account

The email of custom compute service account to be used by Batch (e.g., `[email protected]`)

```console
rule hello_world:
output:
"...",
resources:
googlebatch_service_account="[email protected]"
shell:
"..."
```

#### googlebatch_cpu_milli

This will define the milliseconds per cpu-second for a particular step, overriding the default from the command line.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ black = "^24.4.0"
flake8 = "^6.1.0"
coverage = "^7.3.1"
pytest = "^7.4.2"
snakemake = {git = "https://github.com/snakemake/snakemake.git", branch="main"}
snakemake = "^8.18.0"
snakemake-storage-plugin-s3 = "^0.2.10"

[tool.coverage.run]
Expand Down
9 changes: 9 additions & 0 deletions snakemake_executor_plugin_googlebatch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ class ExecutorSettings(ExecutorSettingsBase):
},
)

service_account: Optional[str] = field(
default=None,
metadata={
"help": "The email of a customer compute service account",
"env_var": True,
"required": False,
},
)

# local SSD uses type "local-ssd".
# Also "pd-balanced", "pd-extreme", "pd-ssd", "pd-standard"
boot_disk_type: Optional[str] = field(
Expand Down
16 changes: 16 additions & 0 deletions snakemake_executor_plugin_googlebatch/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ def get_allocation_policy(self, job):
network_policy = self.get_network_policy(job)
if network_policy is not None:
allocation_policy.network = network_policy
# Add custom compute service account
service_account = self.get_service_account(job)

if service_account is not None:
allocation_policy.service_account = service_account

return allocation_policy

def get_network_policy(self, job):
Expand All @@ -379,6 +385,16 @@ def get_network_policy(self, job):
policy.network_interfaces = [interface]
return policy

def get_service_account(self, job):
"""
Givena job request, get the service account
"""
service_account_email = self.get_param(job, "service_account")
service_account = batch_v1.ServiceAccount()
if service_account_email is not None:
service_account.email = service_account_email
return service_account

def get_boot_disk(self, job):
"""
Given a job request, add a customized boot disk.
Expand Down
Loading