Skip to content

Commit

Permalink
added clean of dangling dind
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianco95 committed Sep 16, 2024
1 parent 8f13315 commit 9c35bae
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/docker/Create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
}
}
}

0 comments on commit 9c35bae

Please sign in to comment.