Skip to content

Commit

Permalink
Merge pull request #8010 from priyawadhwa/systemd-env
Browse files Browse the repository at this point in the history
Add env variable to configure force-systemd
  • Loading branch information
priyawadhwa authored May 5, 2020
2 parents 0b60ff2 + ec74a37 commit a3e9967
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const (
MinikubeActiveDockerdEnv = "MINIKUBE_ACTIVE_DOCKERD"
// PodmanVarlinkBridgeEnv is used for podman settings
PodmanVarlinkBridgeEnv = "PODMAN_VARLINK_BRIDGE"
// MinikubeForceSystemdEnv is used to force systemd as cgroup manager for the container runtime
MinikubeForceSystemdEnv = "MINIKUBE_FORCE_SYSTEMD"
)

var (
Expand Down
6 changes: 5 additions & 1 deletion pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func configureRuntimes(runner cruntime.CommandRunner, cc config.ClusterConfig, k
}
}

err = cr.Enable(disableOthers, viper.GetBool("force-systemd"))
err = cr.Enable(disableOthers, forceSystemd())
if err != nil {
debug.PrintStack()
exit.WithError("Failed to enable container runtime", err)
Expand All @@ -261,6 +261,10 @@ func configureRuntimes(runner cruntime.CommandRunner, cc config.ClusterConfig, k
return cr
}

func forceSystemd() bool {
return viper.GetBool("force-systemd") || os.Getenv(constants.MinikubeForceSystemdEnv) == "true"
}

// setupKubeAdm adds any requested files into the VM before Kubernetes is started
func setupKubeAdm(mAPI libmachine.API, cfg config.ClusterConfig, n config.Node, r command.Runner) bootstrapper.Bootstrapper {
bs, err := cluster.Bootstrapper(mAPI, viper.GetString(cmdcfg.Bootstrapper), cfg, r)
Expand Down
33 changes: 31 additions & 2 deletions test/integration/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package integration

import (
"context"
"os"
"os/exec"
"strings"
"testing"
Expand Down Expand Up @@ -64,13 +65,13 @@ func TestDockerFlags(t *testing.T) {
}
}

func TestForceSystemd(t *testing.T) {
func TestForceSystemdFlag(t *testing.T) {
if NoneDriver() {
t.Skip("skipping: none driver does not support ssh or bundle docker")
}
MaybeParallel(t)

profile := UniqueProfileName("force-systemd")
profile := UniqueProfileName("force-systemd-flag")
ctx, cancel := context.WithTimeout(context.Background(), Minutes(30))
defer CleanupWithLogs(t, profile, cancel)

Expand All @@ -90,3 +91,31 @@ func TestForceSystemd(t *testing.T) {
t.Fatalf("expected systemd cgroup driver, got: %v", rr.Output())
}
}

func TestForceSystemdEnv(t *testing.T) {
if NoneDriver() {
t.Skip("skipping: none driver does not support ssh or bundle docker")
}
MaybeParallel(t)

profile := UniqueProfileName("force-systemd-env")
ctx, cancel := context.WithTimeout(context.Background(), Minutes(30))
defer CleanupWithLogs(t, profile, cancel)

args := append([]string{"start", "-p", profile, "--memory=1800", "--alsologtostderr", "-v=5"}, StartArgs()...)
cmd := exec.CommandContext(ctx, Target(), args...)
cmd.Env = append(os.Environ(), "MINIKUBE_FORCE_SYSTEMD=true")
rr, err := Run(t, cmd)
if err != nil {
t.Errorf("failed to start minikube with args: %q : %v", rr.Command(), err)
}

rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "docker info --format {{.CgroupDriver}}"))
if err != nil {
t.Errorf("failed to get docker cgroup driver. args %q: %v", rr.Command(), err)
}

if !strings.Contains(rr.Output(), "systemd") {
t.Fatalf("expected systemd cgroup driver, got: %v", rr.Output())
}
}

0 comments on commit a3e9967

Please sign in to comment.