From 81a41bdab1e8c64576ead926e6f0fc0e9a7d7a3b Mon Sep 17 00:00:00 2001 From: iwilltry42 Date: Fri, 1 Oct 2021 19:01:19 +0200 Subject: [PATCH] debug: add env var flag K3D_DEBUG_DISABLE_DOCKER_INIT to test k3s as pid 1 --- pkg/runtimes/docker/translate.go | 10 +++++++++- pkg/runtimes/docker/translate_test.go | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/runtimes/docker/translate.go b/pkg/runtimes/docker/translate.go index 873c4a06..383c0f01 100644 --- a/pkg/runtimes/docker/translate.go +++ b/pkg/runtimes/docker/translate.go @@ -25,6 +25,8 @@ package docker import ( "context" "fmt" + "os" + "strconv" "strings" "github.com/containerd/containerd/log" @@ -44,10 +46,16 @@ import ( // TranslateNodeToContainer translates a k3d node specification to a docker container representation func TranslateNodeToContainer(node *k3d.Node) (*NodeInDocker, error) { + init := true + if disableInit, err := strconv.ParseBool(os.Getenv("K3D_DEBUG_DISABLE_DOCKER_INIT")); err == nil && disableInit { + l.Log().Traceln("docker-init disabled for all containers") + init = false + } + /* initialize everything that we need */ containerConfig := docker.Config{} hostConfig := docker.HostConfig{ - Init: &[]bool{true}[0], + Init: &init, ExtraHosts: node.ExtraHosts, } networkingConfig := network.NetworkingConfig{} diff --git a/pkg/runtimes/docker/translate_test.go b/pkg/runtimes/docker/translate_test.go index 43b66168..6f13172b 100644 --- a/pkg/runtimes/docker/translate_test.go +++ b/pkg/runtimes/docker/translate_test.go @@ -23,6 +23,8 @@ THE SOFTWARE. package docker import ( + "os" + "strconv" "testing" "github.com/go-test/deep" @@ -58,6 +60,9 @@ func TestTranslateNodeToContainer(t *testing.T) { } init := true + if disableInit, err := strconv.ParseBool(os.Getenv("K3D_DEBUG_DISABLE_DOCKER_INIT")); err == nil && disableInit { + init = false + } expectedRepresentation := &NodeInDocker{ ContainerConfig: container.Config{