Skip to content

Commit

Permalink
updated handling of delete danglind data
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianco95 committed Sep 13, 2024
1 parent c62cabc commit 7d68646
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions pkg/docker/Create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,25 @@ import (
"errors"

commonIL "github.com/intertwin-eu/interlink-docker-plugin/pkg/common"
"github.com/intertwin-eu/interlink-docker-plugin/pkg/docker/dindmanager"

"path/filepath"
)

func (h *SidecarHandler) CheckGpuRequestFromContainer(containerData v1.Container) error {

numGpusRequested := 0
if val, ok := containerData.Resources.Limits["nvidia.com/gpu"]; ok {
numGpusRequested = int(val.Value())
}

if numGpusRequested > 0 {
return errors.New("GPU requests are not supported")
}

return nil
}

func (h *SidecarHandler) prepareDockerRuns(podData commonIL.RetrievedPodData, w http.ResponseWriter) ([]DockerRunStruct, error) {

var dockerRunStructs []DockerRunStruct
Expand Down Expand Up @@ -77,6 +92,12 @@ func (h *SidecarHandler) prepareDockerRuns(podData commonIL.RetrievedPodData, w

containerName := podNamespace + "-" + podUID + "-" + container.Name

// check if the container has GPU requests
err := h.CheckGpuRequestFromContainer(container)
if err != nil {
return dockerRunStructs, errors.New("GPU requests are not supported")
}

var envVars string = ""
for _, envVar := range container.Env {
if envVar.Value != "" {
Expand Down Expand Up @@ -518,4 +539,35 @@ func HandleErrorAndRemoveData(h *SidecarHandler, w http.ResponseWriter, s string
if podNamespace != "" && podUID != "" {
os.RemoveAll(h.Config.DataRootFolder + podNamespace + "-" + podUID)
}

dindSpec := dindmanager.DindSpecs{}
dindSpec, err = h.DindManager.GetDindFromPodUID(podUID)

if err != nil {
log.G(h.Ctx).Error("\u274C [CREATE CALL] Error retrieving DindSpecs, maybe the Dind container has already been deleted")
} else {
log.G(h.Ctx).Info("\u2705 [CREATE CALL] Retrieved DindSpecs: " + dindSpec.DindID + " " + dindSpec.PodUID + " " + dindSpec.DindNetworkID + " ")

// log the retrieved dindSpec
log.G(h.Ctx).Info("\u2705 [CREATE CALL] Retrieved DindSpecs: " + dindSpec.DindID + " " + dindSpec.PodUID + " " + dindSpec.DindNetworkID + " ")

cmd := []string{"network", "rm", dindSpec.DindNetworkID}
shell := exec.ExecTask{
Command: "docker",
Args: cmd,
Shell: true,
}
execReturn, _ := shell.Execute()
execReturn.Stdout = strings.ReplaceAll(execReturn.Stdout, "\n", "")
if execReturn.Stderr != "" {
log.G(h.Ctx).Error("\u274C [CREATE CALL] Error deleting network " + dindSpec.DindNetworkID)
} else {
log.G(h.Ctx).Info("\u2705 [CREATE CALL] Deleted network " + dindSpec.DindNetworkID)
}
// set the dind available again
err = h.DindManager.RemoveDindFromList(dindSpec.PodUID)
if err != nil {
log.G(h.Ctx).Error("\u274C [CREATE CALL] Error setting DIND container available")
}
}
}

0 comments on commit 7d68646

Please sign in to comment.