@@ -196,30 +196,15 @@ func (h *SidecarHandler) prepareDockerRuns(podData commonIL.RetrievedPodData, w
196196 cmd = append (cmd , fpgaArgs )
197197 }
198198
199- cmd = append (cmd , "-p" , "8888:8888" )
200-
201- // if podIp != "" {
202- // // add --ip flag to the docker run command
203- // cmd = append(cmd, "--ip", podIp)
204-
205- // // add --net vk0
206- // cmd = append(cmd, "--net", "vk0")
207-
208- // // --dns 10.96.0.10
209- // cmd = append(cmd, "--dns", "10.96.0.10")
210-
211- // // add NET_ADMIN capability
212- // cmd = append(cmd, "--cap-add", "NET_ADMIN")
213- // }
214-
215199 var additionalPortArgs []string
216200
217201 for _ , port := range container .Ports {
218- if port .HostPort != 0 {
219- additionalPortArgs = append (additionalPortArgs , "-p" , strconv .Itoa (int (port .HostPort ))+ ":" + strconv .Itoa (int (port .ContainerPort )))
220- }
202+ log .G (h .Ctx ).Info ("\u2705 [POD FLOW] Container port: " + strconv .Itoa (int (port .ContainerPort )) + " Protocol: " + string (port .Protocol ) + " HostPort: " + strconv .Itoa (int (port .HostPort )))
203+ additionalPortArgs = append (additionalPortArgs , "-p" , strconv .Itoa (int (port .ContainerPort ))+ ":" + strconv .Itoa (int (port .ContainerPort )))
221204 }
222205
206+ log .G (h .Ctx ).Info ("\u2705 [POD FLOW] Additional port arguments for container " + containerName + ": " + strings .Join (additionalPortArgs , " " ))
207+
223208 cmd = append (cmd , additionalPortArgs ... )
224209
225210 mounts , err := prepareMounts (h .Ctx , h .Config , podData , container )
@@ -363,6 +348,10 @@ func (h *SidecarHandler) CreateHandler(w http.ResponseWriter, r *http.Request) {
363348
364349 podDirectoryPath := filepath .Join (wd , h .Config .DataRootFolder + "/" + podNamespace + "-" + podUID )
365350
351+ // Sentinel file written by mesh.sh once network setup is complete.
352+ // containers_command.sh polls for this file before starting workload containers.
353+ meshReadyFile := filepath .Join (podDirectoryPath , "mesh_ready" )
354+
366355 // log the pod specifics
367356 log .G (h .Ctx ).Info (fmt .Sprintf ("\u2705 [POD FLOW] Pod specs: %+v" , data .Pod ))
368357
@@ -424,14 +413,17 @@ func (h *SidecarHandler) CreateHandler(w http.ResponseWriter, r *http.Request) {
424413 // Remove the slirp4netns execution at the end of inner script
425414 innerScript = removeSlirp4netnsExecution (innerScript )
426415
427- // Replace command execution with sleep infinity
428- innerScript = strings .Replace (innerScript , "$@" , "sleep infinity" , - 1 )
416+ // Replace command execution with a sentinel touch followed by sleep infinity.
417+ // The sentinel file signals to containers_command.sh that network setup is done.
418+ innerScript = strings .Replace (innerScript , "$@" , "touch " + meshReadyFile + " && sleep infinity" , - 1 )
429419
430420 // Build the complete script with correct order
431421 meshScript = `#!/bin/bash
432422set -e
433423set -m
434424
425+ sleep 20s
426+
435427export PATH=$PATH:$PWD:/usr/sbin:/sbin
436428
437429# Set up temporary directory
@@ -447,10 +439,10 @@ cd $TMPDIR
447439
448440` + innerScript
449441 } else {
450- // Fallback: just clean up the outer script
442+ // Fallback: just clean up the outer script, still touch the sentinel before sleeping.
451443 meshScript = removeSlirp4netnsDownload (meshScript )
452444 meshScript = removeUnshareWrapper (meshScript )
453- meshScript = strings .Replace (meshScript , "$@" , "sleep infinity" , - 1 )
445+ meshScript = strings .Replace (meshScript , "$@" , "touch " + meshReadyFile + " && sleep infinity" , - 1 )
454446 meshScript = removeSlirp4netnsExecution (meshScript )
455447 }
456448
@@ -702,12 +694,23 @@ echo "DNS configured for cluster connectivity"
702694 dnsSearch = "default.svc.cluster.local svc.cluster.local cluster.local" // Fallback
703695 }
704696
705- // Add a delay to ensure network container is ready
697+ // The first container in the list is the network-overlay; start it immediately.
698+ // All subsequent containers are workload containers and must wait for the sentinel.
699+ networkOverlay := containers [0 ]
700+ workloadContainers := containers [1 :]
701+
702+ containersCommand += "# Start network overlay container first\n "
703+ containersCommand += networkOverlay .Command + "\n \n "
704+
705+ // Poll for the sentinel file written by mesh.sh once network setup is complete.
706706 containersCommand += "echo 'Waiting for network overlay to be ready...'\n "
707- containersCommand += "sleep 10\n "
708- containersCommand += "echo 'Starting containers...'\n \n "
707+ containersCommand += "while [ ! -f " + meshReadyFile + " ]; do\n "
708+ containersCommand += " echo 'Network not ready yet, waiting 2s...'\n "
709+ containersCommand += " sleep 2\n "
710+ containersCommand += "done\n "
711+ containersCommand += "echo 'Network overlay is ready (sentinel file found), starting containers...'\n \n "
709712
710- for _ , container := range containers {
713+ for _ , container := range workloadContainers {
711714 containersCommand += "# Start container: " + container .Name + "\n "
712715 containersCommand += container .Command + "\n "
713716 containersCommand += "sleep 2\n "
@@ -718,16 +721,17 @@ echo "DNS configured for cluster connectivity"
718721 containersCommand += "cp /etc/resolv.conf /etc/resolv.conf.backup 2>/dev/null || true\n "
719722 containersCommand += "cat > /etc/resolv.conf << EOF\n "
720723 containersCommand += "nameserver " + dnsNameserver + "\n "
724+ containersCommand += "nameserver 8.8.8.8 \n "
721725 containersCommand += "search " + dnsSearch + "\n "
722726 containersCommand += "EOF\n "
723727 containersCommand += "' || echo 'Warning: Could not configure DNS for " + container .Name + "'\n "
724728 containersCommand += "echo 'DNS configured for container: " + container .Name + "'\n \n "
725729 }
726- }
727-
728- for _ , container := range containers {
729- containersCommand += container . Command + " \n "
730- containersCommand += "sleep 30 \n "
730+ } else {
731+ for _ , container := range containers {
732+ containersCommand += container . Command + " \n "
733+ containersCommand += "sleep 1 \n "
734+ }
731735 }
732736 err = os .WriteFile (podDirectoryPath + "/containers_command.sh" , []byte (containersCommand ), 0644 )
733737 if err != nil {
0 commit comments