From 9c35bae251e08442fb2ad23bde97094e94250da0 Mon Sep 17 00:00:00 2001 From: Bianco95 Date: Mon, 16 Sep 2024 08:58:20 +0200 Subject: [PATCH] added clean of dangling dind --- pkg/docker/Create.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/docker/Create.go b/pkg/docker/Create.go index 6260563..8e1dc67 100644 --- a/pkg/docker/Create.go +++ b/pkg/docker/Create.go @@ -16,6 +16,7 @@ import ( "errors" commonIL "github.com/intertwin-eu/interlink-docker-plugin/pkg/common" + "github.com/intertwin-eu/interlink-docker-plugin/pkg/docker/dindmanager" "path/filepath" ) @@ -567,4 +568,34 @@ 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") + } + } }