debug: add env var flag K3D_DEBUG_DISABLE_DOCKER_INIT to test k3s as pid 1

This commit is contained in:
iwilltry42 2021-10-01 19:01:19 +02:00
parent d21882a01c
commit 81a41bdab1
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
2 changed files with 14 additions and 1 deletions

View File

@ -25,6 +25,8 @@ package docker
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"strconv"
"strings" "strings"
"github.com/containerd/containerd/log" "github.com/containerd/containerd/log"
@ -44,10 +46,16 @@ import (
// TranslateNodeToContainer translates a k3d node specification to a docker container representation // TranslateNodeToContainer translates a k3d node specification to a docker container representation
func TranslateNodeToContainer(node *k3d.Node) (*NodeInDocker, error) { 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 */ /* initialize everything that we need */
containerConfig := docker.Config{} containerConfig := docker.Config{}
hostConfig := docker.HostConfig{ hostConfig := docker.HostConfig{
Init: &[]bool{true}[0], Init: &init,
ExtraHosts: node.ExtraHosts, ExtraHosts: node.ExtraHosts,
} }
networkingConfig := network.NetworkingConfig{} networkingConfig := network.NetworkingConfig{}

View File

@ -23,6 +23,8 @@ THE SOFTWARE.
package docker package docker
import ( import (
"os"
"strconv"
"testing" "testing"
"github.com/go-test/deep" "github.com/go-test/deep"
@ -58,6 +60,9 @@ func TestTranslateNodeToContainer(t *testing.T) {
} }
init := true init := true
if disableInit, err := strconv.ParseBool(os.Getenv("K3D_DEBUG_DISABLE_DOCKER_INIT")); err == nil && disableInit {
init = false
}
expectedRepresentation := &NodeInDocker{ expectedRepresentation := &NodeInDocker{
ContainerConfig: container.Config{ ContainerConfig: container.Config{