Skip to content

Commit e2a1cab

Browse files
authored
Merge pull request #94 from dciangot/feature/startup-probe-support
feat: add support for Kubernetes startup probes
2 parents 7a40736 + fac72a0 commit e2a1cab

File tree

8 files changed

+233
-26
lines changed

8 files changed

+233
-26
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
envs.sh
22
bin
3+
vendor/
4+
35
# Eclipse IDE
46
.project
57
.settings
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: startup-probe-test-pod
5+
namespace: vk
6+
spec:
7+
containers:
8+
- name: app-container
9+
image: nginx:alpine
10+
ports:
11+
- containerPort: 80
12+
startupProbe:
13+
httpGet:
14+
path: /
15+
port: 80
16+
scheme: HTTP
17+
initialDelaySeconds: 300
18+
periodSeconds: 10
19+
timeoutSeconds: 5
20+
successThreshold: 1
21+
failureThreshold: 3
22+
readinessProbe:
23+
httpGet:
24+
path: /
25+
port: 80
26+
scheme: HTTP
27+
initialDelaySeconds: 5
28+
periodSeconds: 10
29+
timeoutSeconds: 5
30+
successThreshold: 1
31+
failureThreshold: 3
32+
livenessProbe:
33+
httpGet:
34+
path: /
35+
port: 80
36+
scheme: HTTP
37+
initialDelaySeconds: 15
38+
periodSeconds: 20
39+
timeoutSeconds: 5
40+
successThreshold: 1
41+
failureThreshold: 3
42+
restartPolicy: Always

pkg/slurm/Create.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,15 @@ func (h *SidecarHandler) SubmitHandler(w http.ResponseWriter, r *http.Request) {
148148
)
149149

150150
// Process probes if enabled
151-
var readinessProbes, livenessProbes []ProbeCommand
151+
var readinessProbes, livenessProbes, startupProbes []ProbeCommand
152152
if h.Config.EnableProbes && !isInit {
153-
readinessProbes, livenessProbes = translateKubernetesProbes(spanCtx, container)
154-
if len(readinessProbes) > 0 || len(livenessProbes) > 0 {
153+
readinessProbes, livenessProbes, startupProbes = translateKubernetesProbes(spanCtx, container)
154+
if len(readinessProbes) > 0 || len(livenessProbes) > 0 || len(startupProbes) > 0 {
155155
log.G(h.Ctx).Info("-- Container " + container.Name + " has probes configured")
156156
span.SetAttributes(
157157
attribute.Int("job.container"+strconv.Itoa(i)+".readiness_probes", len(readinessProbes)),
158158
attribute.Int("job.container"+strconv.Itoa(i)+".liveness_probes", len(livenessProbes)),
159+
attribute.Int("job.container"+strconv.Itoa(i)+".startup_probes", len(startupProbes)),
159160
)
160161
}
161162
}
@@ -168,6 +169,7 @@ func (h *SidecarHandler) SubmitHandler(w http.ResponseWriter, r *http.Request) {
168169
isInitContainer: isInit,
169170
readinessProbes: readinessProbes,
170171
livenessProbes: livenessProbes,
172+
startupProbes: startupProbes,
171173
containerImage: image,
172174
})
173175
}

