Skip to content

Commit c3b826f

Browse files
committed
102-handle-meshsh-script-generation-coming-from-vk
1 parent 666272a commit c3b826f

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

docker/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ ENV TIMEZONE=America/New_York
1616
# Install system packages
1717
RUN DEBIAN_FRONTEND=noninteractive \
1818
dnf install -y epel-release \
19-
&& dnf install -y slurm-slurmd rpm-build slurm-slurmctld apptainer sshpass \
19+
&& dnf install -y --allowerasing slurm-slurmd rpm-build slurm-slurmctld apptainer sshpass slirp4netns iproute curl tar xz make gcc ca-certificates \
20+
&& update-ca-trust \
2021
&& dnf clean all
2122

2223
RUN slurm-setuser -y
@@ -52,4 +53,4 @@ ENV SLURMCONFIGPATH=/root/SlurmConfig.yaml
5253

5354
RUN mkdir -p /cvmfs/grid.cern.ch/etc/grid-security
5455

55-
ENTRYPOINT ["/bin/sh", "-c", "/etc/startup.sh && SHARED_FS=true /sidecar/slurm-sidecar "]
56+
ENTRYPOINT ["/bin/sh", "-c", "/etc/startup.sh && SHARED_FS=true /sidecar/slurm-sidecar "]

pkg/slurm/prepare.go

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,32 @@ type FlavorResolution struct {
6161
SlurmFlags []string
6262
}
6363

64+
func extractHeredoc(content, marker string) (string, error) {
65+
// Find the start of the heredoc
66+
startPattern := fmt.Sprintf("cat <<'%s'", marker)
67+
startIdx := strings.Index(content, startPattern)
68+
if startIdx == -1 {
69+
return "", fmt.Errorf("heredoc start marker not found")
70+
}
71+
72+
// Find the line after the cat command (start of actual content)
73+
contentStart := strings.Index(content[startIdx:], "\n")
74+
if contentStart == -1 {
75+
return "", fmt.Errorf("invalid heredoc format")
76+
}
77+
contentStart += startIdx + 1
78+
79+
// Find the end marker
80+
endMarker := "\n" + marker
81+
endIdx := strings.Index(content[contentStart:], endMarker)
82+
if endIdx == -1 {
83+
return "", fmt.Errorf("heredoc end marker not found")
84+
}
85+
86+
// Extract the content between start and end markers
87+
return content[contentStart : contentStart+endIdx], nil
88+
}
89+
6490
// stringToHex encodes the provided str string into a hex string and removes all trailing redundant zeroes to keep the output more compact
6591
func stringToHex(str string) string {
6692
var buffer bytes.Buffer
@@ -955,7 +981,39 @@ func produceSLURMScript(
955981
}
956982

957983
if preExecAnnotations, ok := metadata.Annotations["slurm-job.vk.io/pre-exec"]; ok {
958-
prefix += "\n" + preExecAnnotations
984+
// Check if pre-exec contains a heredoc that creates mesh.sh
985+
if strings.Contains(preExecAnnotations, "cat <<'EOFMESH' > $TMPDIR/mesh.sh") {
986+
// Extract the heredoc content
987+
meshScript, err := extractHeredoc(preExecAnnotations, "EOFMESH")
988+
if err == nil && meshScript != "" {
989+
990+
meshPath := filepath.Join(path, "mesh.sh")
991+
err := os.WriteFile(meshPath, []byte(meshScript), 0755)
992+
if err != nil {
993+
// Fallback: include the full pre-exec as-is
994+
prefix += "\n" + preExecAnnotations
995+
} else {
996+
// Successfully wrote mesh.sh, just add the execution command
997+
//prefix += "\n" + fmt.Sprintf("source %s", meshPath)
998+
prefix += "\n" + fmt.Sprintf(" %s", meshPath)
999+
}
1000+
1001+
err = os.Chmod(path+"/mesh.sh", 0774)
1002+
if err != nil {
1003+
log.G(Ctx).Error("Unable to chmod file ", path, "/job.sh")
1004+
log.G(Ctx).Error(err)
1005+
return "", err
1006+
} else {
1007+
log.G(Ctx).Debug("--- Created with correct permission file ", path, "/job.sh")
1008+
}
1009+
} else {
1010+
// Could not extract heredoc, include as-is
1011+
prefix += "\n" + preExecAnnotations
1012+
}
1013+
} else {
1014+
// No heredoc pattern, include pre-exec as-is
1015+
prefix += "\n" + preExecAnnotations
1016+
}
9591017
}
9601018

9611019
sbatch_macros := "#!" + config.BashPath +

0 commit comments

Comments
 (0)