Skip to content

Commit

Permalink
updated dind handling when create is called
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianco95 committed Aug 26, 2024
1 parent d5f0f09 commit b8be319
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pkg/docker/Create.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ func (h *SidecarHandler) CreateHandler(w http.ResponseWriter, r *http.Request) {

log.G(h.Ctx).Info("\u23F3 [CREATE CALL] Received create call from InterLink ")

// create bool variable to set if a new dind container has to be created
newDindContainerCreated := false

// get a dind container ID from dind manager of the sidecard handler
dindContainerID, err := h.DindManager.GetAvailableDind()
if err != nil {
Expand All @@ -258,6 +261,7 @@ func (h *SidecarHandler) CreateHandler(w http.ResponseWriter, r *http.Request) {
HandleErrorAndRemoveData(h, w, "During creation of new DIND container, an error occurred during the request of get available DIND container", err, "", "")
return
}
newDindContainerCreated = true
}

// remove the dind container from the list of available dind containers
Expand All @@ -267,8 +271,10 @@ func (h *SidecarHandler) CreateHandler(w http.ResponseWriter, r *http.Request) {
return
}

// create a new dind container in background
go h.DindManager.BuildDindContainers(1)
if !newDindContainerCreated {
// create a new dind container in background
go h.DindManager.BuildDindContainers(1)
}

//var execReturn exec.ExecResult
statusCode := http.StatusOK
Expand Down
7 changes: 6 additions & 1 deletion pkg/docker/dindmanager/DindHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ func (a *DindManager) BuildDindContainers(nDindContainer int8) error {

// add the network to the dind container
dindContainerArgs = append(dindContainerArgs, "--network", randUID+"_dind_network")
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", "--runtime=nvidia", "-d", "--name", randUID+"_dind", dindImage)
// "--runtime=nvidia" is added to the dind container if the GPUENABLED env variable is set to 1

if gpuEnabled == "1" {
dindContainerArgs = append(dindContainerArgs, "--runtime=nvidia")
}
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", randUID+"_dind", dindImage)

var dindContainerID string
shell = exec.ExecTask{
Expand Down

0 comments on commit b8be319

Please sign in to comment.