Skip to content

Commit

Permalink
fixed delete of pod directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianco95 committed Jun 17, 2024
1 parent 41f7fb2 commit 33d44b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
13 changes: 11 additions & 2 deletions pkg/docker/Create.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,16 @@ func (h *SidecarHandler) CreateHandler(w http.ResponseWriter, r *http.Request) {
podUID := string(data.Pod.UID)
podNamespace := string(data.Pod.Namespace)

podDirectoryPath := filepath.Join(wd, h.Config.DataRootFolder+podNamespace+"-"+podUID)
podDirectoryPath := filepath.Join(wd, h.Config.DataRootFolder+"/"+podNamespace+"-"+podUID)

// if the podDirectoryPath does not exist, create it
if _, err := os.Stat(podDirectoryPath); os.IsNotExist(err) {
err = os.MkdirAll(podDirectoryPath, os.ModePerm)
if err != nil {
HandleErrorAndRemoveData(h, w, "An error occurred during the creation of the pod directory", err, "", "")
return
}
}

// call prepareDockerRuns to get the DockerRunStruct array
dockerRunStructs, err := h.prepareDockerRuns(data, w)
Expand Down Expand Up @@ -331,7 +340,7 @@ func (h *SidecarHandler) CreateHandler(w http.ResponseWriter, r *http.Request) {
dindContainerArgs = append(dindContainerArgs, "-v", "/cvmfs:/cvmfs")
}

dindContainerArgs = append(dindContainerArgs, "--privileged", "-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)
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)

var dindContainerID string
shell := exec.ExecTask{
Expand Down
14 changes: 13 additions & 1 deletion pkg/docker/Delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
exec "github.com/alexellis/go-execute/pkg/v1"
"github.com/containerd/containerd/log"
v1 "k8s.io/api/core/v1"

"path/filepath"
)

// DeleteHandler stops and deletes Docker containers from provided data
Expand Down Expand Up @@ -111,7 +113,17 @@ func (h *SidecarHandler) DeleteHandler(w http.ResponseWriter, r *http.Request) {
// check if the container has GPU devices attacched using the GpuManager and release them
h.GpuManager.Release(containerName)

os.RemoveAll(h.Config.DataRootFolder + pod.Namespace + "-" + string(pod.UID))
wd, err := os.Getwd()
if err != nil {
HandleErrorAndRemoveData(h, w, "Unable to get current working directory", err, "", "")
return
}
podDirectoryPathToDelete := filepath.Join(wd, h.Config.DataRootFolder+"/"+podNamespace+"-"+podUID)
log.G(h.Ctx).Info("\u2705 [DELETE CALL] Deleting directory " + podDirectoryPathToDelete)

err = os.RemoveAll(podDirectoryPathToDelete)

//os.RemoveAll(h.Config.DataRootFolder + pod.Namespace + "-" + string(pod.UID))
}

w.WriteHeader(statusCode)
Expand Down

0 comments on commit 33d44b1

Please sign in to comment.