Skip to content

Commit 8678e20

Browse files
johanneskoesterhnawarhatem.nawar
authored
feat: Add support for customer compute service account (#51, @hnawar) (#52)
Test for PR #51. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for specifying a custom compute service account in the `hello_world` rule, enhancing flexibility for cloud interactions. - Introduced a new method to retrieve service account information, providing better control over job allocations. - **Bug Fixes** - Updated `.gitignore` to exclude the `poetry.lock` file, ensuring cleaner version control. - **Documentation** - Enhanced documentation for the `hello_world` rule to include the new `googlebatch_service_account` parameter, improving user guidance. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Hatem Nawar <[email protected]> Co-authored-by: Hatem <[email protected]> Co-authored-by: hatem.nawar <[email protected]>
1 parent 61b6fe0 commit 8678e20

File tree

6 files changed

+139
-101
lines changed

6 files changed

+139
-101
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
__pycache__
22
env
33
.snakemake
4+
poetry.lock

docs/further.md

Lines changed: 109 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ This will define the machine type for a particular step, overriding the default
119119

120120
```console
121121
rule hello_world:
122-
output:
123-
"...",
124-
resources:
125-
googlebatch_machine_type="c3-standard-112"
126-
shell:
122+
output:
123+
"...",
124+
resources:
125+
googlebatch_machine_type="c3-standard-112"
126+
shell:
127127
"..."
128128
```
129129

@@ -136,11 +136,11 @@ This will define the image family for a particular step, overriding the default
136136

137137
```console
138138
rule hello_world:
139-
output:
140-
"...",
141-
resources:
142-
googlebatch_image_family="hpc-centos-7"
143-
shell:
139+
output:
140+
"...",
141+
resources:
142+
googlebatch_image_family="hpc-centos-7"
143+
shell:
144144
"..."
145145
```
146146

@@ -160,11 +160,11 @@ This will define the image project for a particular step, overriding the default
160160

161161
```console
162162
rule hello_world:
163-
output:
164-
"...",
165-
resources:
166-
googlebatch_image_project="cloud-hpc-image-public"
167-
shell:
163+
output:
164+
"...",
165+
resources:
166+
googlebatch_image_project="cloud-hpc-image-public"
167+
shell:
168168
"..."
169169
```
170170

@@ -175,11 +175,11 @@ This will define the bucket for a particular step, overriding the default from t
175175

176176
```console
177177
rule hello_world:
178-
output:
179-
"...",
180-
resources:
181-
googlebatch_bucket="my-snakemake-batch-bucket"
182-
shell:
178+
output:
179+
"...",
180+
resources:
181+
googlebatch_bucket="my-snakemake-batch-bucket"
182+
shell:
183183
"..."
184184
```
185185

@@ -189,11 +189,11 @@ This will define the mount path for a bucket for a particular step, overriding t
189189

190190
```console
191191
rule hello_world:
192-
output:
193-
"...",
194-
resources:
195-
googlebatch_mount_path="/mnt/workflow"
196-
shell:
192+
output:
193+
"...",
194+
resources:
195+
googlebatch_mount_path="/mnt/workflow"
196+
shell:
197197
"..."
198198
```
199199

@@ -204,11 +204,11 @@ This will define the work tasks for a particular step, overriding the default fr
204204

205205
```console
206206
rule hello_world:
207-
output:
208-
"...",
209-
resources:
210-
googlebatch_work_tasks=1
211-
shell:
207+
output:
208+
"...",
209+
resources:
210+
googlebatch_work_tasks=1
211+
shell:
212212
"..."
213213
```
214214

@@ -218,11 +218,11 @@ The URL of an existing network resource (e.g., `projects/{project}/global/networ
218218

219219
```console
220220
rule hello_world:
221-
output:
222-
"...",
223-
resources:
224-
googlebatch_network="projects/{project}/global/networks/{network}"
225-
shell:
221+
output:
222+
"...",
223+
resources:
224+
googlebatch_network="projects/{project}/global/networks/{network}"
225+
shell:
226226
"..."
227227
```
228228

@@ -232,11 +232,25 @@ The URL of an existing subnetwork resource (e.g., `projects/{project}/regions/{r
232232

233233
```console
234234
rule hello_world:
235-
output:
236-
"...",
237-
resources:
238-
googlebatch_subnetwork="projects/{project}/regions/{region}/subnetworks/{subnetwork}"
239-
shell:
235+
output:
236+
"...",
237+
resources:
238+
googlebatch_subnetwork="projects/{project}/regions/{region}/subnetworks/{subnetwork}"
239+
shell:
240+
"..."
241+
```
242+
243+
#### googlebatch_service_account
244+
245+
The email of custom compute service account to be used by Batch (e.g., `[email protected]`)
246+
247+
```console
248+
rule hello_world:
249+
output:
250+
"...",
251+
resources:
252+
googlebatch_service_account="[email protected]"
253+
shell:
240254
"..."
241255
```
242256

@@ -246,11 +260,11 @@ This will define the milliseconds per cpu-second for a particular step, overridi
246260

247261
```console
248262
rule hello_world:
249-
output:
250-
"...",
251-
resources:
252-
googlebatch_cpu_mulli=2000
253-
shell:
263+
output:
264+
"...",
265+
resources:
266+
googlebatch_cpu_mulli=2000
267+
shell:
254268
"..."
255269
```
256270

@@ -260,11 +274,11 @@ This will define the work tasks per node (Google batch calls these tasks) for a
260274

261275
```console
262276
rule hello_world:
263-
output:
264-
"...",
265-
resources:
266-
googlebatch_work_tasks_per_node=2
267-
shell:
277+
output:
278+
"...",
279+
resources:
280+
googlebatch_work_tasks_per_node=2
281+
shell:
268282
"..."
269283
```
270284

@@ -274,11 +288,11 @@ This will define the memory for a particular step as an integer in MiB, overridi
274288

275289
```console
276290
rule hello_world:
277-
output:
278-
"...",
279-
resources:
280-
googlebatch_memory=2000
281-
shell:
291+
output:
292+
"...",
293+
resources:
294+
googlebatch_memory=2000
295+
shell:
282296
"..."
283297
```
284298

@@ -289,11 +303,11 @@ This is the [boot disk type](https://cloud.google.com/compute/docs/disks#pdspecs
289303

290304
```console
291305
rule hello_world:
292-
output:
293-
"...",
294-
resources:
295-
googlebatch_boot_disk_type="pd-standard"
296-
shell:
306+
output:
307+
"...",
308+
resources:
309+
googlebatch_boot_disk_type="pd-standard"
310+
shell:
297311
"..."
298312
```
299313

@@ -304,11 +318,11 @@ This is the boot disk [image](https://github.com/googleapis/googleapis/blob/2fd7
304318

305319
```console
306320
rule hello_world:
307-
output:
308-
"...",
309-
resources:
310-
googlebatch_boot_disk_image="batch-centos"
311-
shell:
321+
output:
322+
"...",
323+
resources:
324+
googlebatch_boot_disk_image="batch-centos"
325+
shell:
312326
"..."
313327
```
314328

@@ -319,11 +333,11 @@ The [size of the boot disk](https://github.com/googleapis/googleapis/blob/2fd762
319333

320334
```console
321335
rule hello_world:
322-
output:
323-
"...",
324-
resources:
325-
googlebatch_boot_disk_gb=40
326-
shell:
336+
output:
337+
"...",
338+
resources:
339+
googlebatch_boot_disk_gb=40
340+
shell:
327341
"..."
328342
```
329343

@@ -333,11 +347,11 @@ This will define the retry times for a step overriding the default from the comm
333347

334348
```console
335349
rule hello_world:
336-
output:
337-
"...",
338-
resources:
339-
googlebatch_retry_count=2
340-
shell:
350+
output:
351+
"...",
352+
resources:
353+
googlebatch_retry_count=2
354+
shell:
341355
"..."
342356
```
343357

@@ -347,11 +361,11 @@ This will define the max run duration for a step overriding the default from the
347361

348362
```console
349363
rule hello_world:
350-
output:
351-
"...",
352-
resources:
353-
googlebatch_max_run_duration="3600s"
354-
shell:
364+
output:
365+
"...",
366+
resources:
367+
googlebatch_max_run_duration="3600s"
368+
shell:
355369
"..."
356370
```
357371

@@ -361,11 +375,11 @@ This will define the extra labels to add to the Google Batch job.
361375

362376
```console
363377
rule hello_world:
364-
output:
365-
"...",
366-
resources:
367-
googlebatch_labels="model=c3,stage=test"
368-
shell:
378+
output:
379+
"...",
380+
resources:
381+
googlebatch_labels="model=c3,stage=test"
382+
shell:
369383
"..."
370384
```
371385

@@ -376,11 +390,11 @@ A container to use only with `image_family` set to batch-cos* (see [here](https:
376390

377391
```console
378392
rule hello_world:
379-
output:
380-
"...",
381-
resources:
382-
googlebatch_container="ghcr.io/rse-ops/atacseq:app-latest"
383-
shell:
393+
output:
394+
"...",
395+
resources:
396+
googlebatch_container="ghcr.io/rse-ops/atacseq:app-latest"
397+
shell:
384398
"..."
385399
```
386400

@@ -391,10 +405,10 @@ One or more named (or file-derived) snippets to add to setup.
391405

392406
```console
393407
rule hello_world:
394-
output:
395-
"...",
396-
resources:
397-
googlebatch_snippets="mpi,myscript.sh"
398-
shell:
408+
output:
409+
"...",
410+
resources:
411+
googlebatch_snippets="mpi,myscript.sh"
412+
shell:
399413
"..."
400414
```

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ black = "^24.4.0"
2828
flake8 = "^6.1.0"
2929
coverage = "^7.3.1"
3030
pytest = "^7.4.2"
31-
snakemake = {git = "https://github.com/snakemake/snakemake.git", branch="main"}
31+
snakemake = "^8.18.0"
3232
snakemake-storage-plugin-s3 = "^0.2.10"
3333

3434
[tool.coverage.run]

snakemake_executor_plugin_googlebatch/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ class ExecutorSettings(ExecutorSettingsBase):
155155
},
156156
)
157157

158+
service_account: Optional[str] = field(
159+
default=None,
160+
metadata={
161+
"help": "The email of a customer compute service account",
162+
"env_var": True,
163+
"required": False,
164+
},
165+
)
166+
158167
# local SSD uses type "local-ssd".
159168
# Also "pd-balanced", "pd-extreme", "pd-ssd", "pd-standard"
160169
boot_disk_type: Optional[str] = field(

snakemake_executor_plugin_googlebatch/executor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ def get_allocation_policy(self, job):
359359
network_policy = self.get_network_policy(job)
360360
if network_policy is not None:
361361
allocation_policy.network = network_policy
362+
# Add custom compute service account
363+
service_account = self.get_service_account(job)
364+
365+
if service_account is not None:
366+
allocation_policy.service_account = service_account
367+
362368
return allocation_policy
363369

364370
def get_network_policy(self, job):
@@ -379,6 +385,16 @@ def get_network_policy(self, job):
379385
policy.network_interfaces = [interface]
380386
return policy
381387

388+
def get_service_account(self, job: JobExecutorInterface) -> batch_v1.ServiceAccount:
389+
"""
390+
Givena job request, get the service account
391+
"""
392+
service_account_email = self.get_param(job, "service_account")
393+
service_account = batch_v1.ServiceAccount()
394+
if service_account_email is not None:
395+
service_account.email = service_account_email
396+
return service_account
397+
382398
def get_boot_disk(self, job):
383399
"""
384400
Given a job request, add a customized boot disk.

0 commit comments

Comments
 (0)