Skip to content

Commit

Permalink
Updated EM kubernetes data mounting from hostpath to PVC
Browse files Browse the repository at this point in the history
  • Loading branch information
IKCAP committed Sep 12, 2024
1 parent 35dad71 commit 64e0939
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
45 changes: 27 additions & 18 deletions src/classes/localex/kubernetes-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,35 @@ const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
const batchV1Api = kc.makeApiClient(k8s.BatchV1Api);
const k8sLogApi = new k8s.Log(kc);

function get_volumes_and_mounts(folderBindings, podname): [Array<k8s.V1Volume>, Array<k8s.V1VolumeMount>] {
async function get_volumes_and_mounts(dataDirectory, namespace, jobname): Promise<[Array<k8s.V1Volume>, Array<k8s.V1VolumeMount>]> {
let volumes = []
let mounts = []
for(let i in folderBindings) {
let fbindings = folderBindings[i];
let fbinding_array = fbindings.split(":")
let host_path = fbinding_array[0]
let mount_path = fbinding_array[1]
let volume_name = podname + "-volume-" + i
volumes.push({
name: volume_name,
hostPath: {
path: host_path

let ensemble_manager_pvc_name = "mint-ensemble-manager"
if(process.env.ENSEMBLE_MANAGER_PVC) {
ensemble_manager_pvc_name = process.env.ENSEMBLE_MANAGER_PVC
}
else {
let pvcs = await k8sApi.listNamespacedPersistentVolumeClaim(namespace)
for(let i in pvcs.body.items) {
let pvc = pvcs.body.items[i]
let pvcname = pvc.metadata.name
if(pvcname.match("ensemble-manager")) {
ensemble_manager_pvc_name = pvcname
}
})
mounts.push({
name: volume_name,
mountPath: mount_path
})
}
}
let volume_name = jobname + "-volume"
volumes.push({
name: volume_name,
persistentVolumeClaim: {
claimName: ensemble_manager_pvc_name
}
})
mounts.push({
name: volume_name,
mountPath: dataDirectory
})
return [volumes, mounts]
}

Expand All @@ -44,12 +53,12 @@ export const runKubernetesPod = async(
image: string,
logstream: WriteStream,
workingDirectory: string,
folderBindings: string[],
dataDirectory: string,
cpu_limit:string = "200m",
memory_limit:string = "2048Mi"
) => {
let container_name = jobname + "-container";
let [volumes, mounts] = get_volumes_and_mounts(folderBindings, jobname)
let [volumes, mounts] = await get_volumes_and_mounts(dataDirectory, namespace, jobname)

// Create the Job
const jobManifest = {
Expand Down
14 changes: 2 additions & 12 deletions src/classes/localex/seed-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ module.exports = async (job: any) => {
let logstream = fs.createWriteStream(logstdout, { 'flags': 'a' });

// Run command in docker image
const folderBindings = [
`${tempdir}:${tempdir}`,
`${localex.datadir}:${localex.datadir}`
];
let details = get_details_from_cwl(comp, seed, results, cwl_file)

let image = details["image"]
Expand All @@ -209,7 +205,7 @@ module.exports = async (job: any) => {
let cpu_limit = prefs.kubernetes?.cpu_limit || null;
let memory_limit = prefs.kubernetes?.memory_limit || null;

statusCode = await runKubernetesPod(namespace, jobname, cmd_args, image, logstream, tempdir, folderBindings, cpu_limit, memory_limit);
statusCode = await runKubernetesPod(namespace, jobname, cmd_args, image, logstream, tempdir, localex.datadir, cpu_limit, memory_limit);

// Clean up
logstream.close();
Expand Down Expand Up @@ -272,18 +268,12 @@ module.exports = async (job: any) => {
console.log("Running as a Kubernetes Job:" )
let logstream = fs.createWriteStream(logstdout, { 'flags': 'a' });

// Run command in docker image
const folderBindings = [
`${tempdir}:${tempdir}`,
`${localex.datadir}:${localex.datadir}`
];

let jobname = "execution-" + uuidv4()
let namespace = prefs.kubernetes?.namespace || "default";
let cpu_limit = prefs.kubernetes?.cpu_limit || null;
let memory_limit = prefs.kubernetes?.memory_limit || null;

statusCode = await runKubernetesPod(namespace, jobname, args, softwareImage, logstream, tempdir, folderBindings, cpu_limit, memory_limit);
statusCode = await runKubernetesPod(namespace, jobname, args, softwareImage, logstream, tempdir, localex.datadir, cpu_limit, memory_limit);

// Clean up
logstream.close();
Expand Down

0 comments on commit 64e0939

Please sign in to comment.