Skip to content

Commit 33d44b1

Browse files
committed
fixed delete of pod directory
1 parent 41f7fb2 commit 33d44b1

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

pkg/docker/Create.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,16 @@ func (h *SidecarHandler) CreateHandler(w http.ResponseWriter, r *http.Request) {
284284
podUID := string(data.Pod.UID)
285285
podNamespace := string(data.Pod.Namespace)
286286

287-
podDirectoryPath := filepath.Join(wd, h.Config.DataRootFolder+podNamespace+"-"+podUID)
287+
podDirectoryPath := filepath.Join(wd, h.Config.DataRootFolder+"/"+podNamespace+"-"+podUID)
288+
289+
// if the podDirectoryPath does not exist, create it
290+
if _, err := os.Stat(podDirectoryPath); os.IsNotExist(err) {
291+
err = os.MkdirAll(podDirectoryPath, os.ModePerm)
292+
if err != nil {
293+
HandleErrorAndRemoveData(h, w, "An error occurred during the creation of the pod directory", err, "", "")
294+
return
295+
}
296+
}
288297

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

334-
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)
343+
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)
335344

336345
var dindContainerID string
337346
shell := exec.ExecTask{

pkg/docker/Delete.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
exec "github.com/alexellis/go-execute/pkg/v1"
1111
"github.com/containerd/containerd/log"
1212
v1 "k8s.io/api/core/v1"
13+
14+
"path/filepath"
1315
)
1416

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

114-
os.RemoveAll(h.Config.DataRootFolder + pod.Namespace + "-" + string(pod.UID))
116+
wd, err := os.Getwd()
117+
if err != nil {
118+
HandleErrorAndRemoveData(h, w, "Unable to get current working directory", err, "", "")
119+
return
120+
}
121+
podDirectoryPathToDelete := filepath.Join(wd, h.Config.DataRootFolder+"/"+podNamespace+"-"+podUID)
122+
log.G(h.Ctx).Info("\u2705 [DELETE CALL] Deleting directory " + podDirectoryPathToDelete)
123+
124+
err = os.RemoveAll(podDirectoryPathToDelete)
125+
126+
//os.RemoveAll(h.Config.DataRootFolder + pod.Namespace + "-" + string(pod.UID))
115127
}
116128

117129
w.WriteHeader(statusCode)

0 commit comments

Comments
 (0)