Skip to content

Commit bdb9fcd

Browse files
committed
updated with latest changes in main
2 parents dfabf3d + 9e181a7 commit bdb9fcd

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

pkg/docker/Create.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,30 @@ func (h *SidecarHandler) CreateHandler(w http.ResponseWriter, r *http.Request) {
285285
dindImage = "docker:dind"
286286
}
287287

288+
// create a dedicated docker network for the dind container
289+
shell := exec.ExecTask{
290+
Command: "docker",
291+
Args: []string{"network", "create", "--driver", "bridge", string(data.Pod.UID) + "_dind_network"},
292+
Shell: true,
293+
}
294+
execReturn, err = shell.Execute()
295+
if err != nil {
296+
HandleErrorAndRemoveData(h, w, "An error occurred during the creation of the network for the DIND container", err, "", "")
297+
return
298+
}
299+
288300
dindContainerArgs := []string{"run"}
289301
dindContainerArgs = append(dindContainerArgs, gpuArgsAsArray...)
290302
if _, err := os.Stat("/cvmfs"); err == nil {
291303
dindContainerArgs = append(dindContainerArgs, "-v", "/cvmfs:/cvmfs")
292304
}
293305

306+
// add the network to the dind container
307+
dindContainerArgs = append(dindContainerArgs, "--network", string(data.Pod.UID)+"_dind_network")
294308
dindContainerArgs = append(dindContainerArgs, "--privileged", "-v", wd+":/"+wd, "-v", "/home:/home", "-v", "/var/lib/docker/overlay2:/var/lib/docker/overlay2", "-v", "/var/lib/docker/image:/var/lib/docker/image", "-d", "--name", string(data.Pod.UID)+"_dind", dindImage)
295309

296310
var dindContainerID string
297-
shell := exec.ExecTask{
311+
shell = exec.ExecTask{
298312
Command: "docker",
299313
Args: dindContainerArgs,
300314
Shell: true,

pkg/docker/Delete.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,21 @@ func (h *SidecarHandler) DeleteHandler(w http.ResponseWriter, r *http.Request) {
110110
log.G(h.Ctx).Info("\u2705 [DELETE CALL] Deleted container " + podUID + "_dind")
111111
}
112112

113-
// check if the container has GPU devices attacched using the GpuManager and release them
113+
// delete also the network of the docker dind container that is called string(data.Pod.UID) + "_dind_network"
114+
cmd = []string{"network", "rm", podUID + "_dind_network"}
115+
shell = exec.ExecTask{
116+
Command: "docker",
117+
Args: cmd,
118+
Shell: true,
119+
}
120+
execReturn, _ = shell.Execute()
121+
execReturn.Stdout = strings.ReplaceAll(execReturn.Stdout, "\n", "")
122+
if execReturn.Stderr != "" {
123+
log.G(h.Ctx).Error("\u274C [DELETE CALL] Error deleting network " + podUID + "_dind_network")
124+
} else {
125+
log.G(h.Ctx).Info("\u2705 [DELETE CALL] Deleted network " + podUID + "_dind_network")
126+
}
127+
114128
wd, err := os.Getwd()
115129
if err != nil {
116130
HandleErrorAndRemoveData(h, w, "Unable to get current working directory", err, "", "")

0 commit comments

Comments
 (0)