pkg/slurm/Status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (h *SidecarHandler) StatusHandler(w http.ResponseWriter, r *http.Request) {
212212
}
213213
for _, ct := range pod.Spec.Containers {
214214
// Check probe status for container readiness
215-
readinessCount, _, err := loadProbeMetadata(path, ct.Name)
215+
readinessCount, _, _, err := loadProbeMetadata(path, ct.Name)
216216
isReady := true
217217
if err != nil {
218218
log.G(h.Ctx).Debug("Failed to load probe metadata for container ", ct.Name, ": ", err)
@@ -287,7 +287,7 @@ func (h *SidecarHandler) StatusHandler(w http.ResponseWriter, r *http.Request) {
287287
}
288288
for _, ct := range pod.Spec.Containers {
289289
// Check probe status for container readiness
290-
readinessCount, _, err := loadProbeMetadata(path, ct.Name)
290+
readinessCount, _, _, err := loadProbeMetadata(path, ct.Name)
291291
isReady := true
292292
if err != nil {
293293
log.G(h.Ctx).Debug("Failed to load probe metadata for container ", ct.Name, ": ", err)

pkg/slurm/func.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ func NewSlurmConfig() (SlurmConfig, error) {
9898

9999
SlurmConfigInst.Tsockspath = path
100100
}
101+
102+
// Set default ContainerRuntime if not configured
103+
if SlurmConfigInst.ContainerRuntime == "" {
104+
SlurmConfigInst.ContainerRuntime = "singularity"
105+
}
106+
101107
// Check if a supported container runtime is configured (supported: singularity, enroot)
102108
if SlurmConfigInst.ContainerRuntime != "singularity" && SlurmConfigInst.ContainerRuntime != "enroot" {
103109
err := fmt.Errorf("container runtime %q is not supported. Please configure a supported one (singularity, enroot)", SlurmConfigInst.ContainerRuntime)

pkg/slurm/prepare.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -836,15 +836,15 @@ highestExitCode=0
836836
// Generate probe cleanup script first if any probes exist
837837
var hasProbes bool
838838
for _, containerCommand := range commands {
839-
if len(containerCommand.readinessProbes) > 0 || len(containerCommand.livenessProbes) > 0 {
839+
if len(containerCommand.readinessProbes) > 0 || len(containerCommand.livenessProbes) > 0 || len(containerCommand.startupProbes) > 0 {
840840
hasProbes = true
841841
break
842842
}
843843
}
844844
if hasProbes && config.EnableProbes {
845845
for _, containerCommand := range commands {
846-
if len(containerCommand.readinessProbes) > 0 || len(containerCommand.livenessProbes) > 0 {
847-
cleanupScript := generateProbeCleanupScript(containerCommand.containerName, containerCommand.readinessProbes, containerCommand.livenessProbes)
846+
if len(containerCommand.readinessProbes) > 0 || len(containerCommand.livenessProbes) > 0 || len(containerCommand.startupProbes) > 0 {
847+
cleanupScript := generateProbeCleanupScript(containerCommand.containerName, containerCommand.readinessProbes, containerCommand.livenessProbes, containerCommand.startupProbes)
848848
stringToBeWritten.WriteString(cleanupScript)
849849
break // Only need one cleanup script
850850
}
@@ -898,7 +898,7 @@ highestExitCode=0
898898
}
899899

900900
// Generate probe scripts if enabled and not an init container
901-
if config.EnableProbes && !containerCommand.isInitContainer && (len(containerCommand.readinessProbes) > 0 || len(containerCommand.livenessProbes) > 0) {
901+
if config.EnableProbes && !containerCommand.isInitContainer && (len(containerCommand.readinessProbes) > 0 || len(containerCommand.livenessProbes) > 0 || len(containerCommand.startupProbes) > 0) {
902902
// Extract the image name from the singularity command
903903
var imageName string
904904
for i, arg := range containerCommand.runtimeCommand {
@@ -922,12 +922,12 @@ highestExitCode=0
922922

923923
if imageName != "" {
924924
// Store probe metadata for status checking
925-
err := storeProbeMetadata(path, containerCommand.containerName, len(containerCommand.readinessProbes), len(containerCommand.livenessProbes))
925+
err := storeProbeMetadata(path, containerCommand.containerName, len(containerCommand.readinessProbes), len(containerCommand.livenessProbes), len(containerCommand.startupProbes))
926926
if err != nil {
927927
log.G(Ctx).Error("Failed to store probe metadata: ", err)
928928
}
929929

930-
probeScript := generateProbeScript(Ctx, config, containerCommand.containerName, imageName, containerCommand.readinessProbes, containerCommand.livenessProbes)
930+
probeScript := generateProbeScript(Ctx, config, containerCommand.containerName, imageName, containerCommand.readinessProbes, containerCommand.livenessProbes, containerCommand.startupProbes)
931931
stringToBeWritten.WriteString("\n")
932932
stringToBeWritten.WriteString(probeScript)
933933
}
@@ -1381,7 +1381,7 @@ func prepareRuntimeCommand(config SlurmConfig, container v1.Container, metadata
13811381
singularityOptions = singOpts
13821382
}
13831383

1384-
// See https://github.com/interTwin-eu/interlink-slurm-plugin/issues/32#issuecomment-2416031030
1384+
// See https://github.com/interlink-hq/interlink-slurm-plugin/issues/32#issuecomment-2416031030
13851385
// singularity run will honor the entrypoint/command (if exist) in container image, while exec will override entrypoint.
13861386
// Thus if pod command (equivalent to container entrypoint) exist, we do exec, and other case we do run
13871387
singularityCommand := ""

0 commit comments

Comments
 (0)