Skip to content

Commit

Permalink
container arguments are now passed inside a file mounted from singula…
Browse files Browse the repository at this point in the history
…rity

Signed-off-by: Surax98 <[email protected]>
  • Loading branch information
Surax98 committed Jun 6, 2024
1 parent ab203ca commit a7ab00c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 1 addition & 3 deletions pkg/slurm/Create.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ func (h *SidecarHandler) SubmitHandler(w http.ResponseWriter, r *http.Request) {
singularity_command := append(commstr1, envs...)
singularity_command = append(singularity_command, mounts...)
singularity_command = append(singularity_command, image)
singularity_command = append(singularity_command, container.Command...)
singularity_command = append(singularity_command, container.Args...)

singularity_command_pod = append(singularity_command_pod, SingularityCommand{command: singularity_command, containerName: container.Name})
singularity_command_pod = append(singularity_command_pod, SingularityCommand{singularityCommand: singularity_command, containerName: container.Name, containerArgs: container.Args, containerCommand: container.Command})
}

path, err := produceSLURMScript(h.Ctx, h.Config, string(data.Pod.UID), filesPath, metadata, singularity_command_pod)
Expand Down
20 changes: 16 additions & 4 deletions pkg/slurm/aux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ type JidStruct struct {
}

type SingularityCommand struct {
containerName string
command []string
containerName string
singularityCommand []string
containerCommand []string
containerArgs []string
}

// stringToHex encodes the provided str string into a hex string and removes all trailing redundant zeroes to keep the output more compact
Expand Down Expand Up @@ -280,6 +282,11 @@ func prepareMounts(
}
}
}

if container.Command != nil {
mountedData += config.DataRootFolder + podData.Pod.Namespace + "-" + string(podData.Pod.UID) + "/" + "commands_" + container.Name + ".sh" +
":" + "/" + "commands_" + container.Name + ".sh"
}
}

if last := len(mountedData) - 1; last >= 0 && mountedData[last] == ',' {
Expand Down Expand Up @@ -342,7 +349,7 @@ func produceSLURMScript(
if mpiFlags != "true" {
mpi := append([]string{"mpiexec", "-np", "$SLURM_NTASKS"}, strings.Split(mpiFlags, " ")...)
for _, singularityCommand := range commands {
singularityCommand.command = append(mpi, singularityCommand.command...)
singularityCommand.singularityCommand = append(mpi, singularityCommand.singularityCommand...)
}
}
}
Expand Down Expand Up @@ -395,7 +402,12 @@ func produceSLURMScript(
stringToBeWritten += sbatch_macros

for _, singularityCommand := range commands {
stringToBeWritten += "\n" + strings.Join(singularityCommand.command[:], " ") +
stringToBeWritten += "\necho \"" + strings.Join(singularityCommand.containerArgs[:], " ") + "\" > " +
path + "/" + "commands_" + singularityCommand.containerName + ".sh" +
"\nchmod +x " + path + "/" + "commands_" + singularityCommand.containerName + ".sh"

stringToBeWritten += "\n" + strings.Join(singularityCommand.singularityCommand[:], " ") + " " +
strings.Join(singularityCommand.containerCommand[:], " ") + " /" + "commands_" + singularityCommand.containerName + ".sh" +
" &> " + path + "/" + singularityCommand.containerName + ".out; " +
"echo $? > " + path + "/" + singularityCommand.containerName + ".status &"
}
Expand Down

0 comments on commit a7ab00c

Please sign in to comment.