Skip to content

Commit 502849a

Browse files
authored
Add support for Ceph user volumes (through PVC) (#49)
* Add support for Ceph user volumes (through PVC) * Fix checkstyle errors * Fix checkstyle errors
1 parent 7c20316 commit 502849a

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

components/java/compute/src/org/sciserver/compute/core/container/KubernetesExecutableManager2.java

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import java.util.LinkedList;
4141
import java.util.List;
4242
import java.util.Map;
43+
import java.util.regex.Matcher;
44+
import java.util.regex.Pattern;
4345
import org.sciserver.authentication.client.AuthenticatedUser;
4446
import org.sciserver.compute.AppConfig;
4547
import org.sciserver.compute.core.registry.Container;
@@ -255,13 +257,58 @@ public ExecutableContainer createContainer(String name, String description, Auth
255257
}
256258
}
257259

258-
private void addVolumes(String source, String dest, Boolean ro, List<V1Volume> vols, List<V1VolumeMount> mounts) {
259-
String srv = source.split("/")[2];
260-
String path = "/" + source.split("/", 4)[3];
261-
String name = "vol-" + vols.size();
262-
vols.add(new V1VolumeBuilder().withName(name).withNewNfs().withServer(srv).withPath(path).withReadOnly(ro)
263-
.endNfs().build());
264-
mounts.add(new V1VolumeMountBuilder().withName(name).withMountPath(dest).withReadOnly(ro).build());
260+
private void addVolumes(String source, String dest, Boolean ro, List<V1Volume> vols, List<V1VolumeMount> mounts)
261+
throws Exception {
262+
Pattern pattern = Pattern.compile("(.*)://([^/]+)/(.*)");
263+
Matcher matcher = pattern.matcher(source);
264+
if (matcher.find()) {
265+
String type = matcher.group(1);
266+
String srv = matcher.group(2);
267+
String path = matcher.group(3);
268+
String name = "vol-" + vols.size();
269+
270+
V1Volume volume = null;
271+
V1VolumeMount volumeMount = null;
272+
273+
switch (type) {
274+
case "nfs":
275+
volume = new V1VolumeBuilder()
276+
.withName(name)
277+
.withNewNfs()
278+
.withServer(srv)
279+
.withPath(path)
280+
.withReadOnly(ro)
281+
.endNfs()
282+
.build();
283+
volumeMount = new V1VolumeMountBuilder()
284+
.withName(name)
285+
.withMountPath(dest)
286+
.withReadOnly(ro)
287+
.build();
288+
break;
289+
case "pvc":
290+
volume = new V1VolumeBuilder()
291+
.withName(name)
292+
.withNewPersistentVolumeClaim()
293+
.withClaimName(srv)
294+
.endPersistentVolumeClaim()
295+
.build();
296+
volumeMount = new V1VolumeMountBuilder()
297+
.withName(name)
298+
.withSubPath(path)
299+
.withMountPath(dest)
300+
.withReadOnly(ro)
301+
.build();
302+
break;
303+
default:
304+
throw new Exception("Unrecognized mount type: " + type);
305+
}
306+
307+
vols.add(volume);
308+
mounts.add(volumeMount);
309+
} else {
310+
throw new Exception("Cannot parse mount source: " + source);
311+
}
265312
}
266313

267314
@Override

0 commit comments

Comments
 (0)