Skip to content

Commit 23da7ea

Browse files
committed
Support network tags in google batch
Signed-off-by: ejseqera <esha.joshi@seqera.io>
1 parent 9a045f8 commit 23da7ea

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

docs/reference/config.md

+5
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,11 @@ The following settings are available for Google Cloud Batch:
877877
- projects/{project}/global/networks/{network}
878878
- global/networks/{network}
879879

880+
`google.batch.networkTags`
881+
: The network tags to be applied to the instances created by Google Batch jobs. Network tags are used to apply firewall rules and control network access (e.g., `['allow-ssh', 'allow-http']`).
882+
883+
: Network tags are ignored when using instance templates. See [Add network tags](https://cloud.google.com/vpc/docs/add-remove-network-tags) for more information.
884+
880885
`google.batch.serviceAccountEmail`
881886
: Define the Google service account email to use for the pipeline execution. If not specified, the default Compute Engine service account for the project will be used.
882887

modules/nf-lang/src/main/java/nextflow/config/scopes/GoogleBatchConfig.java

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ Max number of execution attempts of a job interrupted by a Compute Engine spot r
5858
""")
5959
public String network;
6060

61+
@ConfigOption
62+
@Description("""
63+
The network tags to be applied to the instances created by Google Batch jobs (e.g., `['allow-ssh', 'allow-http']`).
64+
65+
[Read more](https://cloud.google.com/vpc/docs/add-remove-network-tags)
66+
""")
67+
public List<String> networkTags;
68+
6169
@ConfigOption
6270
@Description("""
6371
The Google service account email to use for the pipeline execution. If not specified, the default Compute Engine service account for the project will be used.

plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchTaskHandler.groovy

+7
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ class GoogleBatchTaskHandler extends TaskHandler implements FusionAwareTask {
293293

294294
allocationPolicy.putAllLabels( task.config.getResourceLabels() )
295295

296+
// Add network tags if configured
297+
if( executor.config.networkTags )
298+
allocationPolicy.addAllTags( executor.config.networkTags )
299+
296300
// use instance template if specified
297301
if( task.config.getMachineType()?.startsWith('template://') ) {
298302
if( task.config.getAccelerator() )
@@ -307,6 +311,9 @@ class GoogleBatchTaskHandler extends TaskHandler implements FusionAwareTask {
307311
if( executor.config.cpuPlatform )
308312
log.warn1 'Config option `google.batch.cpuPlatform` ignored because an instance template was specified'
309313

314+
if( executor.config.networkTags )
315+
log.warn1 'Config option `google.batch.networkTags` ignored because an instance template was specified'
316+
310317
if( executor.config.preemptible )
311318
log.warn1 'Config option `google.batch.premptible` ignored because an instance template was specified'
312319

plugins/nf-google/src/main/nextflow/cloud/google/batch/client/BatchConfig.groovy

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class BatchConfig {
4949
private String network
5050
private String subnetwork
5151
private String serviceAccountEmail
52+
private List<String> networkTags
5253
private BatchRetryConfig retryConfig
5354
private List<Integer> autoRetryExitCodes
5455

@@ -66,6 +67,7 @@ class BatchConfig {
6667
String getNetwork() { network }
6768
String getSubnetwork() { subnetwork }
6869
String getServiceAccountEmail() { serviceAccountEmail }
70+
List<String> getNetworkTags() { networkTags }
6971
BatchRetryConfig getRetryConfig() { retryConfig }
7072
List<Integer> getAutoRetryExitCodes() { autoRetryExitCodes }
7173

@@ -85,6 +87,7 @@ class BatchConfig {
8587
result.network = session.config.navigate('google.batch.network')
8688
result.subnetwork = session.config.navigate('google.batch.subnetwork')
8789
result.serviceAccountEmail = session.config.navigate('google.batch.serviceAccountEmail')
90+
result.networkTags = session.config.navigate('google.batch.networkTags', List.of()) as List<String>
8891
result.retryConfig = new BatchRetryConfig( session.config.navigate('google.batch.retryPolicy') as Map ?: Map.of() )
8992
result.autoRetryExitCodes = session.config.navigate('google.batch.autoRetryExitCodes', DEFAULT_RETRY_LIST) as List<Integer>
9093
return result

plugins/nf-google/src/test/nextflow/cloud/google/batch/GoogleBatchTaskHandlerTest.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class GoogleBatchTaskHandlerTest extends Specification {
149149
getAutoRetryExitCodes() >> [50001,50002]
150150
getSpot() >> true
151151
getNetwork() >> 'net-1'
152+
getNetworkTags() >> ['tag1', 'tag2']
152153
getServiceAccountEmail() >> 'foo@bar.baz'
153154
getSubnetwork() >> 'subnet-1'
154155
getUsePrivateAddress() >> true
@@ -219,6 +220,7 @@ class GoogleBatchTaskHandlerTest extends Specification {
219220
allocationPolicy.getInstances(0).getInstallGpuDrivers() == true
220221
allocationPolicy.getLabelsMap() == [foo: 'bar']
221222
allocationPolicy.getServiceAccount().getEmail() == 'foo@bar.baz'
223+
allocationPolicy.getTagsList() == ['tag1', 'tag2']
222224
and:
223225
instancePolicy.getAccelerators(0).getCount() == 1
224226
instancePolicy.getAccelerators(0).getType() == ACCELERATOR.type

0 commit comments

Comments
 (0)