diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index ffecc9d71793..4992b181586b 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -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 ( diff --git a/pkg/minikube/node/start.go b/pkg/minikube/node/start.go index ceee28d23adb..689530fda5c4 100644 --- a/pkg/minikube/node/start.go +++ b/pkg/minikube/node/start.go @@ -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) @@ -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) diff --git a/test/integration/docker_test.go b/test/integration/docker_test.go index e150f7ad3058..27e6a572639b 100644 --- a/test/integration/docker_test.go +++ b/test/integration/docker_test.go @@ -20,6 +20,7 @@ package integration import ( "context" + "os" "os/exec" "strings" "testing" @@ -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) @@ -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()) + } +}