Skip to content

Commit b7d5ae0

Browse files
authored
allow to set a volume as readOnly (apply only in csi driver) (#62)
Signed-off-by: Jorge Aguilera <[email protected]>
1 parent 0a274d6 commit b7d5ae0

File tree

6 files changed

+94
-8
lines changed

6 files changed

+94
-8
lines changed

plugins/nf-nomad/src/main/nextflow/nomad/config/VolumeSpec.groovy

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class VolumeSpec {
3535
private String name
3636
private String path
3737
private boolean workDir = false
38+
private boolean readOnly = false
3839

3940
String getType() {
4041
return type
@@ -52,6 +53,10 @@ class VolumeSpec {
5253
return path
5354
}
5455

56+
boolean getReadOnly(){
57+
return readOnly
58+
}
59+
5560
VolumeSpec type(String type){
5661
this.type = type
5762
this
@@ -72,6 +77,29 @@ class VolumeSpec {
7277
this
7378
}
7479

80+
VolumeSpec readOnly(boolean readOnly){
81+
this.readOnly = readOnly
82+
this
83+
}
84+
85+
String getAccessMode(){
86+
return switch (this.type){
87+
case VOLUME_CSI_TYPE->
88+
readOnly ?
89+
"multi-node-reader-only"
90+
:
91+
"multi-node-multi-writer";
92+
default -> ""
93+
}
94+
}
95+
96+
String getAttachmentMode(){
97+
return switch (this.type){
98+
case VOLUME_CSI_TYPE->"file-system";
99+
default -> ""
100+
}
101+
}
102+
75103
void validate(){
76104
if( !VOLUME_TYPES.contains(type) ) {
77105
throw new IllegalArgumentException("Volume type $type is not supported")
@@ -82,5 +110,8 @@ class VolumeSpec {
82110
if( !this.workDir && !this.path ){
83111
throw new IllegalArgumentException("Volume path is required in secondary volumes")
84112
}
113+
if( this.workDir && this.readOnly ){
114+
throw new IllegalArgumentException("WorkingDir Volume can't be readOnly")
115+
}
85116
}
86117
}

plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,17 @@ class NomadService implements Closeable{
139139
taskGroup.volumes["vol_${idx}".toString()] = new VolumeRequest(
140140
type: volumeSpec.type,
141141
source: volumeSpec.name,
142-
attachmentMode: "file-system",
143-
accessMode: "multi-node-multi-writer"
142+
attachmentMode: volumeSpec.attachmentMode,
143+
accessMode: volumeSpec.accessMode,
144+
readOnly: volumeSpec.readOnly,
144145
)
145146
}
146147

147148
if (volumeSpec && volumeSpec.type == VolumeSpec.VOLUME_HOST_TYPE) {
148149
taskGroup.volumes["vol_${idx}".toString()] = new VolumeRequest(
149150
type: volumeSpec.type,
150151
source: volumeSpec.name,
152+
readOnly: volumeSpec.readOnly,
151153
)
152154
}
153155
}
@@ -326,6 +328,9 @@ class NomadService implements Closeable{
326328
String getClientOfJob(String jobId) {
327329
try{
328330
List<AllocationListStub> allocations = jobsApi.getJobAllocations(jobId, config.jobOpts().region, config.jobOpts().namespace, null, null, null, null, null, null, null, null)
331+
if( !allocations ){
332+
return null
333+
}
329334
AllocationListStub jobAllocation = allocations.first()
330335
return jobAllocation.nodeName
331336
}catch (Exception e){

plugins/nf-nomad/src/test/nextflow/nomad/NomadConfigSpec.groovy

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,38 @@ class NomadConfigSpec extends Specification {
261261
def config3 = new NomadConfig([
262262
jobs: [
263263
volumes : [
264-
{ type "csi" name "test" path '/data'},
264+
{ type "csi" name "test" path '/data' readOnly true},
265265
{ type "docker" name "test" path '/data'},
266266
],
267-
volume : { type "host" name "test" },
267+
volume : { type "csi" name "test" },
268268
]
269269
])
270270

271271
then:
272272
config3.jobOpts.volumeSpec.size()==3
273-
config3.jobOpts.volumeSpec[0].type == VolumeSpec.VOLUME_HOST_TYPE
273+
config3.jobOpts.volumeSpec[0].type == VolumeSpec.VOLUME_CSI_TYPE
274274
config3.jobOpts.volumeSpec[1].type == VolumeSpec.VOLUME_CSI_TYPE
275275
config3.jobOpts.volumeSpec[2].type == VolumeSpec.VOLUME_DOCKER_TYPE
276276

277-
config.jobOpts.volumeSpec[0].workDir
278-
config.jobOpts.volumeSpec.findAll{ it.workDir}.size() == 1
277+
config3.jobOpts.volumeSpec[0].workDir
278+
config3.jobOpts.volumeSpec.findAll{ it.workDir}.size() == 1
279+
config3.jobOpts.volumeSpec[0].accessMode == "multi-node-multi-writer"
280+
281+
config3.jobOpts.volumeSpec[1].readOnly
282+
config3.jobOpts.volumeSpec[1].accessMode == "multi-node-reader-only"
283+
284+
when:
285+
new NomadConfig([
286+
jobs: [
287+
volumes : [
288+
{ type "csi" name "test" path '/data' readOnly true},
289+
{ type "docker" name "test" path '/data'},
290+
],
291+
volume : { type "csi" name "test" readOnly true},
292+
]
293+
])
294+
295+
then:
296+
thrown(IllegalArgumentException)
279297
}
280298
}

plugins/nf-nomad/src/test/nextflow/nomad/executor/NomadServiceSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class NomadServiceSpec extends Specification{
370370
body.Job.TaskGroups[0].Tasks[0].Config.args == args.drop(1)
371371

372372
body.Job.TaskGroups[0].Volumes.size() == 1
373-
body.Job.TaskGroups[0].Volumes['vol_0'] == [AccessMode:"multi-node-multi-writer", AttachmentMode:"file-system", Source:"test", Type:"csi"]
373+
body.Job.TaskGroups[0].Volumes['vol_0'] == [AccessMode:"multi-node-multi-writer", AttachmentMode:"file-system", Source:"test", Type:"csi", ReadOnly:false]
374374
body.Job.TaskGroups[0].Tasks[0].VolumeMounts.size() == 1
375375
body.Job.TaskGroups[0].Tasks[0].VolumeMounts[0] == [Destination:"/a", Volume:"vol_0"]
376376

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
plugins {
2+
id 'nf-nomad@latest'
3+
}
4+
5+
process {
6+
executor = "nomad"
7+
}
8+
9+
nomad {
10+
11+
client {
12+
address = "http://10.0.2.6:4646"
13+
}
14+
15+
jobs {
16+
deleteOnCompletion = false
17+
namespace = "nf"
18+
volumes = [
19+
{ type "csi" name "nextflow-fs-volume" },
20+
{ type "csi" name "nextflow-fs-volume" path "/var/data" readOnly true}
21+
]
22+
}
23+
}

validation/run-all.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ if [ "$SKIPLOCAL" == 0 ]; then
2525

2626
./run-pipeline.sh -c basic/nextflow.config basic/main.nf
2727

28+
./run-pipeline.sh -c directives/nextflow.config directives/main.nf
29+
30+
./run-pipeline.sh -c multiple-volumes/2-volumes.config multiple-volumes/main.nf
31+
32+
./run-pipeline.sh -c multiple-volumes/3-volumes.config multiple-volumes/main.nf
33+
2834
./run-pipeline.sh -c basic/nextflow.config nf-core/demo \
2935
-r dev -profile test,docker \
3036
--outdir $(pwd)/nomad_temp/scratchdir/out
@@ -46,6 +52,9 @@ if [ "$NFAZURE" == 1 ]; then
4652
ssh manager@nfazure \
4753
'cd ~/integration-tests/az-nomadlab; NXF_ASSETS=/projects/assets nextflow run hello -w /projects/ -c nextflow.config'
4854

55+
ssh manager@nfazure \
56+
'cd ~/integration-tests/az-nomadlab; NXF_ASSETS=/projects/assets nextflow run hello -w /projects/ -c 2-volumes.config'
57+
4958
ssh manager@nfazure \
5059
'cd ~/integration-tests/az-nomadlab; NXF_ASSETS=/projects/assets nextflow run bactopia/bactopia -c nextflow.config -w /projects -profile test,docker --outdir /projects/bactopia/outdir --accession SRX4563634 --coverage 100 --genome_size 2800000 --datasets_cache /projects/bactopia/datasets'
5160
else

0 commit comments

Comments
 (0)